Logo AND Algorithmique Numérique Distribuée

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