Logo AND Algorithmique Numérique Distribuée

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