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 };
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 );
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 );
48 MPI_Send_init( buf, n, MPI_CHAR, dest, cs+n+1, comm, &req );
51 MPI_Wait( &req, &status );
52 MPI_Test_cancelled( &status, &flag );
55 printf( "Failed to cancel a persistent send request\n" );
62 MPI_Request_free( &req );
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)
74 MPI_Recv( &nn, 1, MPI_INT, 0, 123, comm, &status );
75 MPI_Recv( &tag, 1, MPI_INT, 0, 123, comm, &status );
78 /* If the message was not cancelled, receive it here */
79 btemp = (char*)malloc( nn );
82 fprintf( stderr, "Unable to allocate %d bytes\n", nn);
83 MPI_Abort( MPI_COMM_WORLD, 1 );
86 MPI_Recv( btemp, nn, MPI_CHAR, 0, tag, comm, &status );
97 buf = (char *)malloc( n );
99 fprintf( stderr, "Unable to allocate %d bytes\n", n );
100 MPI_Abort( MPI_COMM_WORLD, 1 );
103 bsendbufsize = n + MPI_BSEND_OVERHEAD;
104 bsendbuf = (char *)malloc( bsendbufsize );
106 fprintf( stderr, "Unable to allocate %d bytes for bsend\n", n );
107 MPI_Abort( MPI_COMM_WORLD, 1 );
110 MPI_Buffer_attach( bsendbuf, bsendbufsize );
111 MPI_Bsend_init( buf, n, MPI_CHAR, dest, cs+n+2, comm, &req );
114 MPI_Wait( &req, &status );
115 MPI_Test_cancelled( &status, &flag );
118 printf( "Failed to cancel a persistent bsend request\n" );
125 MPI_Request_free( &req );
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 MPI_Rsend_init( 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 a persistent rsend request\n" );
195 MPI_Request_free( &req );
196 /* Send the size, zero for successfully cancelled */
197 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
198 /* Send the tag so the message can be received */
200 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
203 else if (rank == dest)
207 MPI_Recv( &n, 1, MPI_INT, 0, 123, comm, &status );
208 MPI_Recv( &tag, 1, MPI_INT, 0, 123, comm, &status );
211 /* If the message was not cancelled, receive it here */
212 btemp = (char*)malloc( n );
215 fprintf( stderr, "Unable to allocate %d bytes\n", n);
216 MPI_Abort( MPI_COMM_WORLD, 1 );
219 MPI_Recv( btemp, n, MPI_CHAR, 0, tag, comm, &status );
228 buf = (char *)malloc( n );
230 fprintf( stderr, "Unable to allocate %d bytes\n", n );
231 MPI_Abort( MPI_COMM_WORLD, 1 );
234 MPI_Ssend_init( buf, n, MPI_CHAR, dest, cs+n+4, comm, &req );
237 MPI_Wait( &req, &status );
238 MPI_Test_cancelled( &status, &flag );
241 printf( "Failed to cancel a persistent ssend request\n" );
248 MPI_Request_free( &req );
249 /* Send the size, zero for successfully cancelled */
250 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
251 /* Send the tag so the message can be received */
253 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
256 else if (rank == dest)
260 MPI_Recv( &nn, 1, MPI_INT, 0, 123, comm, &status );
261 MPI_Recv( &tag, 1, MPI_INT, 0, 123, comm, &status );
264 /* If the message was not cancelled, receive it here */
265 btemp = (char*)malloc( nn );
268 fprintf( stderr, "Unable to allocate %d bytes\n", nn);
269 MPI_Abort( MPI_COMM_WORLD, 1 );
272 MPI_Recv( btemp, nn, MPI_CHAR, 0, tag, comm, &status );
279 MTest_Finalize( errs );