11 #include <Teuchos_CommHelpers.hpp>
19 const Teuchos::Comm<int>& comm) {
20 using Teuchos::ArrayRCP;
21 using Teuchos::CommRequest;
22 using Teuchos::ireceive;
24 using Teuchos::outArg;
28 const int myRank = comm.getRank();
29 const int rootRank = 0;
30 if (myRank == rootRank) {
34 const int numProcs = comm.getSize();
35 const int sizeTag = 42;
36 const int msgTag = 43;
38 ArrayRCP<size_t> sizeBuf(1);
39 ArrayRCP<char> msgBuf;
40 RCP<CommRequest<int> > req;
42 for (
int p = 1; p < numProcs; ++p) {
44 sizeBuf[0] = s.size();
45 req = isend<int, size_t>(sizeBuf, rootRank, sizeTag, comm);
46 (void)wait<int>(comm, outArg(req));
48 const size_t msgSize = s.size();
49 msgBuf.resize(msgSize + 1);
50 std::copy(s.begin(), s.end(), msgBuf.begin());
51 msgBuf[msgSize] =
'\0';
53 req = isend<int, char>(msgBuf, rootRank, msgTag, comm);
54 (void)wait<int>(comm, outArg(req));
55 }
else if (myRank == rootRank) {
57 req = ireceive<int, size_t>(sizeBuf, p, sizeTag, comm);
58 (void)wait<int>(comm, outArg(req));
60 const size_t msgSize = sizeBuf[0];
61 msgBuf.resize(msgSize + 1);
62 req = ireceive<int, char>(msgBuf, p, msgTag, comm);
63 (void)wait<int>(comm, outArg(req));
65 std::string msg(msgBuf.getRawPtr());
Declaration of a function that prints strings from each process.
void gathervPrint(std::ostream &out, const std::string &s, const Teuchos::Comm< int > &comm)
On Process 0 in the given communicator, print strings from each process in that communicator, in rank order.