HP-MPI User's Guide (11th Edition)

Example applications
cart.C
Appendix A 247
MPI_Barrier(comm);
// Each process prints its profile
printf("global rank %d: cartesian rank %d, coordinate (%d,
%d)\n",
grank, lrank, coords[0], coords[1]);
}
// Program body
//
// Define a torus topology and demonstrate shift operations.
//
void body(void)
{
Node node;
node.profile();
node.print();
node.shift(NORTH);
node.print();
node.shift(EAST);
node.print();
node.shift(SOUTH);
node.print();
node.shift(WEST);
node.print();
}
//
// Main program---it is probably a good programming practice to
call
// MPI_Init() and MPI_Finalize() here.
//
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
body();
MPI_Finalize();
}
cart output
The output from running the cart executable is shown below. The
application was run with -np = 4.
Dimensions: (2, 2)
global rank 0: cartesian rank 0, coordinate (0, 0)
global rank 1: cartesian rank 1, coordinate (0, 1)
global rank 3: cartesian rank 3, coordinate (1, 1)
global rank 2: cartesian rank 2, coordinate (1, 0)
(0, 0) holds 0
(1, 0) holds 2