73 const Comm<int> &comm,
75 const ArrayView<const int> &sendCount,
77 const ArrayView<int> &recvCount
81 int nprocs = comm.getSize();
82 int rank = comm.getRank();
84 recvCount[rank] = sendCount[rank];
89 RCP<CommRequest<int> > *requests =
new RCP<CommRequest<int> > [nprocs];
90 for (
int cnt = 0, i = 0; i < nprocs; i++) {
93 requests[cnt++] = Teuchos::ireceive<int,int>(comm,
94 rcp(&(recvCount[i]),
false),
101 Teuchos::barrier<int>(comm);
104 for (
int i = 0; i < nprocs; i++) {
107 Teuchos::readySend<int,int>(comm, sendCount[i], i);
115 Teuchos::waitAll<int>(comm, arrayView(requests, nprocs-1));
133 const ArrayView<const std::string> &sendBuf,
134 const ArrayView<const int> &sendCount,
135 ArrayRCP<std::string> &recvBuf,
136 const ArrayView<int> &recvCount
139 int nprocs = comm.getSize();
140 int *newCount =
new int [nprocs];
141 memset(newCount, 0,
sizeof(
int) * nprocs);
142 ArrayView<const int> newSendCount(newCount, nprocs);
144 size_t numStrings = sendBuf.size();
148 for (
int p=0, i=0; !fail && p < nprocs; p++){
149 for (
int c=0; !fail && c < sendCount[p]; c++, i++){
150 size_t nchars = sendBuf[i].size();
151 if (nchars > SCHAR_MAX)
154 newCount[p] += nchars;
156 newCount[p] += sendCount[p];
157 numChars += newCount[p];
161 throw std::runtime_error(
"id string length exceeds SCHAR_MAX");
165 sbuf =
new char [numChars];
166 char *sbufptr = sbuf;
168 ArrayView<const char> newSendBuf(sbuf, numChars);
170 for (
size_t i=0; i < numStrings; i++){
171 size_t nchars = sendBuf[i].size();
172 *sbufptr++ =
static_cast<char>(nchars);
173 for (
size_t j=0; j < nchars; j++)
174 *sbufptr++ = sendBuf[i][j];
177 ArrayRCP<char> newRecvBuf;
178 Array<int> newRecvCount(nprocs, 0);
180 AlltoAllv<char>(comm, env, newSendBuf, newSendCount,
181 newRecvBuf, newRecvCount());
186 char *inBuf = newRecvBuf.getRawPtr();
188 int numNewStrings = 0;
190 char *endChar = inBuf + newRecvBuf.size();
191 while (buf < endChar){
192 int slen =
static_cast<int>(*buf++);
198 std::string *newStrings =
new std::string [numNewStrings];
203 for (
int p=0; p < nprocs; p++){
204 int nchars = newRecvCount[p];
205 endChar = buf + nchars;
206 while (buf < endChar){
208 std::string nextString;
209 for (
int i=0; i < slen; i++)
210 nextString.push_back(*buf++);
211 newStrings[next++] = nextString;
216 recvBuf = arcp<std::string>(newStrings, 0, numNewStrings,
true);
221 #ifdef HAVE_ZOLTAN2_LONG_LONG 228 const ArrayView<const unsigned long long> &sendBuf,
229 const ArrayView<const int> &sendCount,
230 ArrayRCP<unsigned long long> &recvBuf,
231 const ArrayView<int> &recvCount
234 const long long *sbuf =
235 reinterpret_cast<const long long *
>(sendBuf.getRawPtr());
236 ArrayView<const long long> newSendBuf(sbuf, sendBuf.size());
237 ArrayRCP<long long> newRecvBuf;
239 AlltoAllv<long long>(comm, env, newSendBuf, sendCount,
240 newRecvBuf, recvCount);
242 recvBuf = arcp_reinterpret_cast<
unsigned long long>(newRecvBuf);
252 const ArrayView<const unsigned short> &sendBuf,
253 const ArrayView<const int> &sendCount,
254 ArrayRCP<unsigned short> &recvBuf,
255 const ArrayView<int> &recvCount
258 const short *sbuf =
reinterpret_cast<const short *
>(sendBuf.getRawPtr());
259 ArrayView<const short> newSendBuf(sbuf, sendBuf.size());
260 ArrayRCP<short> newRecvBuf;
262 AlltoAllv<short>(comm, env, newSendBuf, sendCount,
263 newRecvBuf, recvCount);
265 recvBuf = arcp_reinterpret_cast<
unsigned short>(newRecvBuf);
274 const ArrayView<const unsigned char> &sendBuf,
275 const ArrayView<const int> &sendCount,
276 ArrayRCP<unsigned char> &recvBuf,
277 const ArrayView<int> &recvCount
280 const char *sbuf =
reinterpret_cast<const char *
>(sendBuf.getRawPtr());
281 ArrayView<const char> newSendBuf(sbuf, sendBuf.size());
282 ArrayRCP<char> newRecvBuf;
284 AlltoAllv<char>(comm, env, newSendBuf, sendCount,
285 newRecvBuf, recvCount);
287 recvBuf = arcp_reinterpret_cast<
unsigned char>(newRecvBuf);
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.
AlltoAll communication methods.