MPI_Cart_sub

MPI_Cart_sub creates new communicators for subgrids of up to (N-1) dimensions from an N-dimensional cartesian grid.

Often, after we have created a cartesian grid, we wish to further group elements of this grid into subgrids of lower dimensions. For instance, the subgrids of a 2D cartesian grid are 1D grids of the individual rows or columns. Similarly, for a 3D cartesian grid, the subgrids can either be 2D or 1D.

Fortran Syntax

Subroutine MPI_Cart_sub(old_comm, belongs, new_comm, ierr)

C Syntax

int MPI_Cart_sub(MPI_Comm old_comm, int *belongs, MPI_Comm *new_comm)


Example in Fortran

For a 2D cartesian grid, create subgrids of rows and columns. Create cartesian topology for processes.

!Create 2D cartesian topology for processes
      call MPI_Cart_create(MPI_COMM_WORLD, ndim, dims, 
     &       period, reorder, comm2D, ierr)
      call MPI_Comm_rank(comm2D, id2D, ierr)
      call MPI_Cart_coords(comm2D, id2D, ndim, coords2D, ierr)
!Create 1D row subgrids
      belongs(0) = .false.
      belongs(1) = .true.  ! this dimension belongs to subgrid
      call MPI_Cart_sub(comm2D, belongs, commrow, ierr)
!Create 1D column subgrids
      belongs(0) = .true.  ! this dimension belongs to subgrid
      belongs(1) = .false.
      call MPI_Cart_sub(comm2D, belongs, commcol, ierr)

Shown in Figure a below is a 3-by-2 cartesian topology where the index pair "i,j" represents row "i" and column "j". The number in parentheses represents the rank number associated with the 2D cartesian grid. Figure b shows the row subgrids while Figure c shows the column subgrids.

Figure a.
2D Cartesian Grid
0,0 (0)0,1 (1)
1,0 (2)1,1 (3)
2,0 (4)2,1 (5)
Figure b.
Row Subgrids
0,0 (0)0,1 (1)
1,0 (2)1,1 (3)
2,0 (4)2,1 (5)
Figure c.
Column Subgrids
0,0 (0)0,1 (1)
1,0 (2)1,1 (3)
2,0 (4)2,1 (5)

Here is a fortran example demonstrating the column subgrid.


Note that: