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[])
22 static int bufsizes[4] = { 1, 100, 10000, 1000000 };
25 int veryPicky = 0; /* Set to 1 to test "quality of implementation" in
26 * 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);
38 MTestPrintfMsg(1, "Starting scancel test\n");
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 MTestPrintfMsg(1, "(%d) About to create isend and cancel\n", cs);
48 MPI_Isend(buf, n, MPI_CHAR, dest, cs + n + 1, comm, &req);
50 MPI_Wait(&req, &status);
51 MTestPrintfMsg(1, "Completed wait on isend\n");
52 MPI_Test_cancelled(&status, &flag);
55 printf("Failed to cancel an Isend request\n");
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 MTestPrintfMsg(1, "About to create and cancel ibsend\n");
104 MPI_Ibsend(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 an Ibsend request\n");
116 /* Send the size, zero for successfully cancelled */
117 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
118 /* Send the tag so the message can be received */
120 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
122 MPI_Buffer_detach(&bf, &bs);
125 else if (rank == dest) {
128 MPI_Recv(&nn, 1, MPI_INT, 0, 123, comm, &status);
129 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
131 /* If the message was not cancelled, receive it here */
132 btemp = (char *) malloc(nn);
134 fprintf(stderr, "Unable to allocate %d bytes\n", nn);
135 MPI_Abort(MPI_COMM_WORLD, 1);
137 MPI_Recv(btemp, nn, MPI_CHAR, 0, tag, comm, &status);
143 /* Because this test is erroneous, we do not perform it unless
144 * TEST_IRSEND is defined. */
146 /* We avoid ready send to self because an implementation
147 * is free to detect the error in delivering a message to
148 * itself without a pending receive; we could also check
149 * for an error return from the MPI_Irsend */
150 if (rank == 0 && dest != rank) {
152 buf = (char *) malloc(n);
154 fprintf(stderr, "Unable to allocate %d bytes\n", n);
155 MPI_Abort(MPI_COMM_WORLD, 1);
157 MTestPrintfMsg(1, "About to create and cancel irsend\n");
158 MPI_Irsend(buf, n, MPI_CHAR, dest, cs + n + 3, comm, &req);
160 MPI_Wait(&req, &status);
161 MPI_Test_cancelled(&status, &flag);
162 /* This can be pretty ugly. The standard is clear (Section 3.8)
163 * that either a sent message is received or the
164 * sent message is successfully cancelled. Since this message
165 * can never be received, the cancel must complete
168 * However, since there is no matching receive, this
169 * program is erroneous. In this case, we can't really
170 * flag this as an error */
171 if (!flag && veryPicky) {
173 printf("Failed to cancel an Irsend request\n");
179 /* Send the size, zero for successfully cancelled */
180 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
181 /* Send the tag so the message can be received */
183 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
186 else if (rank == dest) {
189 MPI_Recv(&n, 1, MPI_INT, 0, 123, comm, &status);
190 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
192 /* If the message was not cancelled, receive it here */
193 btemp = (char *) malloc(n);
195 fprintf(stderr, "Unable to allocate %d bytes\n", n);
196 MPI_Abort(MPI_COMM_WORLD, 1);
198 MPI_Recv(btemp, n, MPI_CHAR, 0, tag, comm, &status);
207 buf = (char *) malloc(n);
209 fprintf(stderr, "Unable to allocate %d bytes\n", n);
210 MPI_Abort(MPI_COMM_WORLD, 1);
212 MTestPrintfMsg(1, "About to create and cancel issend\n");
213 MPI_Issend(buf, n, MPI_CHAR, dest, cs + n + 4, comm, &req);
215 MPI_Wait(&req, &status);
216 MPI_Test_cancelled(&status, &flag);
219 printf("Failed to cancel an Issend request\n");
225 /* Send the size, zero for successfully cancelled */
226 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
227 /* Send the tag so the message can be received */
229 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
232 else if (rank == dest) {
235 MPI_Recv(&nn, 1, MPI_INT, 0, 123, comm, &status);
236 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
238 /* If the message was not cancelled, receive it here */
239 btemp = (char *) malloc(nn);
241 fprintf(stderr, "Unable to allocate %d bytes\n", nn);
242 MPI_Abort(MPI_COMM_WORLD, 1);
244 MPI_Recv(btemp, nn, MPI_CHAR, 0, tag, comm, &status);
251 MTest_Finalize(errs);