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 );
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" );
64 /* Send the size, zero for successfully cancelled */
65 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
66 /* Send the tag so the message can be received */
68 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
71 else if (rank == dest)
75 MPI_Recv( &nn, 1, MPI_INT, 0, 123, comm, &status );
76 MPI_Recv( &tag, 1, MPI_INT, 0, 123, comm, &status );
79 /* If the message was not cancelled, receive it here */
80 btemp = (char*)malloc( nn );
83 fprintf( stderr, "Unable to allocate %d bytes\n", nn );
84 MPI_Abort( MPI_COMM_WORLD, 1 );
87 MPI_Recv( btemp, nn, MPI_CHAR, 0, tag, comm, &status );
98 buf = (char *)malloc( n );
100 fprintf( stderr, "Unable to allocate %d bytes\n", n );
101 MPI_Abort( MPI_COMM_WORLD, 1 );
104 bsendbufsize = n + MPI_BSEND_OVERHEAD;
105 bsendbuf = (char *)malloc( bsendbufsize );
107 fprintf( stderr, "Unable to allocate %d bytes for bsend\n", n );
108 MPI_Abort( MPI_COMM_WORLD, 1 );
111 MPI_Buffer_attach( bsendbuf, bsendbufsize );
112 MTestPrintfMsg( 1, "About to create and cancel ibsend\n" );
113 MPI_Ibsend( buf, n, MPI_CHAR, dest, cs+n+2, comm, &req );
115 MPI_Wait( &req, &status );
116 MPI_Test_cancelled( &status, &flag );
119 printf( "Failed to cancel an Ibsend request\n" );
126 /* Send the size, zero for successfully cancelled */
127 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
128 /* Send the tag so the message can be received */
130 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
132 MPI_Buffer_detach( &bf, &bs );
135 else if (rank == dest)
139 MPI_Recv( &nn, 1, MPI_INT, 0, 123, comm, &status );
140 MPI_Recv( &tag, 1, MPI_INT, 0, 123, comm, &status );
143 /* If the message was not cancelled, receive it here */
144 btemp = (char*)malloc( nn );
147 fprintf( stderr, "Unable to allocate %d bytes\n", nn);
148 MPI_Abort( MPI_COMM_WORLD, 1 );
151 MPI_Recv( btemp, nn, MPI_CHAR, 0, tag, comm, &status );
157 /* Because this test is erroneous, we do not perform it unless
158 TEST_IRSEND is defined. */
160 /* We avoid ready send to self because an implementation
161 is free to detect the error in delivering a message to
162 itself without a pending receive; we could also check
163 for an error return from the MPI_Irsend */
164 if (rank == 0 && dest != rank) {
166 buf = (char *)malloc( n );
168 fprintf( stderr, "Unable to allocate %d bytes\n", n );
169 MPI_Abort( MPI_COMM_WORLD, 1 );
172 MTestPrintfMsg( 1, "About to create and cancel irsend\n" );
173 MPI_Irsend( buf, n, MPI_CHAR, dest, cs+n+3, comm, &req );
175 MPI_Wait( &req, &status );
176 MPI_Test_cancelled( &status, &flag );
177 /* This can be pretty ugly. The standard is clear (Section 3.8)
178 that either a sent message is received or the
179 sent message is successfully cancelled. Since this message
180 can never be received, the cancel must complete
183 However, since there is no matching receive, this
184 program is erroneous. In this case, we can't really
185 flag this as an error */
186 if (!flag && veryPicky) {
188 printf( "Failed to cancel an Irsend request\n" );
195 /* Send the size, zero for successfully cancelled */
196 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
197 /* Send the tag so the message can be received */
199 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
202 else if (rank == dest)
206 MPI_Recv( &n, 1, MPI_INT, 0, 123, comm, &status );
207 MPI_Recv( &tag, 1, MPI_INT, 0, 123, comm, &status );
210 /* If the message was not cancelled, receive it here */
211 btemp = (char*)malloc( n );
214 fprintf( stderr, "Unable to allocate %d bytes\n", n);
215 MPI_Abort( MPI_COMM_WORLD, 1 );
218 MPI_Recv( btemp, n, MPI_CHAR, 0, tag, comm, &status );
227 buf = (char *)malloc( n );
229 fprintf( stderr, "Unable to allocate %d bytes\n", n );
230 MPI_Abort( MPI_COMM_WORLD, 1 );
233 MTestPrintfMsg( 1, "About to create and cancel issend\n" );
234 MPI_Issend( buf, n, MPI_CHAR, dest, cs+n+4, comm, &req );
236 MPI_Wait( &req, &status );
237 MPI_Test_cancelled( &status, &flag );
240 printf( "Failed to cancel an Issend request\n" );
247 /* Send the size, zero for successfully cancelled */
248 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
249 /* Send the tag so the message can be received */
251 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
254 else if (rank == dest)
258 MPI_Recv( &nn, 1, MPI_INT, 0, 123, comm, &status );
259 MPI_Recv( &tag, 1, MPI_INT, 0, 123, comm, &status );
262 /* If the message was not cancelled, receive it here */
263 btemp = (char*)malloc( nn );
266 fprintf( stderr, "Unable to allocate %d bytes\n", nn);
267 MPI_Abort( MPI_COMM_WORLD, 1 );
270 MPI_Recv( btemp, nn, MPI_CHAR, 0, tag, comm, &status );
277 MTest_Finalize( errs );