1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2015 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
15 /* This test uses several scenarios to overlap iallreduce and comm_idup
16 * 1.) Use comm_idup dublicate the COMM_WORLD and do iallreduce
18 * 2.) Do the above test in a loop
19 * 3.) Dublicate 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.) Ceate an inter-communicator and duplicate it with comm_idup while
26 * communicating on the inter-communicator
27 * 7.) Dublicate 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
33 int main(int argc, char **argv)
37 int rank, size, lrank, lsize, rsize, isize;
40 MPI_Comm newcomm, newcomm_v[ITERS], dup_comm, split, ic, merge;
41 MPI_Request sreq[ITERS * 2];
43 MTest_Init(&argc, &argv);
44 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
45 MPI_Comm_size(MPI_COMM_WORLD, &size);
48 printf("this test requires at least 2 processes\n");
49 MPI_Abort(MPI_COMM_WORLD, 1);
52 /* set input buffer and compare buffer */
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]);
58 MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
59 /* Test results of overlapping allreduce */
62 /*Test new communicator */
63 errs += MTestTestComm(newcomm);
64 MPI_Comm_free(&newcomm);
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]);
70 MPI_Waitall(ITERS * 2, sreq, MPI_STATUS_IGNORE);
72 for (i = 0; i < ITERS; i++) {
73 errs += MTestTestComm(newcomm_v[i]);
74 MPI_Comm_free(&newcomm_v[i]);
77 MPI_Comm_dup(MPI_COMM_WORLD, &dup_comm);
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);
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);
93 /*Test new communicator */
94 errs += MTestTestComm(newcomm);
96 MPI_Comm_free(&newcomm);
97 MPI_Comm_free(&dup_comm);
99 MPI_Comm_split(MPI_COMM_WORLD, rank % 2, rank, &split);
100 MPI_Comm_rank(split, &lrank);
101 MPI_Comm_size(split, &lsize);
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);
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);
114 /* Test Iallreduce */
118 /* Test new communicator */
119 errs += MTestTestComm(newcomm);
120 MPI_Comm_free(&newcomm);
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);
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);
133 /* Test Iallreduce */
137 /* Test new communicator */
138 errs += MTestTestComm(newcomm);
139 MPI_Comm_free(&newcomm);
141 MPI_Intercomm_create(split, 0, MPI_COMM_WORLD, (rank == 0 ? 1 : 0), 1234, &ic);
142 MPI_Comm_remote_size(ic, &rsize);
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);
153 /* Test new inter communicator */
154 errs += MTestTestComm(newcomm);
155 MPI_Comm_free(&newcomm);
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);
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);
168 /* Test Iallreduce resutls for split-communicator */
171 /* Test new inter-communicator */
173 errs += MTestTestComm(newcomm);
174 MPI_Comm_free(&newcomm);
176 MPI_Intercomm_merge(ic, rank % 2, &merge);
177 MPI_Comm_size(merge, &isize);
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);
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);
194 /* Test new communicator */
195 errs += MTestTestComm(newcomm);
196 MPI_Comm_free(&newcomm);
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);
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);
210 MPI_Comm_free(&merge);
211 MPI_Comm_free(&newcomm);
212 MPI_Comm_free(&split);
215 MTest_Finalize(errs);