MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / comm_gatherStringsToRoot

Function comm_gatherStringsToRoot

quest/src/comm/comm_routines.cpp:793–819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

791
792
793vector<string> comm_gatherStringsToRoot(char* localChars, int maxNumLocalChars) {
794#if COMPILE_MPI
795
796 // no need to validate array sizes and memory alloc successes;
797 // these are trivial O(#nodes)-size arrays containing <20 chars
798 int numNodes = comm_getNumNodes();
799
800 // root makes one big contiguous array to receive all chars contiguously
801 vector<char> allChars(maxNumLocalChars * numNodes);
802
803 // all nodes send root all their local chars
804 int recvRank = ROOT_RANK;
805 MPI_Gather(localChars, maxNumLocalChars, MPI_CHAR, allChars.data(),
806 maxNumLocalChars, MPI_CHAR, recvRank, MPI_COMM_WORLD);
807
808 // divide allChars into stings, delimited by each node's terminal char
809 vector<string> out(numNodes);
810 for (int r=0; r<numNodes; r++)
811 out[r] = std::string(&allChars[r*maxNumLocalChars]);
812
813 return out;
814
815#else
816 error_commButEnvNotDistributed();
817 return {};
818#endif
819}

Callers 1

Calls 2

comm_getNumNodesFunction · 0.85

Tested by

no test coverage detected