14 #ifndef _ZOLTAN2_ALLTOALL_HPP_
15 #define _ZOLTAN2_ALLTOALL_HPP_
26 extern void AlltoAllCount(
const Comm<int> &comm,
const Environment &env,
27 const ArrayView<const int> &sendCount,
const ArrayView<int> &recvCount);
59 const ArrayView<const T> &sendBuf,
60 const ArrayView<const int> &sendCount,
62 const ArrayView<int> &recvCount
65 int nprocs = comm.getSize();
66 int rank = comm.getRank();
77 for(
int i = 0; i < nprocs; i++) {
78 if (recvCount[i] > 0) {
79 totalrecv += recvCount[i];
81 if (recvCount[i] > maxMsg) maxMsg = recvCount[i];
87 if (totalrecv) rbuf =
new T[totalrecv];
91 RCP<CommRequest<int> > *requests =
new RCP<CommRequest<int> > [nrecvranks];
100 if (
size_t(maxMsg) *
sizeof(T) > INT_MAX && nprocs > 1) OK[0] =
false;
101 if (totalrecv && !rbuf) OK[1] = 0;
102 if (!requests) OK[1] = 0;
107 size_t myrecvoffset = 0;
108 size_t mysendoffset = 0;
110 if (OK[0] && OK[1]) {
112 for (
int i = 0; i < nprocs; i++) {
113 if (i != rank && recvCount[i]) {
115 requests[rcnt++] = Teuchos::ireceive<int,T>(comm,
116 Teuchos::arcp(&rbuf[offset],0,recvCount[i],
false),
121 else if (i == rank) {
122 myrecvoffset = offset;
124 offset += recvCount[i];
129 Teuchos::reduceAll<int>(comm, Teuchos::REDUCE_MIN, 2, OK, gOK);
130 if (!gOK[0] || !gOK[1]) {
134 throw std::runtime_error(
"Max single message length exceeded");
136 throw std::bad_alloc();
141 for (
int i = 0; i < nprocs; i++) {
142 if (i != rank && sendCount[i]) {
144 Teuchos::readySend<int,T>(comm,
145 Teuchos::arrayView(&sendBuf[offset],sendCount[i]),
150 else if (i == rank) {
151 mysendoffset = offset;
153 offset += sendCount[i];
157 for (
int j = 0; j < sendCount[rank]; j++)
158 rbuf[myrecvoffset++] = sendBuf[mysendoffset++];
162 Teuchos::waitAll<int>(comm, Teuchos::arrayView(requests, nrecvranks));
170 if (totalrecv && !rbuf)
171 throw std::bad_alloc();
173 for (
int j = 0; j < sendCount[0]; j++)
174 rbuf[j] = sendBuf[j];
178 recvBuf = ArrayRCP<T>(rbuf, 0, totalrecv,
true);
180 recvBuf = Teuchos::null;
192 const Environment &env,
193 const ArrayView<const std::string> &sendBuf,
194 const ArrayView<const int> &sendCount,
195 ArrayRCP<std::string> &recvBuf,
196 const ArrayView<int> &recvCount);
200 #ifdef HAVE_TPETRA_INT_LONG_LONG
203 const Environment &env,
204 const ArrayView<const unsigned long long> &sendBuf,
205 const ArrayView<const int> &sendCount,
206 ArrayRCP<unsigned long long> &recvBuf,
207 const ArrayView<int> &recvCount);
214 const Environment &env,
215 const ArrayView<const unsigned short> &sendBuf,
216 const ArrayView<const int> &sendCount,
217 ArrayRCP<unsigned short> &recvBuf,
218 const ArrayView<int> &recvCount);
224 const Environment &env,
225 const ArrayView<const unsigned char> &sendBuf,
226 const ArrayView<const int> &sendCount,
227 ArrayRCP<unsigned char> &recvBuf,
228 const ArrayView<int> &recvCount);
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
void AlltoAllv(const Comm< int > &comm, const Environment &env, const ArrayView< const std::string > &sendBuf, const ArrayView< const int > &sendCount, ArrayRCP< std::string > &recvBuf, const ArrayView< int > &recvCount)
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
Gathering definitions used in software development.
Defines the Environment class.
#define Z2_THROW_OUTSIDE_ERROR(env)
Throw an error returned from outside the Zoltan2 library.
void AlltoAllCount(const Comm< int > &comm, const Environment &env, const ArrayView< const int > &sendCount, const ArrayView< int > &recvCount)
Each process sends a value to every process, an all-to-all.