Logo AND Algorithmique Numérique Distribuée

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