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 );
28 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
32 comm = MPI_COMM_WORLD;
35 buf0 = (int *)malloc( n0 * sizeof(int) );
36 buf1 = (int *)malloc( n1 * sizeof(int) );
37 buf2 = (int *)malloc( n2 * sizeof(int) );
38 if (!buf0 || !buf1 || !buf2) {
39 fprintf( stderr, "Unable to allocate buffers of size %d\n",
40 n0 * (int)sizeof(int) );
41 MPI_Abort( MPI_COMM_WORLD, 1 );
43 memset( buf0, -1, n0 * sizeof(int) );
44 memset( buf1, -1, n0 * sizeof(int) );
45 memset( buf2, -1, n0 * sizeof(int) );
48 MPI_Irecv( buf0, n0, MPI_INT, src, 0, comm, &r[0] );
49 MPI_Irecv( buf1, n1, MPI_INT, src, 1, comm, &r[1] );
50 MPI_Irecv( buf2, n2, MPI_INT, src, 2, comm, &r[2] );
56 memset( s, -1, sizeof(s) );
57 MPI_Waitall( 3, r, s );
58 MPI_Test_cancelled( &s[0], &flag );
61 printf( "request 0 was cancelled!\n" );
63 MPI_Test_cancelled( &s[1], &flag );
66 printf( "request 1 was not cancelled!\n" );
68 MPI_Test_cancelled( &s[2], &flag );
71 printf( "request 2 was cancelled!\n" );
79 MPI_Send( buf0, n0, MPI_INT, dest, 0, comm );
80 MPI_Isend( buf2, n2, MPI_INT, dest, 2, comm, &r[1] );
81 MPI_Isend( buf1, n1, MPI_INT, dest, 4, comm, &r[0] );
83 memset( s, -3, sizeof(s) );
86 MPI_Testall( 2, r, &tflag, s );
88 MPI_Test_cancelled( &s[0], &flag );
91 printf( "send request 0 was not cancelled!\n" );
93 MPI_Test_cancelled( &s[1], &flag );
96 printf( "send request 1 was cancelled!\n" );
100 /* If all requests are not complete, then neither r nor s
102 if ( (s[0].MPI_ERROR) != -3) {
104 printf( "Send request status 0 modified. s[0].MPI_ERROR = %x\n",
107 if ( (s[1].MPI_ERROR) != -3) {
109 printf( "Send request status 1 modified. s[1].MPI_ERROR = %x\n",
115 MPI_Testall( 2, r, &tflag, s );
117 MPI_Test_cancelled( &s[0], &flag );
120 printf( "send request 0 was not cancelled!\n" );
122 MPI_Test_cancelled( &s[1], &flag );
125 printf( "send request 1 was cancelled!\n" );
128 if (rank != src && rank != dest) {
134 MTest_Finalize( errs );