Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[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             exit(1);                                                      \
24         }                                                                 \
25     } while (0)
26
27 int main(int argc, char **argv)
28 {
29     int errs = 0;
30     int i;
31     int rank, size;
32     int *sbuf = NULL;
33     int *rbuf = NULL;
34     int *scounts = NULL;
35     int *rcounts = NULL;
36     int *sdispls = NULL;
37     int *rdispls = NULL;
38     int *types = NULL;
39     MPI_Comm comm;
40     MPI_Request req;
41
42     /* intentionally not using MTest_Init/MTest_Finalize in order to make it
43      * easy to take this test and use it as an NBC sanity test outside of the
44      * MPICH test suite */
45     MPI_Init(&argc, &argv);
46
47     comm = MPI_COMM_WORLD;
48
49     MPI_Comm_size(comm, &size);
50     MPI_Comm_rank(comm, &rank);
51
52     /* enough space for every process to contribute at least NUM_INTS ints to any
53      * collective operation */
54     sbuf = malloc(NUM_INTS*size*sizeof(int));
55     my_assert(sbuf);
56     rbuf = malloc(NUM_INTS*size*sizeof(int));
57     my_assert(rbuf);
58     scounts = malloc(size*sizeof(int));
59     my_assert(scounts);
60     rcounts = malloc(size*sizeof(int));
61     my_assert(rcounts);
62     sdispls = malloc(size*sizeof(int));
63     my_assert(sdispls);
64     rdispls = malloc(size*sizeof(int));
65     my_assert(rdispls);
66     types = malloc(size*sizeof(int));
67     my_assert(types);
68
69     for (i = 0; i < size; ++i) {
70         sbuf[2*i]   = i;
71         sbuf[2*i+1] = i;
72         rbuf[2*i]   = i;
73         rbuf[2*i+1] = i;
74         scounts[i]  = NUM_INTS;
75         rcounts[i]  = NUM_INTS;
76         sdispls[i]  = i * NUM_INTS;
77         rdispls[i]  = i * NUM_INTS;
78         types[i]    = MPI_INT;
79     }
80
81     MPI_Ibarrier(comm, &req);
82     MPI_Wait(&req, MPI_STATUS_IGNORE);
83
84     MPI_Ibcast(sbuf, NUM_INTS, MPI_INT, 0, comm, &req);
85     MPI_Wait(&req, MPI_STATUS_IGNORE);
86
87     MPI_Igather(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
88     MPI_Wait(&req, MPI_STATUS_IGNORE);
89
90     MPI_Igatherv(sbuf, NUM_INTS, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, 0, comm, &req);
91     MPI_Wait(&req, MPI_STATUS_IGNORE);
92
93     MPI_Iscatter(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
94     MPI_Wait(&req, MPI_STATUS_IGNORE);
95
96     MPI_Iscatterv(sbuf, scounts, sdispls, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
97     MPI_Wait(&req, MPI_STATUS_IGNORE);
98
99     MPI_Iallgather(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, comm, &req);
100     MPI_Wait(&req, MPI_STATUS_IGNORE);
101
102     MPI_Iallgatherv(sbuf, NUM_INTS, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, comm, &req);
103     MPI_Wait(&req, MPI_STATUS_IGNORE);
104
105     MPI_Ialltoall(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, comm, &req);
106     MPI_Wait(&req, MPI_STATUS_IGNORE);
107
108     MPI_Ialltoallv(sbuf, scounts, sdispls, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, comm, &req);
109     MPI_Wait(&req, MPI_STATUS_IGNORE);
110
111     MPI_Ialltoallw(sbuf, scounts, sdispls, types, rbuf, rcounts, rdispls, types, comm, &req);
112     MPI_Wait(&req, MPI_STATUS_IGNORE);
113
114     MPI_Ireduce(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, 0, comm, &req);
115     MPI_Wait(&req, MPI_STATUS_IGNORE);
116
117     MPI_Iallreduce(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
118     MPI_Wait(&req, MPI_STATUS_IGNORE);
119
120     MPI_Ireduce_scatter(sbuf, rbuf, rcounts, MPI_INT, MPI_SUM, comm, &req);
121     MPI_Wait(&req, MPI_STATUS_IGNORE);
122
123     MPI_Ireduce_scatter_block(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
124     MPI_Wait(&req, MPI_STATUS_IGNORE);
125
126     MPI_Iscan(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
127     MPI_Wait(&req, MPI_STATUS_IGNORE);
128
129     MPI_Iexscan(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
130     MPI_Wait(&req, MPI_STATUS_IGNORE);
131
132     if (sbuf) free(sbuf);
133     if (rbuf) free(rbuf);
134     if (scounts) free(scounts);
135     if (rcounts) free(rcounts);
136     if (sdispls) free(sdispls);
137     if (rdispls) free(rdispls);
138
139     if (rank == 0) {
140         if (errs)
141             fprintf(stderr, "Found %d errors\n", errs);
142         else
143             printf(" No errors\n");
144     }
145     MPI_Finalize();
146     return 0;
147 }
148