Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / comm_idup_iallreduce.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2015 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "mpi.h"
11 #include "mpitest.h"
12
13 #define ITERS 10
14
15 /* This test uses several scenarios to overlap iallreduce and comm_idup
16  * 1.)  Use comm_idup  duplicate the COMM_WORLD and do iallreduce
17  *      on the COMM_WORLD
18  * 2.)  Do the above test in a loop
19  * 3.)  Duplicate  COMM_WORLD, overalp iallreduce on one
20  *      communicator with comm_idup on the nother communicator
21  * 4.)  Split MPI_COMM_WORLD, communicate on the split communicator
22         while dublicating COMM_WORLD
23  *  5.) Duplicate the split communicators with comm_idup
24  *      while communicating  onCOMM_WORLD
25  *  6.) Create an inter-communicator and duplicate it with comm_idup while
26  *      communicating on the inter-communicator
27  *  7.) Duplicate the inter-communicator whil communicate on COMM_WORLD
28  *  8.) Merge the inter-communicator to an intra-communicator and idup it,
29  *      overlapping with communication on MPI_COMM_WORLD
30  *  9.) Communicate on the merge communicator, while duplicating COMM_WORLD
31 */
32
33 int main(int argc, char **argv)
34 {
35     int errs = 0;
36     int i;
37     int rank, size, lrank, lsize, rsize, isize;
38     int in, out, sol;
39
40     MPI_Comm newcomm, newcomm_v[ITERS], dup_comm, split, ic, merge;
41     MPI_Request sreq[ITERS * 2];
42
43     MTest_Init(&argc, &argv);
44     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
45     MPI_Comm_size(MPI_COMM_WORLD, &size);
46
47     if (size < 2) {
48         printf("this test requires at least 2 processes\n");
49         MPI_Abort(MPI_COMM_WORLD, 1);
50     }
51
52     /* set input buffer and compare buffer */
53     in = 1;
54     sol = size;
55     MPI_Comm_idup(MPI_COMM_WORLD, &newcomm, &sreq[0]);
56     MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[1]);
57
58     MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
59     /* Test results of overlapping allreduce */
60     if (sol != out)
61         errs++;
62     /*Test new communicator */
63     errs += MTestTestComm(newcomm);
64     MPI_Comm_free(&newcomm);
65
66     for (i = 0; i < ITERS; i++) {
67         MPI_Comm_idup(MPI_COMM_WORLD, &newcomm_v[i], &sreq[i]);
68         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[i + ITERS]);
69     }
70     MPI_Waitall(ITERS * 2, sreq, MPI_STATUS_IGNORE);
71
72     for (i = 0; i < ITERS; i++) {
73         errs += MTestTestComm(newcomm_v[i]);
74         MPI_Comm_free(&newcomm_v[i]);
75     }
76
77     MPI_Comm_dup(MPI_COMM_WORLD, &dup_comm);
78
79     if (rank == 0) {
80         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
81         MPI_Comm_idup(dup_comm, &newcomm, &sreq[1]);
82         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
83     }
84     else {
85         MPI_Comm_idup(dup_comm, &newcomm, &sreq[1]);
86         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
87         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
88     }
89     /* Test Iallreduce */
90     if (sol != out)
91         errs++;
92
93     /*Test new communicator */
94     errs += MTestTestComm(newcomm);
95
96     MPI_Comm_free(&newcomm);
97     MPI_Comm_free(&dup_comm);
98
99     MPI_Comm_split(MPI_COMM_WORLD, rank % 2, rank, &split);
100     MPI_Comm_rank(split, &lrank);
101     MPI_Comm_size(split, &lsize);
102
103     sol = lsize;
104     if (lrank == 0) {
105         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, split, &sreq[0]);
106         MPI_Comm_idup(MPI_COMM_WORLD, &newcomm, &sreq[1]);
107         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
108     }
109     else {
110         MPI_Comm_idup(MPI_COMM_WORLD, &newcomm, &sreq[1]);
111         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, split, &sreq[0]);
112         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
113     }
114     /* Test Iallreduce */
115     if (sol != out)
116         errs++;
117
118     /* Test new communicator */
119     errs += MTestTestComm(newcomm);
120     MPI_Comm_free(&newcomm);
121     sol = size;
122
123     if (lrank == 0) {
124         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
125         MPI_Comm_idup(split, &newcomm, &sreq[1]);
126         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
127     }
128     else {
129         MPI_Comm_idup(split, &newcomm, &sreq[1]);
130         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
131         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
132     }
133     /* Test Iallreduce */
134     if (sol != out)
135         errs++;
136
137     /* Test new communicator */
138     errs += MTestTestComm(newcomm);
139     MPI_Comm_free(&newcomm);
140
141     MPI_Intercomm_create(split, 0, MPI_COMM_WORLD, (rank == 0 ? 1 : 0), 1234, &ic);
142     MPI_Comm_remote_size(ic, &rsize);
143
144     sol = rsize;
145
146     MPI_Comm_idup(ic, &newcomm, &sreq[1]);
147     MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, ic, &sreq[0]);
148     MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
149
150
151     if (sol != out)
152         errs++;
153     /* Test new inter communicator */
154     errs += MTestTestComm(newcomm);
155     MPI_Comm_free(&newcomm);
156
157     sol = lsize;
158     if (lrank == 0) {
159         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, split, &sreq[0]);
160         MPI_Comm_idup(ic, &newcomm, &sreq[1]);
161         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
162     }
163     else {
164         MPI_Comm_idup(ic, &newcomm, &sreq[1]);
165         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, split, &sreq[0]);
166         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
167     }
168     /* Test Iallreduce resutls for split-communicator */
169     if (sol != out)
170         errs++;
171     /* Test new inter-communicator */
172
173     errs += MTestTestComm(newcomm);
174     MPI_Comm_free(&newcomm);
175
176     MPI_Intercomm_merge(ic, rank % 2, &merge);
177     MPI_Comm_size(merge, &isize);
178
179     sol = size;
180     if (rank == 0) {
181         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
182         MPI_Comm_idup(merge, &newcomm, &sreq[1]);
183         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
184     }
185     else {
186         MPI_Comm_idup(merge, &newcomm, &sreq[1]);
187         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
188         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
189     }
190
191
192     if (sol != out)
193         errs++;
194     /* Test new communicator */
195     errs += MTestTestComm(newcomm);
196     MPI_Comm_free(&newcomm);
197     sol = isize;
198
199     if (rank == 0) {
200         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, merge, &sreq[0]);
201         MPI_Comm_idup(MPI_COMM_WORLD, &newcomm, &sreq[1]);
202         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
203     }
204     else {
205         MPI_Comm_idup(MPI_COMM_WORLD, &newcomm, &sreq[1]);
206         MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, merge, &sreq[0]);
207         MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
208     }
209
210     MPI_Comm_free(&merge);
211     MPI_Comm_free(&newcomm);
212     MPI_Comm_free(&split);
213     MPI_Comm_free(&ic);
214
215     MTest_Finalize(errs);
216     MPI_Finalize();
217     return 0;
218 }