1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2012 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
13 #if !defined(USE_STRICT_MPI) && defined(MPICH)
14 #define TEST_NEIGHB_COLL 1
17 /* assert-like macro that bumps the err count and emits a message */
23 fprintf(stderr, "check failed: (%s), line %d\n", #x_, __LINE__); \
28 int main(int argc, char *argv[])
32 int periods[1] = { 0 };
33 MPI_Comm cart, dgraph, graph;
35 MPI_Init(&argc, &argv);
36 MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
37 MPI_Comm_size(MPI_COMM_WORLD, &wsize);
39 #if defined(TEST_NEIGHB_COLL)
40 /* a basic test for the 10 (5 patterns x {blocking,nonblocking}) MPI-3
41 * neighborhood collective routines */
43 /* (wrap)--> 0 <--> 1 <--> ... <--> p-1 <--(wrap) */
44 MPI_Cart_create(MPI_COMM_WORLD, 1, &wsize, periods, /*reorder= */ 0, &cart);
48 int sendbuf[1] = { wrank };
49 int recvbuf[2] = { 0xdeadbeef, 0xdeadbeef };
51 /* should see one send to each neighbor (rank-1 and rank+1) and one receive
53 MPI_Neighbor_allgather(sendbuf, 1, MPI_INT, recvbuf, 1, MPI_INT, cart);
56 check(recvbuf[0] == 0xdeadbeef);
58 check(recvbuf[0] == wrank - 1);
60 if (wrank == wsize - 1)
61 check(recvbuf[1] == 0xdeadbeef);
63 check(recvbuf[1] == wrank + 1);
68 int sendbuf[1] = { wrank };
69 int recvbuf[2] = { 0xdeadbeef, 0xdeadbeef };
70 int recvcounts[2] = { 1, 1 };
71 int displs[2] = { 1, 0 };
73 /* should see one send to each neighbor (rank-1 and rank+1) and one receive
74 * each from same, but put them in opposite slots in the buffer */
75 MPI_Neighbor_allgatherv(sendbuf, 1, MPI_INT, recvbuf, recvcounts, displs, MPI_INT, cart);
78 check(recvbuf[1] == 0xdeadbeef);
80 check(recvbuf[1] == wrank - 1);
82 if (wrank == wsize - 1)
83 check(recvbuf[0] == 0xdeadbeef);
85 check(recvbuf[0] == wrank + 1);
90 int sendbuf[2] = { -(wrank + 1), wrank + 1 };
91 int recvbuf[2] = { 0xdeadbeef, 0xdeadbeef };
93 /* should see one send to each neighbor (rank-1 and rank+1) and one
94 * receive each from same */
95 MPI_Neighbor_alltoall(sendbuf, 1, MPI_INT, recvbuf, 1, MPI_INT, cart);
98 check(recvbuf[0] == 0xdeadbeef);
100 check(recvbuf[0] == wrank);
102 if (wrank == wsize - 1)
103 check(recvbuf[1] == 0xdeadbeef);
105 check(recvbuf[1] == -(wrank + 2));
110 int sendbuf[2] = { -(wrank + 1), wrank + 1 };
111 int recvbuf[2] = { 0xdeadbeef, 0xdeadbeef };
112 int sendcounts[2] = { 1, 1 };
113 int recvcounts[2] = { 1, 1 };
114 int sdispls[2] = { 0, 1 };
115 int rdispls[2] = { 1, 0 };
117 /* should see one send to each neighbor (rank-1 and rank+1) and one receive
118 * each from same, but put them in opposite slots in the buffer */
119 MPI_Neighbor_alltoallv(sendbuf, sendcounts, sdispls, MPI_INT,
120 recvbuf, recvcounts, rdispls, MPI_INT, cart);
123 check(recvbuf[1] == 0xdeadbeef);
125 check(recvbuf[1] == wrank);
127 if (wrank == wsize - 1)
128 check(recvbuf[0] == 0xdeadbeef);
130 check(recvbuf[0] == -(wrank + 2));
135 int sendbuf[2] = { -(wrank + 1), wrank + 1 };
136 int recvbuf[2] = { 0xdeadbeef, 0xdeadbeef };
137 int sendcounts[2] = { 1, 1 };
138 int recvcounts[2] = { 1, 1 };
139 MPI_Aint sdispls[2] = { 0, sizeof(int) };
140 MPI_Aint rdispls[2] = { sizeof(int), 0 };
141 MPI_Datatype sendtypes[2] = { MPI_INT, MPI_INT };
142 MPI_Datatype recvtypes[2] = { MPI_INT, MPI_INT };
144 /* should see one send to each neighbor (rank-1 and rank+1) and one receive
145 * each from same, but put them in opposite slots in the buffer */
146 MPI_Neighbor_alltoallw(sendbuf, sendcounts, sdispls, sendtypes,
147 recvbuf, recvcounts, rdispls, recvtypes, cart);
150 check(recvbuf[1] == 0xdeadbeef);
152 check(recvbuf[1] == wrank);
154 if (wrank == wsize - 1)
155 check(recvbuf[0] == 0xdeadbeef);
157 check(recvbuf[0] == -(wrank + 2));
161 MPI_Comm_free(&cart);
162 #endif /* defined(TEST_NEIGHB_COLL) */
164 MPI_Reduce((wrank == 0 ? MPI_IN_PLACE : &errs), &errs, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
167 printf("found %d errors\n", errs);
170 printf(" No errors\n");