111 MPI_Comm_size(MPI_COMM_WORLD, &nProc);
112 MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
114 int nColumnsMax = (int)sqrt(RealType(nProc));
117 for (
int i = 1; i < nColumnsMax + 1; i++) {
118 if (nProc % i == 0) nColumns = i;
122 rowIndex_ = myRank / nColumns;
123 columnIndex_ = myRank % nColumns;
127 MPI_Comm_split(MPI_COMM_WORLD, rowIndex_, 0, &myComm);
130 MPI_Comm_split(MPI_COMM_WORLD, columnIndex_, 0, &myComm);
133 MPI_Comm_split(MPI_COMM_WORLD, myRank, 0, &myComm);
137 MPI_Comm getComm() {
return myComm; }
148 Plan<T>(MPI_Comm comm,
int nObjects) : myComm(comm) {
150 MPI_Comm_size(myComm, &nCommProcs);
152 counts.resize(nCommProcs, 0);
153 displacements.resize(nCommProcs, 0);
157 MPI_Allgather(&planSize_, 1, MPI_INT, &counts[0], 1, MPI_INT, myComm);
159 displacements[0] = 0;
160 for (
int i = 1; i < nCommProcs; i++) {
161 displacements[i] = displacements[i - 1] + counts[i - 1];
165 for (
int i = 0; i < nCommProcs; i++) {
170 void gather(vector<T>& v1, vector<T>& v2) {
179 void scatter(vector<T>& v1, vector<T>& v2) {
187 int getSize() {
return size_; }
193 vector<int> displacements;