MPI_Cart_rank Example

## MPI_Cart_rank Example

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.

 `````` ``` ```

## Output

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.

 `````` tonka:virtual_topology/codes % cart_rank_example -np 6 MPI_PROC_NULL = -1 i j myid -3 0 0 -3 1 1 -3 2 -1 -2 0 2 -2 1 3 -2 2 -1 -1 0 4 -1 1 5 -1 2 -1 0 0 0 0 1 1 0 2 -1 1 0 2 1 1 3 1 2 -1 2 0 4 2 1 5 2 2 -1 3 0 0 3 1 1 3 2 -1 4 0 2 4 1 3 4 2 -1 5 0 4 5 1 5 5 2 -1 ``` ```