Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc++'
[simgrid.git] / teshsuite / smpi / mpich3-test / topo / cartsuball.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 size, dims[2], periods[2], remain[2];
15     int result, rank;
16     MPI_Comm comm, newcomm;
17
18     MTest_Init( &argc, &argv );
19
20     /* First, create a 1-dim cartesian communicator */
21     periods[0] = 0;
22     MPI_Comm_size( MPI_COMM_WORLD, &size );
23     dims[0] = size;
24     MPI_Cart_create( MPI_COMM_WORLD, 1, dims, periods, 0, &comm );
25     
26     /* Now, extract a communicator with no dimensions */
27     remain[0] = 0;
28     MPI_Cart_sub( comm, remain, &newcomm );
29
30     MPI_Comm_rank(comm, &rank);
31
32     if (rank == 0) {
33         /* This should be congruent to MPI_COMM_SELF */
34         MPI_Comm_compare( MPI_COMM_SELF, newcomm, &result );
35         if (result != MPI_CONGRUENT) {
36             errs++;
37             printf( "cart sub to size 0 did not give self\n" );
38         }
39         MPI_Comm_free( &newcomm );
40     }
41     else if (newcomm != MPI_COMM_NULL) {
42         errs++;
43         printf( "cart sub to size 0 did not give null\n" );
44     }
45
46     /* Free the new communicator so that storage leak tests will
47        be happy */
48     MPI_Comm_free( &comm );
49     
50     MTest_Finalize( errs );
51     MPI_Finalize();
52     return 0;
53   
54 }