Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
functioning MPI_Comm_get_name, MPI_Comm_set_name
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / iccreate.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2007 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  * This program tests that MPI_Comm_create applies to intercommunicators;
14  * this is an extension added in MPI-2
15  */
16 int main(int argc, char *argv[])
17 {
18     int errs = 0;
19     int size, isLeft, wrank;
20     MPI_Comm intercomm, newcomm;
21     MPI_Group oldgroup, newgroup;
22
23     MTest_Init(&argc, &argv);
24
25     MPI_Comm_size(MPI_COMM_WORLD, &size);
26     if (size < 4) {
27         printf("This test requires at least 4 processes\n");
28         MPI_Abort(MPI_COMM_WORLD, 1);
29     }
30     MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
31
32     while (MTestGetIntercomm(&intercomm, &isLeft, 2)) {
33         int ranks[10], nranks, result;
34
35         if (intercomm == MPI_COMM_NULL)
36             continue;
37
38         MPI_Comm_group(intercomm, &oldgroup);
39         ranks[0] = 0;
40         nranks = 1;
41         MTestPrintfMsg(1, "Creating a new intercomm 0-0\n");
42         MPI_Group_incl(oldgroup, nranks, ranks, &newgroup);
43         MPI_Comm_create(intercomm, newgroup, &newcomm);
44
45         /* Make sure that the new communicator has the appropriate pieces */
46         if (newcomm != MPI_COMM_NULL) {
47             int new_rsize, new_size, flag, commok = 1;
48
49             MPI_Comm_set_name(newcomm, (char *) "Single rank in each group");
50             MPI_Comm_test_inter(intercomm, &flag);
51             if (!flag) {
52                 errs++;
53                 printf("[%d] Output communicator is not an intercomm\n", wrank);
54                 commok = 0;
55             }
56
57             MPI_Comm_remote_size(newcomm, &new_rsize);
58             MPI_Comm_size(newcomm, &new_size);
59             /* The new communicator has 1 process in each group */
60             if (new_rsize != 1) {
61                 errs++;
62                 printf("[%d] Remote size is %d, should be one\n", wrank, new_rsize);
63                 commok = 0;
64             }
65             if (new_size != 1) {
66                 errs++;
67                 printf("[%d] Local size is %d, should be one\n", wrank, new_size);
68                 commok = 0;
69             }
70             /* ... more to do */
71             if (commok) {
72                 errs += MTestTestComm(newcomm);
73             }
74         }
75         MPI_Group_free(&newgroup);
76         if (newcomm != MPI_COMM_NULL) {
77             MPI_Comm_free(&newcomm);
78         }
79
80         /* Now, do a sort of dup, using the original group */
81         MTestPrintfMsg(1, "Creating a new intercomm (manual dup)\n");
82         MPI_Comm_create(intercomm, oldgroup, &newcomm);
83         MPI_Comm_set_name(newcomm, (char *) "Dup of original");
84         MTestPrintfMsg(1, "Creating a new intercomm (manual dup (done))\n");
85
86         MPI_Comm_compare(intercomm, newcomm, &result);
87         MTestPrintfMsg(1, "Result of comm/intercomm compare is %d\n", result);
88         if (result != MPI_CONGRUENT) {
89             const char *rname = 0;
90             errs++;
91             switch (result) {
92             case MPI_IDENT:
93                 rname = "IDENT";
94                 break;
95             case MPI_CONGRUENT:
96                 rname = "CONGRUENT";
97                 break;
98             case MPI_SIMILAR:
99                 rname = "SIMILAR";
100                 break;
101             case MPI_UNEQUAL:
102                 rname = "UNEQUAL";
103                 break;
104                 printf("[%d] Expected MPI_CONGRUENT but saw %d (%s)", wrank, result, rname);
105                 fflush(stdout);
106             }
107         }
108         else {
109             /* Try to communication between each member of intercomm */
110             errs += MTestTestComm(newcomm);
111         }
112
113         if (newcomm != MPI_COMM_NULL) {
114             MPI_Comm_free(&newcomm);
115         }
116         /* test that an empty group in either side of the intercomm results in
117          * MPI_COMM_NULL for all members of the comm */
118         if (isLeft) {
119             /* left side reuses oldgroup, our local group in intercomm */
120             MPI_Comm_create(intercomm, oldgroup, &newcomm);
121         }
122         else {
123             /* right side passes MPI_GROUP_EMPTY */
124             MPI_Comm_create(intercomm, MPI_GROUP_EMPTY, &newcomm);
125         }
126         if (newcomm != MPI_COMM_NULL) {
127             printf("[%d] expected MPI_COMM_NULL, but got a different communicator\n", wrank);
128             fflush(stdout);
129             errs++;
130         }
131
132         if (newcomm != MPI_COMM_NULL) {
133             MPI_Comm_free(&newcomm);
134         }
135         MPI_Group_free(&oldgroup);
136         MPI_Comm_free(&intercomm);
137     }
138
139     MTest_Finalize(errs);
140
141     MPI_Finalize();
142
143     return 0;
144 }