Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / topol / cart2.c
1 #include "mpi.h"
2 #include <stdio.h>
3 #include "test.h"
4
5 #define NUM_DIMS 2
6
7 int verbose = 0; 
8
9 int main( int argc, char **argv )
10 {
11     int              rank, size, i;
12     int              dims[NUM_DIMS];
13     int              periods[NUM_DIMS];
14     int              new_coords[NUM_DIMS];
15     int              new_new_coords[NUM_DIMS];
16     int              reorder = 1;
17     int              left, right, top, bottom;
18     MPI_Comm         comm_cart;
19
20     MPI_Init( &argc, &argv );
21
22     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
23     MPI_Comm_size( MPI_COMM_WORLD, &size );
24
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 );
28
29     /* Make a new communicator with a topology */
30     MPI_Cart_create ( MPI_COMM_WORLD, 2, dims, periods, reorder, &comm_cart );
31
32     /* Does the mapping from rank to coords work */
33     MPI_Cart_coords ( comm_cart, rank, NUM_DIMS, new_coords ); 
34
35     /* 2nd call to Cart coords gives us an error - why? */
36     MPI_Cart_coords ( comm_cart, rank, NUM_DIMS, new_new_coords ); /***34***/ 
37
38     /* Try cart shift */
39     MPI_Cart_shift( comm_cart, 0, 1, &left, &right );
40     MPI_Cart_shift( comm_cart, 1, 1, &bottom, &top );
41
42     if (dims[0] == 2) {
43         /* We should see
44            [0] -1 2 -1 1
45            [1] -1 3 0 -1
46            [2] 0 -1 -1 3
47            [3] 1 -1 2 -1
48         */
49         if (verbose) {
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 );
53         }
54     }
55
56     MPI_Comm_free( &comm_cart );
57     Test_Waitforall( );
58     MPI_Finalize();
59     
60     return 0;
61 }