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" );
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 );
85 MPI_Recv( btemp, nn, MPI_CHAR, 0, tag, comm, &status );
96 buf = (char *)malloc( n );
98 fprintf( stderr, "Unable to allocate %d bytes\n", n );
99 MPI_Abort( MPI_COMM_WORLD, 1 );
101 bsendbufsize = n + MPI_BSEND_OVERHEAD;
102 bsendbuf = (char *)malloc( bsendbufsize );
104 fprintf( stderr, "Unable to allocate %d bytes for bsend\n", n );
105 MPI_Abort( MPI_COMM_WORLD, 1 );
107 MPI_Buffer_attach( bsendbuf, bsendbufsize );
108 MTestPrintfMsg( 1, "About to create and cancel ibsend\n" );
109 MPI_Ibsend( buf, n, MPI_CHAR, dest, cs+n+2, comm, &req );
111 MPI_Wait( &req, &status );
112 MPI_Test_cancelled( &status, &flag );
115 printf( "Failed to cancel an Ibsend request\n" );
122 /* Send the size, zero for successfully cancelled */
123 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
124 /* Send the tag so the message can be received */
126 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
128 MPI_Buffer_detach( &bf, &bs );
131 else if (rank == dest)
135 MPI_Recv( &nn, 1, MPI_INT, 0, 123, comm, &status );
136 MPI_Recv( &tag, 1, MPI_INT, 0, 123, comm, &status );
139 /* If the message was not cancelled, receive it here */
140 btemp = (char*)malloc( nn );
143 fprintf( stderr, "Unable to allocate %d bytes\n", nn);
144 MPI_Abort( MPI_COMM_WORLD, 1 );
146 MPI_Recv( btemp, nn, MPI_CHAR, 0, tag, comm, &status );
152 /* Because this test is erroneous, we do not perform it unless
153 TEST_IRSEND is defined. */
155 /* We avoid ready send to self because an implementation
156 is free to detect the error in delivering a message to
157 itself without a pending receive; we could also check
158 for an error return from the MPI_Irsend */
159 if (rank == 0 && dest != rank) {
161 buf = (char *)malloc( n );
163 fprintf( stderr, "Unable to allocate %d bytes\n", n );
164 MPI_Abort( MPI_COMM_WORLD, 1 );
166 MTestPrintfMsg( 1, "About to create and cancel irsend\n" );
167 MPI_Irsend( buf, n, MPI_CHAR, dest, cs+n+3, comm, &req );
169 MPI_Wait( &req, &status );
170 MPI_Test_cancelled( &status, &flag );
171 /* This can be pretty ugly. The standard is clear (Section 3.8)
172 that either a sent message is received or the
173 sent message is successfully cancelled. Since this message
174 can never be received, the cancel must complete
177 However, since there is no matching receive, this
178 program is erroneous. In this case, we can't really
179 flag this as an error */
180 if (!flag && veryPicky) {
182 printf( "Failed to cancel an Irsend request\n" );
189 /* Send the size, zero for successfully cancelled */
190 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
191 /* Send the tag so the message can be received */
193 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
196 else if (rank == dest)
200 MPI_Recv( &n, 1, MPI_INT, 0, 123, comm, &status );
201 MPI_Recv( &tag, 1, MPI_INT, 0, 123, comm, &status );
204 /* If the message was not cancelled, receive it here */
205 btemp = (char*)malloc( n );
208 fprintf( stderr, "Unable to allocate %d bytes\n", n);
209 MPI_Abort( MPI_COMM_WORLD, 1 );
211 MPI_Recv( btemp, n, MPI_CHAR, 0, tag, comm, &status );
220 buf = (char *)malloc( n );
222 fprintf( stderr, "Unable to allocate %d bytes\n", n );
223 MPI_Abort( MPI_COMM_WORLD, 1 );
225 MTestPrintfMsg( 1, "About to create and cancel issend\n" );
226 MPI_Issend( buf, n, MPI_CHAR, dest, cs+n+4, comm, &req );
228 MPI_Wait( &req, &status );
229 MPI_Test_cancelled( &status, &flag );
232 printf( "Failed to cancel an Issend request\n" );
239 /* Send the size, zero for successfully cancelled */
240 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
241 /* Send the tag so the message can be received */
243 MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
246 else if (rank == dest)
250 MPI_Recv( &nn, 1, MPI_INT, 0, 123, comm, &status );
251 MPI_Recv( &tag, 1, MPI_INT, 0, 123, comm, &status );
254 /* If the message was not cancelled, receive it here */
255 btemp = (char*)malloc( nn );
258 fprintf( stderr, "Unable to allocate %d bytes\n", nn);
259 MPI_Abort( MPI_COMM_WORLD, 1 );
261 MPI_Recv( btemp, nn, MPI_CHAR, 0, tag, comm, &status );
268 MTest_Finalize( errs );