MPI_Comm_split
Form new communicators from existing one
In many scientific and engineering computations, we often deal with grids, especially cartesian grids, in rows and columns. On occasions however, we may need to deal with them in less traditional manners. For example, instead of dealing with individual rows, we may want to deal with groups of rows or even more generally, other arbitrary configurations. MPI_Comm_split permits the creation of new communicators with such flexibilities.
The input variable color
provides the identity of the group while the key
variable identifies a member of the group.
Fortran syntax
Subroutine MPI_Comm_split(old_comm,color,key,new_comm,ierr)
C syntax
int MPI_Comm_split(MPI_COMM old_comm,int color, int key, MPI_Comm* new_comm, int* ierr)
Example in Fortran
For a 2D cartesian grid, create subgrids of rows and columns
c**virtual topology with nv rows and mv columns iv = Iam/mv !! row number jv = mod(Iam, mv) !! column number comm2D = MPI_COMM_WORLD call MPI_Comm_split(comm2D, iv, jv, row_comm, ierr) call MPI_Comm_split(comm2D, jv, iv, col_comm, ierr)
Shown in Figure a below is a 3-by-2 virtual grid. The number in parentheses represents the rank number associated with the virtual grid. Figure b shows the row subgrids while Figure c shows the column subgrids created by using MPI_Comm_split
.
|
|
|
As another example of MPI_Comm_split, lets split the rows into two groups of rows: the first consists of rows 1 and 2 while the second represents row 3. The code fragment that dose that is:
C**MPI_Comm_split is more general than MPI_Cart_sub C**simple example of 6 processes divided into 2 groups; C**1st 4 belongs to 1 group and remaining two to another group do i=0,5 row_group(i) = i/4 !! this expression by no means general enddo call MPI_Comm_split(comm2D, row_group(Iam), Iam, & row_comm, ierr)
And the output of the fortran code for this particular arrangement is shown below:
The above table is illustrated in the figure below.
(0) | (1) |
---|---|
(2) | (3) |
(4) | (5) |
We have just demonstrated the use of MPI_Comm_split to divide a virtual grid into arbitrary subgrids. This routine is very similar to MPI_Cart_sub
but is more general.