| 791 | |
| 792 | |
| 793 | vector<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 | } |
no test coverage detected