Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change include order for smpi tests/examples to avoid conflicts
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / nonblocking4.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
17 #define NUM_INTS (2)
18
19 #define my_assert(cond_)                                                  \
20     do {                                                                  \
21         if (!(cond_)) {                                                   \
22             fprintf(stderr, "assertion (%s) failed, aborting\n", #cond_); \
23             MPI_Abort(MPI_COMM_WORLD, 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     MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
53
54     /* enough space for every process to contribute at least NUM_INTS ints to any
55      * collective operation */
56     sbuf = malloc(NUM_INTS*size*sizeof(int));
57     my_assert(sbuf);
58     rbuf = malloc(NUM_INTS*size*sizeof(int));
59     my_assert(rbuf);
60     scounts = malloc(size*sizeof(int));
61     my_assert(scounts);
62     rcounts = malloc(size*sizeof(int));
63     my_assert(rcounts);
64     sdispls = malloc(size*sizeof(int));
65     my_assert(sdispls);
66     rdispls = malloc(size*sizeof(int));
67     my_assert(rdispls);
68     types = malloc(size*sizeof(int));
69     my_assert(types);
70
71     for (i = 0; i < size; ++i) {
72         sbuf[2*i]   = i;
73         sbuf[2*i+1] = i;
74         rbuf[2*i]   = i;
75         rbuf[2*i+1] = i;
76         scounts[i]  = NUM_INTS;
77         rcounts[i]  = NUM_INTS;
78         sdispls[i]  = i * NUM_INTS;
79         rdispls[i]  = i * NUM_INTS;
80         types[i]    = MPI_INT;
81     }
82
83     if (rank == 0 && MPI_SUCCESS ==
84             MPI_Igather(sbuf, NUM_INTS, MPI_INT, sbuf, NUM_INTS, MPI_INT, 0, comm, &req))
85         errs++;
86
87     if (rank == 0 && MPI_SUCCESS ==
88             MPI_Igatherv(sbuf, NUM_INTS, MPI_INT, sbuf, rcounts, rdispls, MPI_INT, 0, comm, &req))
89         errs++;
90
91     if (rank == 0 && MPI_SUCCESS ==
92             MPI_Iscatter(sbuf, NUM_INTS, MPI_INT, sbuf, NUM_INTS, MPI_INT, 0, comm, &req))
93         errs++;
94
95     if (rank == 0 && MPI_SUCCESS ==
96             MPI_Iscatterv(sbuf, scounts, sdispls, MPI_INT, sbuf, NUM_INTS, MPI_INT, 0, comm, &req))
97         errs++;
98
99     if (MPI_SUCCESS ==
100             MPI_Iallgather(&sbuf[rank], 1, MPI_INT, sbuf, 1, MPI_INT, comm, &req))
101         errs++;
102
103     if (MPI_SUCCESS ==
104             MPI_Iallgatherv(&sbuf[rank * rcounts[rank]], rcounts[rank], MPI_INT, sbuf, rcounts, rdispls, MPI_INT, comm, &req))
105         errs++;
106
107     if (MPI_SUCCESS ==
108             MPI_Ialltoall(sbuf, NUM_INTS, MPI_INT, sbuf, NUM_INTS, MPI_INT, comm, &req))
109         errs++;
110
111     if (MPI_SUCCESS ==
112             MPI_Ialltoallv(sbuf, scounts, sdispls, MPI_INT, sbuf, scounts, sdispls, MPI_INT, comm, &req))
113         errs++;
114
115     if (MPI_SUCCESS ==
116             MPI_Ialltoallw(sbuf, scounts, sdispls, types, sbuf, scounts, sdispls, types, comm, &req))
117         errs++;
118
119     if (rank == 0 && MPI_SUCCESS ==
120             MPI_Ireduce(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, 0, comm, &req))
121         errs++;
122
123     if (MPI_SUCCESS ==
124             MPI_Iallreduce(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req))
125         errs++;
126
127     if (MPI_SUCCESS ==
128             MPI_Ireduce_scatter(sbuf, sbuf, rcounts, MPI_INT, MPI_SUM, comm, &req))
129         errs++;
130
131     if (MPI_SUCCESS ==
132             MPI_Ireduce_scatter_block(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req))
133         errs++;
134
135     if (MPI_SUCCESS ==
136             MPI_Iscan(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req))
137         errs++;
138
139     if (MPI_SUCCESS ==
140             MPI_Iexscan(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req))
141         errs++;
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