11 #include <Teuchos_CommHelpers.hpp>
20 const Teuchos::Comm<int>& comm)
22 using Teuchos::ArrayRCP;
23 using Teuchos::CommRequest;
24 using Teuchos::ireceive;
26 using Teuchos::outArg;
30 const int myRank = comm.getRank ();
31 const int rootRank = 0;
32 if (myRank == rootRank) {
36 const int numProcs = comm.getSize ();
37 const int sizeTag = 42;
38 const int msgTag = 43;
40 ArrayRCP<size_t> sizeBuf (1);
41 ArrayRCP<char> msgBuf;
42 RCP<CommRequest<int> > req;
44 for (
int p = 1; p < numProcs; ++p) {
46 sizeBuf[0] = s.size ();
47 req = isend<int, size_t> (sizeBuf, rootRank, sizeTag, comm);
48 (void) wait<int> (comm, outArg (req));
50 const size_t msgSize = s.size ();
51 msgBuf.resize (msgSize + 1);
52 std::copy (s.begin (), s.end (), msgBuf.begin ());
53 msgBuf[msgSize] =
'\0';
55 req = isend<int, char> (msgBuf, rootRank, msgTag, comm);
56 (void) wait<int> (comm, outArg (req));
58 else if (myRank == rootRank) {
60 req = ireceive<int, size_t> (sizeBuf, p, sizeTag, comm);
61 (void) wait<int> (comm, outArg (req));
63 const size_t msgSize = sizeBuf[0];
64 msgBuf.resize (msgSize + 1);
65 req = ireceive<int, char> (msgBuf, p, msgTag, comm);
66 (void) wait<int> (comm, outArg (req));
68 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.