Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MPI_Iallreduce
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / nonblocking.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2010 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 /* This is a very weak sanity test that all nonblocking collectives specified by
8  * MPI-3 are present in the library and take arguments as expected.  This test
9  * does not check for progress, matching issues, or sensible output buffer
10  * values. */
11
12 #include "mpi.h"
13 #include <stdio.h>
14 #include <stdlib.h>
15
16 #define NUM_INTS (2)
17
18 #define my_assert(cond_)                                                  \
19     do {                                                                  \
20         if (!(cond_)) {                                                   \
21             fprintf(stderr, "assertion (%s) failed, aborting\n", #cond_); \
22             MPI_Abort(MPI_COMM_WORLD, 1);                                 \
23         }                                                                 \
24     } while (0)
25
26 int main(int argc, char **argv)
27 {
28     int errs = 0;
29     int i;
30     int rank, size;
31     int *sbuf = NULL;
32     int *rbuf = NULL;
33     int *scounts = NULL;
34     int *rcounts = NULL;
35     int *sdispls = NULL;
36     int *rdispls = NULL;
37     MPI_Datatype *types = NULL;
38     MPI_Comm comm;
39     MPI_Request req;
40
41     /* intentionally not using MTest_Init/MTest_Finalize in order to make it
42      * easy to take this test and use it as an NBC sanity test outside of the
43      * MPICH test suite */
44     MPI_Init(&argc, &argv);
45
46     comm = MPI_COMM_WORLD;
47
48     MPI_Comm_size(comm, &size);
49     MPI_Comm_rank(comm, &rank);
50
51     /* enough space for every process to contribute at least NUM_INTS ints to any
52      * collective operation */
53     sbuf = malloc(NUM_INTS * size * sizeof(int));
54     my_assert(sbuf);
55     rbuf = malloc(NUM_INTS * size * sizeof(int));
56     my_assert(rbuf);
57     scounts = malloc(size * sizeof(int));
58     my_assert(scounts);
59     rcounts = malloc(size * sizeof(int));
60     my_assert(rcounts);
61     sdispls = malloc(size * sizeof(int));
62     my_assert(sdispls);
63     rdispls = malloc(size * sizeof(int));
64     my_assert(rdispls);
65     types = malloc(size * sizeof(MPI_Datatype));
66     my_assert(types);
67
68     for (i = 0; i < size; ++i) {
69         sbuf[2 * i] = i;
70         sbuf[2 * i + 1] = i;
71         rbuf[2 * i] = i;
72         rbuf[2 * i + 1] = i;
73         scounts[i] = NUM_INTS;
74         rcounts[i] = NUM_INTS;
75         sdispls[i] = i * NUM_INTS;
76         rdispls[i] = i * NUM_INTS;
77         types[i] = MPI_INT;
78     }
79
80     MPI_Ibarrier(comm, &req);
81     MPI_Wait(&req, MPI_STATUS_IGNORE);
82
83     MPI_Ibcast(sbuf, NUM_INTS, MPI_INT, 0, comm, &req);
84     MPI_Wait(&req, MPI_STATUS_IGNORE);
85
86     MPI_Igather(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
87     MPI_Wait(&req, MPI_STATUS_IGNORE);
88
89     if (0 == rank)
90         MPI_Igather(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
91     else
92         MPI_Igather(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
93     MPI_Wait(&req, MPI_STATUS_IGNORE);
94
95     MPI_Igatherv(sbuf, NUM_INTS, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, 0, comm, &req);
96     MPI_Wait(&req, MPI_STATUS_IGNORE);
97
98     if (0 == rank)
99         MPI_Igatherv(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, rbuf, rcounts, rdispls, MPI_INT, 0, comm,
100                      &req);
101     else
102         MPI_Igatherv(sbuf, NUM_INTS, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, 0, comm, &req);
103     MPI_Wait(&req, MPI_STATUS_IGNORE);
104
105     MPI_Iscatter(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
106     MPI_Wait(&req, MPI_STATUS_IGNORE);
107
108     if (0 == rank)
109         MPI_Iscatter(sbuf, NUM_INTS, MPI_INT, MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, 0, comm, &req);
110     else
111         MPI_Iscatter(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
112     MPI_Wait(&req, MPI_STATUS_IGNORE);
113
114     MPI_Iscatterv(sbuf, scounts, sdispls, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
115     MPI_Wait(&req, MPI_STATUS_IGNORE);
116
117     if (0 == rank)
118         MPI_Iscatterv(sbuf, scounts, sdispls, MPI_INT, MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, 0, comm,
119                       &req);
120     else
121         MPI_Iscatterv(sbuf, scounts, sdispls, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
122     MPI_Wait(&req, MPI_STATUS_IGNORE);
123
124     MPI_Iallgather(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, comm, &req);
125     MPI_Wait(&req, MPI_STATUS_IGNORE);
126
127     MPI_Iallgather(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, rbuf, NUM_INTS, MPI_INT, comm, &req);
128     MPI_Wait(&req, MPI_STATUS_IGNORE);
129
130     MPI_Iallgatherv(sbuf, NUM_INTS, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, comm, &req);
131     MPI_Wait(&req, MPI_STATUS_IGNORE);
132
133     MPI_Iallgatherv(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, rbuf, rcounts, rdispls, MPI_INT, comm,
134                     &req);
135     MPI_Wait(&req, MPI_STATUS_IGNORE);
136
137     MPI_Ialltoall(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, comm, &req);
138     MPI_Wait(&req, MPI_STATUS_IGNORE);
139
140     MPI_Ialltoall(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, rbuf, NUM_INTS, MPI_INT, comm, &req);
141     MPI_Wait(&req, MPI_STATUS_IGNORE);
142
143     MPI_Ialltoallv(sbuf, scounts, sdispls, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, comm, &req);
144     MPI_Wait(&req, MPI_STATUS_IGNORE);
145
146     MPI_Ialltoallv(MPI_IN_PLACE, NULL, NULL, MPI_DATATYPE_NULL, rbuf, rcounts, rdispls, MPI_INT,
147                    comm, &req);
148     MPI_Wait(&req, MPI_STATUS_IGNORE);
149
150     MPI_Ialltoallw(sbuf, scounts, sdispls, types, rbuf, rcounts, rdispls, types, comm, &req);
151     MPI_Wait(&req, MPI_STATUS_IGNORE);
152
153     MPI_Ialltoallw(MPI_IN_PLACE, NULL, NULL, NULL, rbuf, rcounts, rdispls, types, comm, &req);
154     MPI_Wait(&req, MPI_STATUS_IGNORE);
155
156     MPI_Ireduce(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, 0, comm, &req);
157     MPI_Wait(&req, MPI_STATUS_IGNORE);
158
159     if (0 == rank)
160         MPI_Ireduce(MPI_IN_PLACE, rbuf, NUM_INTS, MPI_INT, MPI_SUM, 0, comm, &req);
161     else
162         MPI_Ireduce(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, 0, comm, &req);
163     MPI_Wait(&req, MPI_STATUS_IGNORE);
164
165     MPI_Iallreduce(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
166     MPI_Wait(&req, MPI_STATUS_IGNORE);
167
168     MPI_Iallreduce(MPI_IN_PLACE, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
169     MPI_Wait(&req, MPI_STATUS_IGNORE);
170
171 /*    MPI_Ireduce_scatter(sbuf, rbuf, rcounts, MPI_INT, MPI_SUM, comm, &req);*/
172 /*    MPI_Wait(&req, MPI_STATUS_IGNORE);*/
173
174 /*    MPI_Ireduce_scatter(MPI_IN_PLACE, rbuf, rcounts, MPI_INT, MPI_SUM, comm, &req);*/
175 /*    MPI_Wait(&req, MPI_STATUS_IGNORE);*/
176
177 /*    MPI_Ireduce_scatter_block(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);*/
178 /*    MPI_Wait(&req, MPI_STATUS_IGNORE);*/
179
180 /*    MPI_Ireduce_scatter_block(MPI_IN_PLACE, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);*/
181 /*    MPI_Wait(&req, MPI_STATUS_IGNORE);*/
182
183 /*    MPI_Iscan(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);*/
184 /*    MPI_Wait(&req, MPI_STATUS_IGNORE);*/
185
186 /*    MPI_Iscan(MPI_IN_PLACE, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);*/
187 /*    MPI_Wait(&req, MPI_STATUS_IGNORE);*/
188
189 /*    MPI_Iexscan(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);*/
190 /*    MPI_Wait(&req, MPI_STATUS_IGNORE);*/
191
192 /*    MPI_Iexscan(MPI_IN_PLACE, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);*/
193 /*    MPI_Wait(&req, MPI_STATUS_IGNORE);*/
194
195     if (sbuf)
196         free(sbuf);
197     if (rbuf)
198         free(rbuf);
199     if (scounts)
200         free(scounts);
201     if (rcounts)
202         free(rcounts);
203     if (sdispls)
204         free(sdispls);
205     if (rdispls)
206         free(rdispls);
207     if (types)
208         free(types);
209
210     if (rank == 0) {
211         if (errs)
212             fprintf(stderr, "Found %d errors\n", errs);
213         else
214             printf(" No errors\n");
215     }
216     MPI_Finalize();
217     return 0;
218 }