MPI_Cart_rank finds the corresponding process rank of the cartesian coordinates of a cartesian communicator.
Subroutine MPI_Cart_rank(comm, coords, rank, ierr)
int MPI_Cart_rank(MPI_Comm comm, int *coords, int *rank)
Example in Fortran
Once a cartesian communicator has been established, repeated applications of
MPI_Cart_rank for all possible values of the cartesian coordinates produce a correlation table of the cartesian coordinates and their corresponding process ranks.
Shown in Figure a below is the resulting 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 coordinates.
|0,0 (0)||0,1 (1)|
|1,0 (2)||1,1 (3)|
|2,0 (4)||2,1 (5)|
Here is the fortran code used to generate the above tables.
- the rank number of the cartesian grid (i.e., number in parentheses) need not be the same as those corresponding to MPI_COMM_WORLD.
- this routine is the reciprocal of MPI_Cart_coords.
- the return rank of the routine could be negative (with the value MPI_PROC_NULL), indicating that the specified
coordsis out of bound.