MPI_Cart_get retrieves properties such as periodicity and size of a subgrid.

On occasions, a subgrid communicator may be created in one routine and is subsequently used in another routine. If only the communicator is available in the latter, this routine, along with MPI_Cartdim_get, may be used to determine the size and other pertinent information regarding the subgrid.

Fortran Syntax

Subroutine MPI_Cart_get(subgrid_comm, ndims, dims, period, coords, ierr)

C Syntax

int MPI_Cart_get(MPI_Comm subgrid_comm, int dims, int *ndims, int *periods, int *coords)

Example in Fortran

create cartesian topology for processes
      dims(1) = nv
      dims(2) = mv
      call MPI_Cart_create(MPI_COMM_WORLD, ndim, dims, 
     &       period, reorder, grid_comm, ierr)
      call MPI_Comm_rank(grid_comm, me, ierr)
      call MPI_Cart_coords(grid_comm, me, ndim, coords, ierr)
create row subgrids
      remain(0) = 1
      remain(1) = 0
      call MPI_Cart_sub(grid_comm, remain, row_comm, ierr)
c**Retrieve subgrid dimensions and other info
      call MPI_Cartdim_get(row_comm, mdims, ierr)
      call MPI_Cart_get(row_comm, mdims, dims, period, 
     &     row_coords, ierr)

Shown in Figure a below is a 3-by-2 cartesian topology (grid) where the index pair “i,j” represent row “i” and column “j”. The number in parentheses represents the rank number associated with the cartesian grid.

Figure a.
Cartesian Grid
0,0 (0) 0,1 (1)
1,0 (2) 1,1 (3)
2,0 (4) 2,1 (5)

We have just demonstrated the use of MPI_Cart_get to retrieve information on a subgrid communicator. Often, MPI_Cartdim_get needs to be called first, as ndims, the dimensions of the subgrid, is needed as input to MPI_Cart_get.