1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2006 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
10 #include <string.h> /* For memset */
12 int main( int argc, char *argv[] )
16 int *buf0, *buf1, *buf2;
17 int rank, size, src, dest, flag, errs = 0;
21 MTest_Init( &argc, &argv );
23 MPI_Comm_size( MPI_COMM_WORLD, &size );
25 fprintf( stderr, "Must run with at least 2 processes\n" );
26 MPI_Abort( MPI_COMM_WORLD, 1 );
29 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
33 comm = MPI_COMM_WORLD;
36 buf0 = (int *)malloc( n0 * sizeof(int) );
37 buf1 = (int *)malloc( n1 * sizeof(int) );
38 buf2 = (int *)malloc( n2 * sizeof(int) );
39 if (!buf0 || !buf1 || !buf2) {
40 fprintf( stderr, "Unable to allocate buffers of size %d\n",
41 n0 * (int)sizeof(int) );
42 MPI_Abort( MPI_COMM_WORLD, 1 );
45 memset( buf0, -1, n0 * sizeof(int) );
46 memset( buf1, -1, n0 * sizeof(int) );
47 memset( buf2, -1, n0 * sizeof(int) );
50 MPI_Irecv( buf0, n0, MPI_INT, src, 0, comm, &r[0] );
51 MPI_Irecv( buf1, n1, MPI_INT, src, 1, comm, &r[1] );
52 MPI_Irecv( buf2, n2, MPI_INT, src, 2, comm, &r[2] );
58 memset( s, -1, sizeof(s) );
59 MPI_Waitall( 3, r, s );
60 MPI_Test_cancelled( &s[0], &flag );
63 printf( "request 0 was cancelled!\n" );
65 MPI_Test_cancelled( &s[1], &flag );
68 printf( "request 1 was not cancelled!\n" );
70 MPI_Test_cancelled( &s[2], &flag );
73 printf( "request 2 was cancelled!\n" );
81 MPI_Send( buf0, n0, MPI_INT, dest, 0, comm );
82 MPI_Isend( buf2, n2, MPI_INT, dest, 2, comm, &r[1] );
83 MPI_Isend( buf1, n1, MPI_INT, dest, 4, comm, &r[0] );
85 memset( s, -3, sizeof(s) );
88 MPI_Testall( 2, r, &tflag, s );
90 MPI_Test_cancelled( &s[0], &flag );
93 printf( "send request 0 was not cancelled!\n" );
95 MPI_Test_cancelled( &s[1], &flag );
98 printf( "send request 1 was cancelled!\n" );
102 /* If all requests are not complete, then neither r nor s
104 if ( (s[0].MPI_ERROR) != -3) {
106 printf( "Send request status 0 modified. s[0].MPI_ERROR = %x\n",
109 if ( (s[1].MPI_ERROR) != -3) {
111 printf( "Send request status 1 modified. s[1].MPI_ERROR = %x\n",
117 MPI_Testall( 2, r, &tflag, s );
119 MPI_Test_cancelled( &s[0], &flag );
122 printf( "send request 0 was not cancelled!\n" );
124 MPI_Test_cancelled( &s[1], &flag );
127 printf( "send request 1 was cancelled!\n" );
130 if (rank != src && rank != dest) {
136 MTest_Finalize( errs );