5 /* This test makes sure that the ordering if reorder is FALSE is
6 as specified in 6.2, virtual topologies
8 At the same time, it duplicates the tests in cart.c, but
14 int main( int argc, char **argv )
19 int periods[NUM_DIMS];
21 int new_coords[NUM_DIMS];
23 MPI_Comm comm_temp, comm_cart, new_comm;
27 int remain_dims[NUM_DIMS];
30 MPI_Init( &argc, &argv );
32 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
33 MPI_Comm_size( MPI_COMM_WORLD, &size );
35 /* Clear dims array and get dims for topology */
36 for(i=0;i<NUM_DIMS;i++) { dims[i] = 0; periods[i] = 0; }
37 MPI_Dims_create ( size, NUM_DIMS, dims );
39 /* Make a new communicator with a topology */
40 MPI_Cart_create ( MPI_COMM_WORLD, 2, dims, periods, reorder, &comm_temp );
41 MPI_Comm_dup ( comm_temp, &comm_cart );
43 /* Determine the status of the new communicator */
44 MPI_Topo_test ( comm_cart, &topo_status );
45 if (topo_status != MPI_CART) {
46 printf( "topo_status of duped comm is not MPI_CART\n" );
50 /* How many dims do we have? */
51 MPI_Cartdim_get( comm_cart, &ndims );
52 if ( ndims != NUM_DIMS ) {
53 printf( "Number of dims of duped comm (%d) should be %d\n",
58 /* Get the topology, does it agree with what we put in? */
59 for(i=0;i<NUM_DIMS;i++) { dims[i] = 0; periods[i] = 0; }
60 MPI_Cart_get ( comm_cart, NUM_DIMS, dims, periods, coords );
62 /* Check that the coordinates are correct */
64 if (rank != coords[1] + coords[0] * dims[1]) {
67 "Did not get expected coordinate (row major required by MPI standard 6.2)\n" );
70 /* Does the mapping from coords to rank work? */
71 MPI_Cart_rank ( comm_cart, coords, &new_rank );
72 if ( new_rank != rank ) {
73 printf( "New rank of duped comm (%d) != old rank (%d)\n",
78 /* Does the mapping from rank to coords work */
79 MPI_Cart_coords ( comm_cart, rank, NUM_DIMS, new_coords );
80 for (i=0;i<NUM_DIMS;i++)
81 if ( coords[i] != new_coords[i] ) {
82 printf( "Old coords[%d] of duped comm (%d) != new_coords (%d)\n",
83 i, coords[i], new_coords[i] );
87 /* Let's shift in each dimension and see how it works! */
88 /* Because it's late and I'm tired, I'm not making this */
89 /* automatically test itself. */
90 for (i=0;i<NUM_DIMS;i++) {
92 MPI_Cart_shift(comm_cart, i, 1, &source, &dest);
94 printf ("[%d] Shifting %d in the %d dimension\n",rank,1,i);
95 printf ("[%d] source = %d dest = %d\n",rank,source,dest);
101 for (i=1; i<NUM_DIMS; i++) remain_dims[i] = 1;
102 MPI_Cart_sub ( comm_cart, remain_dims, &new_comm );
104 /* Determine the status of the new communicator */
105 MPI_Topo_test ( new_comm, &topo_status );
106 if (topo_status != MPI_CART) {
107 printf( "topo_status of cartsub comm is not MPI_CART\n" );
111 /* How many dims do we have? */
112 MPI_Cartdim_get( new_comm, &ndims );
113 if ( ndims != NUM_DIMS-1 ) {
114 printf( "Number of dims of cartsub comm (%d) should be %d\n",
119 /* Get the topology, does it agree with what we put in? */
120 for(i=0;i<NUM_DIMS-1;i++) { dims[i] = 0; periods[i] = 0; }
121 MPI_Cart_get ( new_comm, ndims, dims, periods, coords );
123 /* Does the mapping from coords to rank work? */
124 MPI_Comm_rank ( new_comm, &newnewrank );
125 MPI_Cart_rank ( new_comm, coords, &new_rank );
126 if ( new_rank != newnewrank ) {
127 printf( "New rank of cartsub comm (%d) != old rank (%d)\n",
128 new_rank, newnewrank );
131 /* Does the mapping from rank to coords work */
132 MPI_Cart_coords ( new_comm, new_rank, NUM_DIMS -1, new_coords );
133 for (i=0;i<NUM_DIMS-1;i++)
134 if ( coords[i] != new_coords[i] ) {
135 printf( "Old coords[%d] of cartsub comm (%d) != new_coords (%d)\n",
136 i, coords[i], new_coords[i] );
140 /* We're at the end */
141 MPI_Comm_free( &new_comm );
142 MPI_Comm_free( &comm_temp );
143 MPI_Comm_free( &comm_cart );
145 if (errors) printf( "[%d] done with %d ERRORS!\n", rank,errors );