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.
13 static char MTEST_Descrip[] = "Test of various send cancel calls";
16 int main(int argc, char *argv[])
23 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 */
31 MTest_Init(&argc, &argv);
32 xbt_log_control_set("smpi_kernel.thr:critical");
34 comm = MPI_COMM_WORLD;
35 MPI_Comm_rank(comm, &rank);
36 MPI_Comm_size(comm, &size);
40 MTestPrintfMsg(1, "Starting scancel test\n");
41 for (cs = 0; cs < 4; cs++) {
44 buf = (char *) malloc(n);
46 fprintf(stderr, "Unable to allocate %d bytes\n", n);
47 MPI_Abort(MPI_COMM_WORLD, 1);
49 MTestPrintfMsg(1, "(%d) About to create isend and cancel\n", cs);
50 MPI_Isend(buf, n, MPI_CHAR, dest, cs + n + 1, comm, &req);
52 MPI_Wait(&req, &status);
53 MTestPrintfMsg(1, "Completed wait on isend\n");
54 MPI_Test_cancelled(&status, &flag);
57 printf("Failed to cancel an Isend request\n");
63 /* Send the size, zero for successfully cancelled */
64 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
65 /* Send the tag so the message can be received */
67 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
70 else if (rank == dest) {
73 MPI_Recv(&nn, 1, MPI_INT, 0, 123, comm, &status);
74 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
76 /* If the message was not cancelled, receive it here */
77 btemp = (char *) malloc(nn);
79 fprintf(stderr, "Unable to allocate %d bytes\n", nn);
80 MPI_Abort(MPI_COMM_WORLD, 1);
82 MPI_Recv(btemp, nn, MPI_CHAR, 0, tag, comm, &status);
93 buf = (char *) malloc(n);
95 fprintf(stderr, "Unable to allocate %d bytes\n", n);
96 MPI_Abort(MPI_COMM_WORLD, 1);
98 bsendbufsize = n + MPI_BSEND_OVERHEAD;
99 bsendbuf = (char *) malloc(bsendbufsize);
101 fprintf(stderr, "Unable to allocate %d bytes for bsend\n", n);
102 MPI_Abort(MPI_COMM_WORLD, 1);
104 MPI_Buffer_attach(bsendbuf, bsendbufsize);
105 MTestPrintfMsg(1, "About to create and cancel ibsend\n");
106 MPI_Ibsend(buf, n, MPI_CHAR, dest, cs + n + 2, comm, &req);
108 MPI_Wait(&req, &status);
109 MPI_Test_cancelled(&status, &flag);
112 printf("Failed to cancel an Ibsend request\n");
118 /* Send the size, zero for successfully cancelled */
119 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
120 /* Send the tag so the message can be received */
122 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
124 MPI_Buffer_detach(&bf, &bs);
127 else if (rank == dest) {
130 MPI_Recv(&nn, 1, MPI_INT, 0, 123, comm, &status);
131 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
133 /* If the message was not cancelled, receive it here */
134 btemp = (char *) malloc(nn);
136 fprintf(stderr, "Unable to allocate %d bytes\n", nn);
137 MPI_Abort(MPI_COMM_WORLD, 1);
139 MPI_Recv(btemp, nn, MPI_CHAR, 0, tag, comm, &status);
145 /* Because this test is erroneous, we do not perform it unless
146 * TEST_IRSEND is defined. */
148 /* We avoid ready send to self because an implementation
149 * is free to detect the error in delivering a message to
150 * itself without a pending receive; we could also check
151 * for an error return from the MPI_Irsend */
152 if (rank == 0 && dest != rank) {
154 buf = (char *) malloc(n);
156 fprintf(stderr, "Unable to allocate %d bytes\n", n);
157 MPI_Abort(MPI_COMM_WORLD, 1);
159 MTestPrintfMsg(1, "About to create and cancel irsend\n");
160 MPI_Irsend(buf, n, MPI_CHAR, dest, cs + n + 3, comm, &req);
162 MPI_Wait(&req, &status);
163 MPI_Test_cancelled(&status, &flag);
164 /* This can be pretty ugly. The standard is clear (Section 3.8)
165 * that either a sent message is received or the
166 * sent message is successfully cancelled. Since this message
167 * can never be received, the cancel must complete
170 * However, since there is no matching receive, this
171 * program is erroneous. In this case, we can't really
172 * flag this as an error */
173 if (!flag && veryPicky) {
175 printf("Failed to cancel an Irsend request\n");
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 MTestPrintfMsg(1, "About to create and cancel issend\n");
215 MPI_Issend(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 an Issend request\n");
227 /* Send the size, zero for successfully cancelled */
228 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
229 /* Send the tag so the message can be received */
231 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
234 else if (rank == dest) {
237 MPI_Recv(&nn, 1, MPI_INT, 0, 123, comm, &status);
238 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
240 /* If the message was not cancelled, receive it here */
241 btemp = (char *) malloc(nn);
243 fprintf(stderr, "Unable to allocate %d bytes\n", nn);
244 MPI_Abort(MPI_COMM_WORLD, 1);
246 MPI_Recv(btemp, nn, MPI_CHAR, 0, tag, comm, &status);
253 MTest_Finalize(errs);