Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c5f103edbaa4e1463bb0cc0327656c20bde0de72
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / cmsplit.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 <stdlib.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Test comm split";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0;
19     int rank, size, color, srank;
20     MPI_Comm      comm, scomm;
21
22     MTest_Init( &argc, &argv );
23
24     MPI_Comm_dup( MPI_COMM_WORLD, &comm );
25
26     MPI_Comm_rank( comm, &rank );
27     MPI_Comm_size( comm, &size );
28
29     if (size < 4) {
30         fprintf( stderr, "This test requires at least four processes." );
31         MPI_Abort( MPI_COMM_WORLD, 1 );
32     }
33
34     color = MPI_UNDEFINED;
35     if (rank < 2) color = 1;
36     MPI_Comm_split( comm, color, size - rank, &scomm );
37     
38     if (rank < 2) {
39         /* Check that the ranks are ordered correctly */
40         MPI_Comm_rank( scomm, &srank );
41         if (srank != 1 - rank) {
42             errs++;
43         }
44         MPI_Comm_free( &scomm );
45     }
46     else {
47         if (scomm != MPI_COMM_NULL) {
48             errs++;
49         }
50     }
51     MPI_Comm_free( &comm );
52     MTest_Finalize( errs );
53     MPI_Finalize();
54     return 0;
55 }