37 CommGrid::CommGrid(MPI_Comm world,
int nrowproc,
int ncolproc): grrows(nrowproc), grcols(ncolproc)
39 MPI_Comm_dup(world, &commWorld);
40 MPI_Comm_rank(commWorld, &myrank);
42 MPI_Comm_size(commWorld,&nproc);
44 if(grrows == 0 && grcols == 0)
46 grrows = (int)std::sqrt((
float)nproc);
49 if(grcols * grrows != nproc)
51 cerr <<
"This version of the Combinatorial BLAS only works on a square logical processor grid" << endl;
55 assert((nproc == (grrows*grcols)));
57 myproccol = (int) (myrank % grcols);
58 myprocrow = (int) (myrank / grcols);
66 MPI_Comm_split(commWorld,myprocrow, myrank,&rowWorld);
67 MPI_Comm_split(commWorld,myproccol, myrank,&colWorld);
71 MPI_Comm_rank(rowWorld,&rowRank);
72 MPI_Comm_rank(colWorld,&colRank);
73 assert( (rowRank == myproccol) );
74 assert( (colRank == myprocrow) );
81 cout <<
"The grid is not square... !" << endl;
82 cout <<
"Returning diagworld to everyone instead of the diagonal" << endl;
83 diagWorld = commWorld;
86 int * process_ranks =
new int[grcols];
87 for(
int i=0; i < grcols; ++i)
89 process_ranks[i] = i*grcols + i;
92 MPI_Comm_group(commWorld,&group);
94 MPI_Group_incl(group,grcols, process_ranks, &diag_group);
95 MPI_Group_free(&group);
96 delete [] process_ranks;
99 MPI_Comm_create(commWorld,diag_group,&diagWorld);
100 MPI_Group_free(&diag_group);
105 return ( myproccol == ((
int) (rhsrank % grcols)) );
110 return ( myprocrow == ((
int) (rhsrank / grcols)) );
116 return ((
int) (wholerank / grcols));
122 return ((
int) (wholerank % grcols));
142 MPI_Comm_compare(commWorld, rhs.commWorld, &result);
143 if ((result != MPI_IDENT) && (result != MPI_CONGRUENT))
149 return ( (grrows == rhs.grrows) && (grcols == rhs.grcols) && (myprocrow == rhs.myprocrow) && (myproccol == rhs.myproccol));
159 string ofilename = prefix;
161 output.open(ofilename.c_str(), ios_base::app );
168 cout <<
"Grids don't confirm for multiplication" << endl;
173 innerdim = gridA->grcols;
174 Aoffset = (gridA->myprocrow + gridA->myproccol) % gridA->grcols;
175 Boffset = (gridB->myprocrow + gridB->myproccol) % gridB->grrows;
179 return shared_ptr<CommGrid>(
new CommGrid(*gridA) );
void OpenDebugFile(std::string prefix, std::ofstream &output) const
CommGrid(MPI_Comm world, int nrowproc, int ncolproc)
friend std::shared_ptr< CommGrid > ProductGrid(CommGrid *gridA, CommGrid *gridB, int &innerdim, int &Aoffset, int &Boffset)
bool OnSameProcCol(int rhsrank)
bool OnSameProcRow(int rhsrank)
bool operator==(const CommGrid &rhs) const