37CommGrid::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) );
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);