37 const Comm<int> &comm,
39 const ArrayView<const int> &sendCount,
41 const ArrayView<int> &recvCount
45 int nprocs = comm.getSize();
46 int rank = comm.getRank();
48 recvCount[rank] = sendCount[rank];
53 RCP<CommRequest<int> > *requests =
new RCP<CommRequest<int> > [nprocs];
54 for (
int cnt = 0, i = 0; i < nprocs; i++) {
57 requests[cnt++] = Teuchos::ireceive<int,int>(comm,
58 rcp(&(recvCount[i]),
false),
65 Teuchos::barrier<int>(comm);
68 for (
int i = 0; i < nprocs; i++) {
71 Teuchos::readySend<int,int>(comm, sendCount[i], i);
79 Teuchos::waitAll<int>(comm, arrayView(requests, nprocs-1));
97 const ArrayView<const std::string> &sendBuf,
98 const ArrayView<const int> &sendCount,
99 ArrayRCP<std::string> &recvBuf,
100 const ArrayView<int> &recvCount
103 int nprocs = comm.getSize();
104 int *newCount =
new int [nprocs];
105 memset(newCount, 0,
sizeof(
int) * nprocs);
106 ArrayView<const int> newSendCount(newCount, nprocs);
108 size_t numStrings = sendBuf.size();
112 for (
int p=0, i=0; !fail && p < nprocs; p++){
113 for (
int c=0; !fail && c < sendCount[p]; c++, i++){
114 size_t nchars = sendBuf[i].size();
115 if (nchars > SCHAR_MAX)
118 newCount[p] += nchars;
120 newCount[p] += sendCount[p];
121 numChars += newCount[p];
125 throw std::runtime_error(
"id string length exceeds SCHAR_MAX");
129 sbuf =
new char [numChars];
130 char *sbufptr = sbuf;
132 ArrayView<const char> newSendBuf(sbuf, numChars);
134 for (
size_t i=0; i < numStrings; i++){
135 size_t nchars = sendBuf[i].size();
136 *sbufptr++ =
static_cast<char>(nchars);
137 for (
size_t j=0; j < nchars; j++)
138 *sbufptr++ = sendBuf[i][j];
141 ArrayRCP<char> newRecvBuf;
142 Array<int> newRecvCount(nprocs, 0);
144 AlltoAllv<char>(comm, env, newSendBuf, newSendCount,
145 newRecvBuf, newRecvCount());
150 char *inBuf = newRecvBuf.getRawPtr();
152 int numNewStrings = 0;
154 char *endChar = inBuf + newRecvBuf.size();
155 while (buf < endChar){
156 int slen =
static_cast<int>(*buf++);
162 std::string *newStrings =
new std::string [numNewStrings];
167 for (
int p=0; p < nprocs; p++){
168 int nchars = newRecvCount[p];
169 endChar = buf + nchars;
170 while (buf < endChar){
172 std::string nextString;
173 for (
int i=0; i < slen; i++)
174 nextString.push_back(*buf++);
175 newStrings[next++] = nextString;
180 recvBuf = arcp<std::string>(newStrings, 0, numNewStrings,
true);
187 #ifdef HAVE_TPETRA_INT_LONG_LONG
190 const Environment &env,
191 const ArrayView<const unsigned long long> &sendBuf,
192 const ArrayView<const int> &sendCount,
193 ArrayRCP<unsigned long long> &recvBuf,
194 const ArrayView<int> &recvCount
197 const long long *sbuf =
198 reinterpret_cast<const long long *
>(sendBuf.getRawPtr());
199 ArrayView<const long long> newSendBuf(sbuf, sendBuf.size());
200 ArrayRCP<long long> newRecvBuf;
202 AlltoAllv<long long>(comm, env, newSendBuf, sendCount,
203 newRecvBuf, recvCount);
205 recvBuf = arcp_reinterpret_cast<
unsigned long long>(newRecvBuf);
215 const ArrayView<const unsigned short> &sendBuf,
216 const ArrayView<const int> &sendCount,
217 ArrayRCP<unsigned short> &recvBuf,
218 const ArrayView<int> &recvCount
221 const short *sbuf =
reinterpret_cast<const short *
>(sendBuf.getRawPtr());
222 ArrayView<const short> newSendBuf(sbuf, sendBuf.size());
223 ArrayRCP<short> newRecvBuf;
225 AlltoAllv<short>(comm, env, newSendBuf, sendCount,
226 newRecvBuf, recvCount);
228 recvBuf = arcp_reinterpret_cast<
unsigned short>(newRecvBuf);
237 const ArrayView<const unsigned char> &sendBuf,
238 const ArrayView<const int> &sendCount,
239 ArrayRCP<unsigned char> &recvBuf,
240 const ArrayView<int> &recvCount
243 const char *sbuf =
reinterpret_cast<const char *
>(sendBuf.getRawPtr());
244 ArrayView<const char> newSendBuf(sbuf, sendBuf.size());
245 ArrayRCP<char> newRecvBuf;
247 AlltoAllv<char>(comm, env, newSendBuf, sendCount,
248 newRecvBuf, recvCount);
250 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...
static const std::string fail
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.