3 /* stdlib.h Needed for malloc declaration */
9 int main( int argc, char **argv )
14 int periods[NUM_DIMS];
18 MPI_Init( &argc, &argv );
20 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
21 MPI_Comm_size( MPI_COMM_WORLD, &size );
23 /* Clear dims array and get dims for topology */
24 for(i=0;i<NUM_DIMS;i++) { dims[i] = 0; periods[i] = 0; }
25 MPI_Dims_create ( size, NUM_DIMS, dims );
27 /* Look at what rankings a cartesian topology MIGHT have */
28 MPI_Cart_map( MPI_COMM_WORLD, 2, dims, periods, &new_rank );
30 /* Check that all new ranks are used exactly once */
31 rbuf = (int *)malloc( size * sizeof(int) );
32 sbuf = (int *)malloc( size * sizeof(int) );
34 MPI_Abort( MPI_COMM_WORLD, 1 );
36 for (i=0; i<size; i++)
39 MPI_Reduce( sbuf, rbuf, size, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD );
41 for (i=0; i<size; i++) {
44 fprintf( stderr, "Rank %d used %d times\n", i, rbuf[i] );
48 printf( "Cart map test passed\n" );