1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2003 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
12 static char MTEST_Descrip[] = "Test of various send cancel calls";
15 int main(int argc, char *argv[])
18 int rank, size, source, dest;
22 static int bufsizes[4] = { 1, 100, 10000, 1000000 };
26 int veryPicky = 0; /* Set to 1 to test "quality of implementation" in
27 * a tricky part of cancel */
30 MTest_Init(&argc, &argv);
32 comm = MPI_COMM_WORLD;
33 MPI_Comm_rank(comm, &rank);
34 MPI_Comm_size(comm, &size);
39 for (cs = 0; cs < 4; cs++) {
42 buf = (char *) malloc(n);
44 fprintf(stderr, "Unable to allocate %d bytes\n", n);
45 MPI_Abort(MPI_COMM_WORLD, 1);
47 MPI_Send_init(buf, n, MPI_CHAR, dest, cs + n + 1, comm, &req);
50 MPI_Wait(&req, &status);
51 MPI_Test_cancelled(&status, &flag);
54 printf("Failed to cancel a persistent send request\n");
60 MPI_Request_free(&req);
61 /* Send the size, zero for successfully cancelled */
62 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
63 /* Send the tag so the message can be received */
65 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
68 else if (rank == dest) {
71 MPI_Recv(&nn, 1, MPI_INT, 0, 123, comm, &status);
72 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
74 /* If the message was not cancelled, receive it here */
75 btemp = (char *) malloc(nn);
77 fprintf(stderr, "Unable to allocate %d bytes\n", nn);
78 MPI_Abort(MPI_COMM_WORLD, 1);
80 MPI_Recv(btemp, nn, MPI_CHAR, 0, tag, comm, &status);
91 buf = (char *) malloc(n);
93 fprintf(stderr, "Unable to allocate %d bytes\n", n);
94 MPI_Abort(MPI_COMM_WORLD, 1);
96 bsendbufsize = n + MPI_BSEND_OVERHEAD;
97 bsendbuf = (char *) malloc(bsendbufsize);
99 fprintf(stderr, "Unable to allocate %d bytes for bsend\n", n);
100 MPI_Abort(MPI_COMM_WORLD, 1);
102 MPI_Buffer_attach(bsendbuf, bsendbufsize);
103 MPI_Bsend_init(buf, n, MPI_CHAR, dest, cs + n + 2, comm, &req);
106 MPI_Wait(&req, &status);
107 MPI_Test_cancelled(&status, &flag);
110 printf("Failed to cancel a persistent bsend request\n");
116 MPI_Request_free(&req);
117 /* Send the size, zero for successfully cancelled */
118 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
119 /* Send the tag so the message can be received */
121 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
123 MPI_Buffer_detach(&bf, &bs);
126 else if (rank == dest) {
129 MPI_Recv(&nn, 1, MPI_INT, 0, 123, comm, &status);
130 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
132 /* If the message was not cancelled, receive it here */
133 btemp = (char *) malloc(nn);
135 fprintf(stderr, "Unable to allocate %d bytes\n", nn);
136 MPI_Abort(MPI_COMM_WORLD, 1);
138 MPI_Recv(btemp, nn, MPI_CHAR, 0, tag, comm, &status);
144 /* Because this test is erroneous, we do not perform it unless
145 * TEST_IRSEND is defined. */
147 /* We avoid ready send to self because an implementation
148 * is free to detect the error in delivering a message to
149 * itself without a pending receive; we could also check
150 * for an error return from the MPI_Irsend */
151 if (rank == 0 && dest != rank) {
153 buf = (char *) malloc(n);
155 fprintf(stderr, "Unable to allocate %d bytes\n", n);
156 MPI_Abort(MPI_COMM_WORLD, 1);
158 MPI_Rsend_init(buf, n, MPI_CHAR, dest, cs + n + 3, comm, &req);
161 MPI_Wait(&req, &status);
162 MPI_Test_cancelled(&status, &flag);
163 /* This can be pretty ugly. The standard is clear (Section 3.8)
164 * that either a sent message is received or the
165 * sent message is successfully cancelled. Since this message
166 * can never be received, the cancel must complete
169 * However, since there is no matching receive, this
170 * program is erroneous. In this case, we can't really
171 * flag this as an error */
172 if (!flag && veryPicky) {
174 printf("Failed to cancel a persistent rsend request\n");
180 MPI_Request_free(&req);
181 /* Send the size, zero for successfully cancelled */
182 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
183 /* Send the tag so the message can be received */
185 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
188 else if (rank == dest) {
191 MPI_Recv(&n, 1, MPI_INT, 0, 123, comm, &status);
192 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
194 /* If the message was not cancelled, receive it here */
195 btemp = (char *) malloc(n);
197 fprintf(stderr, "Unable to allocate %d bytes\n", n);
198 MPI_Abort(MPI_COMM_WORLD, 1);
200 MPI_Recv(btemp, n, MPI_CHAR, 0, tag, comm, &status);
209 buf = (char *) malloc(n);
211 fprintf(stderr, "Unable to allocate %d bytes\n", n);
212 MPI_Abort(MPI_COMM_WORLD, 1);
214 MPI_Ssend_init(buf, n, MPI_CHAR, dest, cs + n + 4, comm, &req);
217 MPI_Wait(&req, &status);
218 MPI_Test_cancelled(&status, &flag);
221 printf("Failed to cancel a persistent ssend request\n");
227 MPI_Request_free(&req);
228 /* Send the size, zero for successfully cancelled */
229 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
230 /* Send the tag so the message can be received */
232 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
235 else if (rank == dest) {
238 MPI_Recv(&nn, 1, MPI_INT, 0, 123, comm, &status);
239 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
241 /* If the message was not cancelled, receive it here */
242 btemp = (char *) malloc(nn);
244 fprintf(stderr, "Unable to allocate %d bytes\n", nn);
245 MPI_Abort(MPI_COMM_WORLD, 1);
247 MPI_Recv(btemp, nn, MPI_CHAR, 0, tag, comm, &status);
254 MTest_Finalize(errs);