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 };
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);
38 for (cs = 0; cs < 4; cs++) {
41 buf = (char *) malloc(n);
43 fprintf(stderr, "Unable to allocate %d bytes\n", n);
44 MPI_Abort(MPI_COMM_WORLD, 1);
46 MPI_Send_init(buf, n, MPI_CHAR, dest, cs + n + 1, comm, &req);
49 MPI_Wait(&req, &status);
50 MPI_Test_cancelled(&status, &flag);
53 printf("Failed to cancel a persistent send request\n");
59 MPI_Request_free(&req);
60 /* Send the size, zero for successfully cancelled */
61 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
62 /* Send the tag so the message can be received */
64 MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
67 else if (rank == dest) {
70 MPI_Recv(&nn, 1, MPI_INT, 0, 123, comm, &status);
71 MPI_Recv(&tag, 1, MPI_INT, 0, 123, comm, &status);
73 /* If the message was not cancelled, receive it here */
74 btemp = (char *) malloc(nn);
76 fprintf(stderr, "Unable to allocate %d bytes\n", nn);
77 MPI_Abort(MPI_COMM_WORLD, 1);
79 MPI_Recv(btemp, nn, MPI_CHAR, 0, tag, comm, &status);
90 buf = (char *) malloc(n);
92 fprintf(stderr, "Unable to allocate %d bytes\n", n);
93 MPI_Abort(MPI_COMM_WORLD, 1);
95 bsendbufsize = n + MPI_BSEND_OVERHEAD;
96 bsendbuf = (char *) malloc(bsendbufsize);
98 fprintf(stderr, "Unable to allocate %d bytes for bsend\n", n);
99 MPI_Abort(MPI_COMM_WORLD, 1);
101 MPI_Buffer_attach(bsendbuf, bsendbufsize);
102 MPI_Bsend_init(buf, n, MPI_CHAR, dest, cs + n + 2, comm, &req);
105 MPI_Wait(&req, &status);
106 MPI_Test_cancelled(&status, &flag);
109 printf("Failed to cancel a persistent bsend request\n");
115 MPI_Request_free(&req);
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 MPI_Rsend_init(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 a persistent rsend request\n");
179 MPI_Request_free(&req);
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 MPI_Ssend_init(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 a persistent ssend request\n");
226 MPI_Request_free(&req);
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);