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 };
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);
39 MTestPrintfMsg(1, "Starting scancel test\n");
40 for (cs = 0; cs < 4; cs++) {
43 buf = (char *) malloc(n);
45 fprintf(stderr, "Unable to allocate %d bytes\n", n);
46 MPI_Abort(MPI_COMM_WORLD, 1);
48 MTestPrintfMsg(1, "(%d) About to create isend and cancel\n", cs);
49 MPI_Isend(buf, n, MPI_CHAR, dest, cs + n + 1, comm, &req);
51 MPI_Wait(&req, &status);
52 MTestPrintfMsg(1, "Completed wait on isend\n");
53 MPI_Test_cancelled(&status, &flag);
56 printf("Failed to cancel an Isend request\n");
62 /* Send the size, zero for successfully cancelled */
63 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
64 /* Send the tag so the message can be received */
66 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
69 else if (rank == dest) {
72 MPI_Recv(&nn, 1, MPI_INT, 0, 123, comm, &status);
73 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
75 /* If the message was not cancelled, receive it here */
76 btemp = (char *) malloc(nn);
78 fprintf(stderr, "Unable to allocate %d bytes\n", nn);
79 MPI_Abort(MPI_COMM_WORLD, 1);
81 MPI_Recv(btemp, nn, MPI_CHAR, 0, tag, comm, &status);
92 buf = (char *) malloc(n);
94 fprintf(stderr, "Unable to allocate %d bytes\n", n);
95 MPI_Abort(MPI_COMM_WORLD, 1);
97 bsendbufsize = n + MPI_BSEND_OVERHEAD;
98 bsendbuf = (char *) malloc(bsendbufsize);
100 fprintf(stderr, "Unable to allocate %d bytes for bsend\n", n);
101 MPI_Abort(MPI_COMM_WORLD, 1);
103 MPI_Buffer_attach(bsendbuf, bsendbufsize);
104 MTestPrintfMsg(1, "About to create and cancel ibsend\n");
105 MPI_Ibsend(buf, n, MPI_CHAR, dest, cs + n + 2, comm, &req);
107 MPI_Wait(&req, &status);
108 MPI_Test_cancelled(&status, &flag);
111 printf("Failed to cancel an Ibsend request\n");
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 MTestPrintfMsg(1, "About to create and cancel irsend\n");
159 MPI_Irsend(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 an Irsend request\n");
180 /* Send the size, zero for successfully cancelled */
181 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
182 /* Send the tag so the message can be received */
184 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
187 else if (rank == dest) {
190 MPI_Recv(&n, 1, MPI_INT, 0, 123, comm, &status);
191 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
193 /* If the message was not cancelled, receive it here */
194 btemp = (char *) malloc(n);
196 fprintf(stderr, "Unable to allocate %d bytes\n", n);
197 MPI_Abort(MPI_COMM_WORLD, 1);
199 MPI_Recv(btemp, n, MPI_CHAR, 0, tag, comm, &status);
208 buf = (char *) malloc(n);
210 fprintf(stderr, "Unable to allocate %d bytes\n", n);
211 MPI_Abort(MPI_COMM_WORLD, 1);
213 MTestPrintfMsg(1, "About to create and cancel issend\n");
214 MPI_Issend(buf, n, MPI_CHAR, dest, cs + n + 4, comm, &req);
216 MPI_Wait(&req, &status);
217 MPI_Test_cancelled(&status, &flag);
220 printf("Failed to cancel an Issend request\n");
226 /* Send the size, zero for successfully cancelled */
227 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
228 /* Send the tag so the message can be received */
230 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
233 else if (rank == dest) {
236 MPI_Recv(&nn, 1, MPI_INT, 0, 123, comm, &status);
237 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
239 /* If the message was not cancelled, receive it here */
240 btemp = (char *) malloc(nn);
242 fprintf(stderr, "Unable to allocate %d bytes\n", nn);
243 MPI_Abort(MPI_COMM_WORLD, 1);
245 MPI_Recv(btemp, nn, MPI_CHAR, 0, tag, comm, &status);
252 MTest_Finalize(errs);