45 #include <Teuchos_CommHelpers.hpp>
54 const Teuchos::Comm<int>& comm)
56 using Teuchos::ArrayRCP;
57 using Teuchos::CommRequest;
58 using Teuchos::ireceive;
60 using Teuchos::outArg;
64 const int myRank = comm.getRank ();
65 const int rootRank = 0;
66 if (myRank == rootRank) {
70 const int numProcs = comm.getSize ();
71 const int sizeTag = 42;
72 const int msgTag = 43;
74 ArrayRCP<size_t> sizeBuf (1);
75 ArrayRCP<char> msgBuf;
76 RCP<CommRequest<int> > req;
78 for (
int p = 1; p < numProcs; ++p) {
80 sizeBuf[0] = s.size ();
81 req = isend<int, size_t> (sizeBuf, rootRank, sizeTag, comm);
82 (void) wait<int> (comm, outArg (req));
84 const size_t msgSize = s.size ();
85 msgBuf.resize (msgSize + 1);
86 std::copy (s.begin (), s.end (), msgBuf.begin ());
87 msgBuf[msgSize] =
'\0';
89 req = isend<int, char> (msgBuf, rootRank, msgTag, comm);
90 (void) wait<int> (comm, outArg (req));
92 else if (myRank == rootRank) {
94 req = ireceive<int, size_t> (sizeBuf, p, sizeTag, comm);
95 (void) wait<int> (comm, outArg (req));
97 const size_t msgSize = sizeBuf[0];
98 msgBuf.resize (msgSize + 1);
99 req = ireceive<int, char> (msgBuf, p, msgTag, comm);
100 (void) wait<int> (comm, outArg (req));
102 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.