Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc++'
[simgrid.git] / teshsuite / smpi / mpich3-test / topo / cartmap1.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 int main( int argc, char *argv[] )
12 {
13     int errs = 0;
14     int dims[2];
15     int periods[2];
16     int size, rank, newrank;
17
18     MTest_Init( &argc, &argv );
19
20     MPI_Comm_size( MPI_COMM_WORLD, &size );
21     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
22     
23     /* This defines a one dimensional cartision grid with a single point */
24     periods[0] = 1;
25     dims[0] = 1;
26
27     MPI_Cart_map( MPI_COMM_WORLD, 1, dims, periods, &newrank );
28     if (rank > 0) {
29         if (newrank != MPI_UNDEFINED) {
30             errs++;
31             printf( "rank outside of input communicator not UNDEFINED\n" );
32         }
33     }
34     else {
35         if (rank != newrank) {
36             errs++;
37             printf( "Newrank not defined and should be 0\n" );
38         }
39     }
40
41
42     /* As of MPI 2.1, a 0-dimensional topology is valid (its also a
43        point) */
44     MPI_Cart_map( MPI_COMM_WORLD, 0, dims, periods, &newrank );
45     if (rank > 0) {
46         if (newrank != MPI_UNDEFINED) {
47             errs++;
48             printf( "rank outside of input communicator not UNDEFINED\n" );
49         }
50     }
51     else {
52         /* rank == 0 */
53         if (rank != newrank) {
54             errs++;
55             printf( "Newrank not defined and should be 0\n" );
56         }
57     }
58
59
60     MTest_Finalize( errs );
61     MPI_Finalize();
62     return 0;
63   
64 }