2 * This file shows a typical use of MPI_Cancel to free IRecv's that
3 * are not wanted. We check for both successful and unsuccessful
10 #if defined(NEEDS_STDLIB_PROTOTYPES)
14 int main( int argc, char **argv )
19 int partner, buf[10], flag;
22 MPI_Init( &argc, &argv );
24 MPI_Comm_size( MPI_COMM_WORLD, &size );
25 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
28 printf( "Cancel test requires at least 2 processes\n" );
29 MPI_Abort( MPI_COMM_WORLD, 1 );
33 * Here is the test. First, we ensure an unsatisfied Irecv:
34 * process 0 process size-1
39 * Next, we confirm receipt before canceling
47 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, 1,
48 MPI_BOTTOM, 0, MPI_INT, partner, 1,
49 MPI_COMM_WORLD, &status );
50 MPI_Irecv( buf, 10, MPI_INT, partner, 0, MPI_COMM_WORLD, &r1 );
52 MPI_Wait( &r1, &status );
53 MPI_Test_cancelled( &status, &flag );
54 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, 1,
55 MPI_BOTTOM, 0, MPI_INT, partner, 1,
56 MPI_COMM_WORLD, &status );
59 printf( "Cancel of a receive failed where it should succeed.\n" );
63 MPI_Irecv( buf, 10, MPI_INT, partner, 2, MPI_COMM_WORLD, &r1 );
64 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, 1,
65 MPI_BOTTOM, 0, MPI_INT, partner, 1,
66 MPI_COMM_WORLD, &status );
68 MPI_Test( &r1, &flag, &status );
69 MPI_Test_cancelled( &status, &flag );
70 /* It is technically possible for the cancel to succeed, even though
71 the message was (at least partially) delivered. I'm leaving
72 this test in since most of the MPICH devices provide this
76 printf( "Cancel of a receive succeeded where it shouldn't.\n" );
80 printf( "Test failed with %d errors.\n", err );
83 printf( " No Errors\n" );
86 else if (rank == size - 1) {
89 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, 1,
90 MPI_BOTTOM, 0, MPI_INT, partner, 1,
91 MPI_COMM_WORLD, &status );
92 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, 1,
93 MPI_BOTTOM, 0, MPI_INT, partner, 1,
94 MPI_COMM_WORLD, &status );
96 MPI_Send( buf, 3, MPI_INT, partner, 2, MPI_COMM_WORLD );
97 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, 1,
98 MPI_BOTTOM, 0, MPI_INT, partner, 1,
99 MPI_COMM_WORLD, &status );
103 Next test - check that a cancel for a request receive from
104 MPI_PROC_NULL succeeds (there is some suspicion that some
105 systems can't handle this - also, MPI_REQUEST_NULL
107 Note that a null request is invalid (see the various NULL comments)
108 r1 = MPI_REQUEST_NULL;
111 MPI_Irecv( buf, 10, MPI_INT, MPI_PROC_NULL, 0, MPI_COMM_WORLD, &r1 );
114 MPI_Request_free( &r1 );