Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add mpich3 topo tests
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / icm.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2004 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 intercomm merge, including the choice of the high value";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0;
19     int rank, size, rsize;
20     int nsize, nrank;
21     int minsize = 2;
22     int isLeft;
23     MPI_Comm      comm, comm1, comm2, comm3, comm4;
24
25     MTest_Init( &argc, &argv );
26
27     /* The following illustrates the use of the routines to 
28        run through a selection of communicators and datatypes.
29        Use subsets of these for tests that do not involve combinations 
30        of communicators, datatypes, and counts of datatypes */
31     while (MTestGetIntercomm( &comm, &isLeft, minsize )) {
32         if (comm == MPI_COMM_NULL) continue;
33         /* Determine the sender and receiver */
34         MPI_Comm_rank( comm, &rank );
35         MPI_Comm_remote_size( comm, &rsize );
36         MPI_Comm_size( comm, &size );
37
38         /* Try building intercomms */
39         MPI_Intercomm_merge( comm, isLeft, &comm1 );
40         /* Check the size and ranks */
41         MPI_Comm_size( comm1, &nsize );
42         MPI_Comm_rank( comm1, &nrank );
43         if (nsize != size + rsize) {
44             errs++;
45             printf( "(1) Comm size is %d but should be %d\n", nsize,
46                     size + rsize );
47             if (isLeft) {
48                 /* The left processes should be high */
49                 if (nrank != rsize + rank) {
50                     errs++;
51                     printf( "(1) rank for high process is %d should be %d\n",
52                             nrank, rsize + rank );
53                 }
54             }
55             else {
56                 /* The right processes should be low */
57                 if (nrank != rank) {
58                     errs++;
59                     printf( "(1) rank for low process is %d should be %d\n",
60                             nrank, rank );
61                 }
62             }
63         }
64         
65         MPI_Intercomm_merge( comm, !isLeft, &comm2 ); 
66         /* Check the size and ranks */
67         MPI_Comm_size( comm1, &nsize );
68         MPI_Comm_rank( comm1, &nrank );
69         if (nsize != size + rsize) {
70             errs++;
71             printf( "(2) Comm size is %d but should be %d\n", nsize,
72                     size + rsize );
73             if (!isLeft) {
74                 /* The right processes should be high */
75                 if (nrank != rsize + rank) {
76                     errs++;
77                     printf( "(2) rank for high process is %d should be %d\n",
78                             nrank, rsize + rank );
79                 }
80             }
81             else {
82                 /* The left processes should be low */
83                 if (nrank != rank) {
84                     errs++;
85                     printf( "(2) rank for low process is %d should be %d\n",
86                             nrank, rank );
87                 }
88             }
89         }
90         
91
92         MPI_Intercomm_merge( comm, 0, &comm3 ); 
93
94         MPI_Intercomm_merge( comm, 1, &comm4 ); 
95         
96         MPI_Comm_free( &comm1 );
97         MPI_Comm_free( &comm2 );
98         MPI_Comm_free( &comm3 ); 
99         MPI_Comm_free( &comm4 );
100       
101         MTestFreeComm( &comm );
102     }
103
104     MTest_Finalize( errs );
105     MPI_Finalize();
106     return 0;
107 }