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];
122 T *rbuf =
new T[totalrecv];
126 RCP<CommRequest<int> > *requests =
new RCP<CommRequest<int> > [nrecvranks];
135 if (
size_t(maxMsg) *
sizeof(T) > INT_MAX && nprocs > 1) OK[0] =
false;
136 if (totalrecv && !rbuf) OK[1] = 0;
137 if (!requests) OK[1] = 0;
142 size_t myrecvoffset = 0;
143 size_t mysendoffset = 0;
145 if (OK[0] && OK[1]) {
147 for (
int i = 0; i < nprocs; i++) {
148 if (i != rank && recvCount[i]) {
150 requests[rcnt++] = Teuchos::ireceive<int,T>(comm,
151 Teuchos::arcp(&rbuf[offset],0,recvCount[i],
false),
156 else if (i == rank) {
157 myrecvoffset = offset;
159 offset += recvCount[i];
164 Teuchos::reduceAll<int>(comm, Teuchos::REDUCE_MIN, 2, OK, gOK);
165 if (!gOK[0] || !gOK[1]) {
169 throw std::runtime_error(
"Max single message length exceeded");
171 throw std::bad_alloc();
176 for (
int i = 0; i < nprocs; i++) {
177 if (i != rank && sendCount[i]) {
179 Teuchos::readySend<int,T>(comm,
180 Teuchos::arrayView(&sendBuf[offset],sendCount[i]),
185 else if (i == rank) {
186 mysendoffset = offset;
188 offset += sendCount[i];
192 for (
int j = 0; j < sendCount[rank]; j++)
193 rbuf[myrecvoffset++] = sendBuf[mysendoffset++];
197 Teuchos::waitAll<int>(comm, Teuchos::arrayView(requests, nrecvranks));
205 if (totalrecv && !rbuf)
206 throw std::bad_alloc();
208 for (
int j = 0; j < sendCount[0]; j++)
209 rbuf[j] = sendBuf[j];
213 recvBuf = ArrayRCP<T>(rbuf, 0, totalrecv,
true);
215 recvBuf = Teuchos::null;
228 const ArrayView<const string> &sendBuf,
229 const ArrayView<const int> &sendCount,
230 ArrayRCP<string> &recvBuf,
231 const ArrayView<int> &recvCount);
233 #ifdef HAVE_ZOLTAN2_LONG_LONG 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);
251 const ArrayView<const unsigned short> &sendBuf,
252 const ArrayView<const int> &sendCount,
253 ArrayRCP<unsigned short> &recvBuf,
254 const ArrayView<int> &recvCount);
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.
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.
void AlltoAllv(const Comm< int > &comm, const Environment &env, const ArrayView< const string > &sendBuf, const ArrayView< const int > &sendCount, ArrayRCP< string > &recvBuf, const ArrayView< int > &recvCount)