9 int main( int argc, char **argv )
13 int periods[NUM_DIMS];
14 int new_coords[NUM_DIMS];
15 int new_new_coords[NUM_DIMS];
17 int left, right, top, bottom;
20 MPI_Init( &argc, &argv );
22 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
23 MPI_Comm_size( MPI_COMM_WORLD, &size );
25 /* Clear dims array and get dims for topology */
26 for(i=0;i<NUM_DIMS;i++) { dims[i] = 0; periods[i] = 0; }
27 MPI_Dims_create ( size, NUM_DIMS, dims );
29 /* Make a new communicator with a topology */
30 MPI_Cart_create ( MPI_COMM_WORLD, 2, dims, periods, reorder, &comm_cart );
32 /* Does the mapping from rank to coords work */
33 MPI_Cart_coords ( comm_cart, rank, NUM_DIMS, new_coords );
35 /* 2nd call to Cart coords gives us an error - why? */
36 MPI_Cart_coords ( comm_cart, rank, NUM_DIMS, new_new_coords ); /***34***/
39 MPI_Cart_shift( comm_cart, 0, 1, &left, &right );
40 MPI_Cart_shift( comm_cart, 1, 1, &bottom, &top );
50 printf( "[%d] final dims = [%d,%d]\n", rank, dims[0], dims[1] );
51 printf( "[%d] left = %d, right = %d, bottom = %d, top = %d\n",
52 rank, left, right, bottom, top );
56 MPI_Comm_free( &comm_cart );