50 #ifndef _ZOLTAN2_ALLTOALL_HPP_
51 #define _ZOLTAN2_ALLTOALL_HPP_
62 extern void AlltoAllCount(
const Comm<int> &comm,
const Environment &env,
63 const ArrayView<const int> &sendCount,
const ArrayView<int> &recvCount);
95 const ArrayView<const T> &sendBuf,
96 const ArrayView<const int> &sendCount,
98 const ArrayView<int> &recvCount
101 int nprocs = comm.getSize();
102 int rank = comm.getRank();
110 size_t totalrecv = 0;
113 for(
int i = 0; i < nprocs; i++) {
114 if (recvCount[i] > 0) {
115 totalrecv += recvCount[i];
117 if (recvCount[i] > maxMsg) maxMsg = recvCount[i];
123 if (totalrecv) rbuf =
new T[totalrecv];
127 RCP<CommRequest<int> > *requests =
new RCP<CommRequest<int> > [nrecvranks];
136 if (
size_t(maxMsg) *
sizeof(T) > INT_MAX && nprocs > 1) OK[0] =
false;
137 if (totalrecv && !rbuf) OK[1] = 0;
138 if (!requests) OK[1] = 0;
143 size_t myrecvoffset = 0;
144 size_t mysendoffset = 0;
146 if (OK[0] && OK[1]) {
148 for (
int i = 0; i < nprocs; i++) {
149 if (i != rank && recvCount[i]) {
151 requests[rcnt++] = Teuchos::ireceive<int,T>(comm,
152 Teuchos::arcp(&rbuf[offset],0,recvCount[i],
false),
157 else if (i == rank) {
158 myrecvoffset = offset;
160 offset += recvCount[i];
165 Teuchos::reduceAll<int>(comm, Teuchos::REDUCE_MIN, 2, OK, gOK);
166 if (!gOK[0] || !gOK[1]) {
170 throw std::runtime_error(
"Max single message length exceeded");
172 throw std::bad_alloc();
177 for (
int i = 0; i < nprocs; i++) {
178 if (i != rank && sendCount[i]) {
180 Teuchos::readySend<int,T>(comm,
181 Teuchos::arrayView(&sendBuf[offset],sendCount[i]),
186 else if (i == rank) {
187 mysendoffset = offset;
189 offset += sendCount[i];
193 for (
int j = 0; j < sendCount[rank]; j++)
194 rbuf[myrecvoffset++] = sendBuf[mysendoffset++];
198 Teuchos::waitAll<int>(comm, Teuchos::arrayView(requests, nrecvranks));
206 if (totalrecv && !rbuf)
207 throw std::bad_alloc();
209 for (
int j = 0; j < sendCount[0]; j++)
210 rbuf[j] = sendBuf[j];
214 recvBuf = ArrayRCP<T>(rbuf, 0, totalrecv,
true);
216 recvBuf = Teuchos::null;
228 const Environment &env,
229 const ArrayView<const std::string> &sendBuf,
230 const ArrayView<const int> &sendCount,
231 ArrayRCP<std::string> &recvBuf,
232 const ArrayView<int> &recvCount);
236 #ifdef HAVE_TPETRA_INT_LONG_LONG
239 const Environment &env,
240 const ArrayView<const unsigned long long> &sendBuf,
241 const ArrayView<const int> &sendCount,
242 ArrayRCP<unsigned long long> &recvBuf,
243 const ArrayView<int> &recvCount);
250 const Environment &env,
251 const ArrayView<const unsigned short> &sendBuf,
252 const ArrayView<const int> &sendCount,
253 ArrayRCP<unsigned short> &recvBuf,
254 const ArrayView<int> &recvCount);
260 const Environment &env,
261 const ArrayView<const unsigned char> &sendBuf,
262 const ArrayView<const int> &sendCount,
263 ArrayRCP<unsigned char> &recvBuf,
264 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.