This page imported from: /afs/bu.edu/cwis/webuser/web/s/c/scv/documentation/tutorials/MPI/alliance/virtual_topology/codes/cart_rank_example.html
In this example, the objective is to demonstrate the usage of
MPI_Cart_rank. With six (6) active processes, we
proceed to create a 2D cartesian topology for these 6 processes.
This results in a 3×2 cartesian topology representation for the
6 processes. Furthermore, we impose a cyclic boundary condition
along the columns — but not the rows – of this 2D grid.
Given a row and a column number, MPI_Cart_rank is called to
obtain its original, 1D, rank number. Repeating this procedure
for a range of rows and columns results in a correlation table
between these two representations.
In the following, the first (i) and second (j) column of data represent the
row and column coordinates, respectively, of the cartesian grid of the
processes. The third column of data represent its equivalence in
the original 1D process rank, myid.
A negative number in the third column indicates that the specified
row, or column, number, after taken into account the cyclic condition,
is out of bound and hence myid corresponding
to that particular coordinate pair is set to MPI_PROC_NULL.
The value of MPI_PROC_NULL is implementation dependent. In this case, it
happens to be -1. In this 3×2 setting each column gets the wrap-around.
So “i” can take on any integer, negative or positive, without causing
out-of-bound because the cyclic condition will take care of it. Since
no cyclic condition is imposed along the rows, any “j” outside of
0 and 1 will effect an out-of-bound condition.