Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into CRTP
[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)
33             continue;
34         /* Determine the sender and receiver */
35         MPI_Comm_rank(comm, &rank);
36         MPI_Comm_remote_size(comm, &rsize);
37         MPI_Comm_size(comm, &size);
38
39         /* Try building intercomms */
40         MPI_Intercomm_merge(comm, isLeft, &comm1);
41         /* Check the size and ranks */
42         MPI_Comm_size(comm1, &nsize);
43         MPI_Comm_rank(comm1, &nrank);
44         if (nsize != size + rsize) {
45             errs++;
46             printf("(1) Comm size is %d but should be %d\n", nsize, 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", nrank, rsize + rank);
52                 }
53             }
54             else {
55                 /* The right processes should be low */
56                 if (nrank != rank) {
57                     errs++;
58                     printf("(1) rank for low process is %d should be %d\n", nrank, rank);
59                 }
60             }
61         }
62
63         MPI_Intercomm_merge(comm, !isLeft, &comm2);
64         /* Check the size and ranks */
65         MPI_Comm_size(comm1, &nsize);
66         MPI_Comm_rank(comm1, &nrank);
67         if (nsize != size + rsize) {
68             errs++;
69             printf("(2) Comm size is %d but should be %d\n", nsize, size + rsize);
70             if (!isLeft) {
71                 /* The right processes should be high */
72                 if (nrank != rsize + rank) {
73                     errs++;
74                     printf("(2) rank for high process is %d should be %d\n", nrank, rsize + rank);
75                 }
76             }
77             else {
78                 /* The left processes should be low */
79                 if (nrank != rank) {
80                     errs++;
81                     printf("(2) rank for low process is %d should be %d\n", nrank, rank);
82                 }
83             }
84         }
85
86
87         MPI_Intercomm_merge(comm, 0, &comm3);
88
89         MPI_Intercomm_merge(comm, 1, &comm4);
90
91         MPI_Comm_free(&comm1);
92         MPI_Comm_free(&comm2);
93         MPI_Comm_free(&comm3);
94         MPI_Comm_free(&comm4);
95
96         MTestFreeComm(&comm);
97     }
98
99     MTest_Finalize(errs);
100     MPI_Finalize();
101     return 0;
102 }