2 Test of waitall. This makes sure that the requests in a wait can occur
12 #if defined(NEEDS_STDLIB_PROTOTYPES)
18 void Pause( double sec )
20 /*double t1 =*/ MPI_Wtime();
22 //while (MPI_Wtime() - t1 < sec) ;
25 int main( int argc, char **argv )
27 int size, rank, flag, i;
28 int *buf1, *buf2, cnt;
30 MPI_Status statuses[2];
33 MPI_Init( &argc, &argv );
34 MPI_Comm_size( MPI_COMM_WORLD, &size );
35 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
38 printf( "This test requires at least 2 processors\n" );
39 MPI_Abort( MPI_COMM_WORLD, 1 );
43 /* Large enough that almost certainly a rendezvous algorithm will be used
44 by Issend. buflimit.c will give you a more reliable value */
52 pause(2 sec) pause(2 sec)
58 If the test for Issend2 never succeeds, then the waitall appears to be
59 waiting for req1 first. By using Issend, we can keep the program from
62 buf1 = (int *)malloc( cnt * sizeof(int) );
63 buf2 = (int *)malloc( cnt * sizeof(int) );
65 printf( "Could not allocate buffers of size %d\n", cnt );
66 MPI_Abort( MPI_COMM_WORLD, 1 );
70 for (i=0; i<cnt; i++) {
76 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_BYTE, size - 1, 3,
77 MPI_BOTTOM, 0, MPI_BYTE, size - 1, 3,
78 MPI_COMM_WORLD, &statuses[0] );
80 MPI_Isend( buf2, cnt, MPI_INT, size-1, 2, MPI_COMM_WORLD, &req[0] );
83 while (t0 + 5.0 > MPI_Wtime() && !flag)
84 MPI_Test( &req[0], &flag, &statuses[0] );
85 MPI_Send( buf1, cnt, MPI_INT, size-1, 1, MPI_COMM_WORLD );
88 "*ERROR: MPI_Waitall appears to be waiting for requests in the order\n\
89 they appear in the request list\n" );
90 MPI_Wait( &req[0], &statuses[0] );
93 printf( "No errors\n" ) ;
96 else if (rank == size - 1) {
97 MPI_Irecv( buf1, cnt, MPI_INT, 0, 1, MPI_COMM_WORLD, &req[0] );
98 MPI_Irecv( buf2, cnt, MPI_INT, 0, 2, MPI_COMM_WORLD, &req[1] );
99 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_BYTE, 0, 3,
100 MPI_BOTTOM, 0, MPI_BYTE, 0, 3, MPI_COMM_WORLD, &statuses[0] );
102 MPI_Waitall( 2, req, statuses );