1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2010 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
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
16 /* USE_STRICT_MPI may be defined in mpitestconf.h */
17 #include "mpitestconf.h"
19 #if !defined(USE_STRICT_MPI) && defined(MPICH)
20 #define TEST_NBC_ROUTINES 1
25 #define my_assert(cond_) \
28 fprintf(stderr, "assertion (%s) failed, aborting\n", #cond_); \
29 MPI_Abort(MPI_COMM_WORLD, 1); \
34 int main(int argc, char **argv)
45 #if defined(TEST_NBC_ROUTINES)
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
54 MPI_Init(&argc, &argv);
56 comm = MPI_COMM_WORLD;
58 MPI_Comm_size(comm, &size);
59 MPI_Comm_rank(comm, &rank);
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));
66 rbuf = malloc(NUM_INTS*size*sizeof(int));
68 scounts = malloc(size*sizeof(int));
70 rcounts = malloc(size*sizeof(int));
72 sdispls = malloc(size*sizeof(int));
74 rdispls = malloc(size*sizeof(int));
76 types = malloc(size*sizeof(int));
79 for (i = 0; i < size; ++i) {
84 scounts[i] = NUM_INTS;
85 rcounts[i] = NUM_INTS;
86 sdispls[i] = i * NUM_INTS;
87 rdispls[i] = i * NUM_INTS;
91 MPI_Ibarrier(comm, &req);
92 MPI_Wait(&req, MPI_STATUS_IGNORE);
94 MPI_Ibcast(sbuf, NUM_INTS, MPI_INT, 0, comm, &req);
95 MPI_Wait(&req, MPI_STATUS_IGNORE);
97 MPI_Igather(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
98 MPI_Wait(&req, MPI_STATUS_IGNORE);
100 MPI_Igatherv(sbuf, NUM_INTS, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, 0, comm, &req);
101 MPI_Wait(&req, MPI_STATUS_IGNORE);
103 MPI_Iscatter(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
104 MPI_Wait(&req, MPI_STATUS_IGNORE);
106 MPI_Iscatterv(sbuf, scounts, sdispls, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
107 MPI_Wait(&req, MPI_STATUS_IGNORE);
109 MPI_Iallgather(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, comm, &req);
110 MPI_Wait(&req, MPI_STATUS_IGNORE);
112 MPI_Iallgatherv(sbuf, NUM_INTS, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, comm, &req);
113 MPI_Wait(&req, MPI_STATUS_IGNORE);
115 MPI_Ialltoall(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, comm, &req);
116 MPI_Wait(&req, MPI_STATUS_IGNORE);
118 MPI_Ialltoallv(sbuf, scounts, sdispls, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, comm, &req);
119 MPI_Wait(&req, MPI_STATUS_IGNORE);
121 MPI_Ialltoallw(sbuf, scounts, sdispls, types, rbuf, rcounts, rdispls, types, comm, &req);
122 MPI_Wait(&req, MPI_STATUS_IGNORE);
124 MPI_Ireduce(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, 0, comm, &req);
125 MPI_Wait(&req, MPI_STATUS_IGNORE);
127 MPI_Iallreduce(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
128 MPI_Wait(&req, MPI_STATUS_IGNORE);
130 MPI_Ireduce_scatter(sbuf, rbuf, rcounts, MPI_INT, MPI_SUM, comm, &req);
131 MPI_Wait(&req, MPI_STATUS_IGNORE);
133 MPI_Ireduce_scatter_block(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
134 MPI_Wait(&req, MPI_STATUS_IGNORE);
136 MPI_Iscan(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
137 MPI_Wait(&req, MPI_STATUS_IGNORE);
139 MPI_Iexscan(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
140 MPI_Wait(&req, MPI_STATUS_IGNORE);
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);
153 fprintf(stderr, "Found %d errors\n", errs);
155 printf(" No errors\n");