MPI_Cart_sub
MPI_Cart_sub creates new communicators for subgrids of up to (N1) dimensions from an Ndimensional 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.

Shown in Figure a below is a 3by2 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.



Here is a fortran example demonstrating the column subgrid.
As another example, lets look at a 3D cartesian grid of 3x2x4. Calling MPI_Cart_sub
with belongs
array defined as

yields four 3by2 subgrids. The output of a fortran code for this particular arrangement is shown below:
MPI_Cart_sub example: 3x2x4 cartesian grid ==> 4 (3x2) subgrids

The above table is illustrated below in four figures, each representing one of the four 2D subgrids of size (3×2). The top set of numbers denote the 3D cartesian grid coordinates with the process rank in that grid enclosed in parentheses. The lower, colored, sets represent the corresponding numbers in the 2D subgrids.





We have just demonstrated the use of MPI_Cart_sub to divide a cartesian grid into subgrids of lower dimensions. On occasions, the information regarding a subgrid may not be available, as in the case where the subgrid communicator was created in one routine and is used in another. In such a situation, MPI_Cartdim_get may be called to find out the dimensions of the subgrid. Armed with this information, additional information may be obtained by calling MPI_Cart_get. We will discuss these routines next.
Note that:
 full length of each dimension of the original grid are used in the subgrids.
 there is a comparable MPI_Comm_split routine to perform similar function.
 MPI_Cartdim_get and MPI_Cart_get can be used to acquire background information of grid (such as dimensions, periodicity).