2 Test of waitall. This makes sure that the requests in a wait can occur
5 Run with 4 processes. This checks for code that listens to a specified
6 process. This is similar to the test in waitall3, except that the
7 wait is on sends instead of receives. Messages are sent by process 2 to
8 processes 0 and 1. Process 3 is uninvolved.
15 #if defined(NEEDS_STDLIB_PROTOTYPES)
21 void Pause( double sec )
23 /*double t1 =*/ MPI_Wtime();
25 // while (MPI_Wtime() - t1 < sec) ;
28 int main( int argc, char **argv )
30 int size, rank, flag, i;
31 int *buf1, *buf2, cnt;
33 MPI_Status statuses[2];
36 MPI_Init( &argc, &argv );
37 MPI_Comm_size( MPI_COMM_WORLD, &size );
38 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
41 printf( "This test requires at least 3 processors\n" );
42 MPI_Abort( MPI_COMM_WORLD, 1 );
46 /* Large enough that almost certainly a rendezvous algorithm will be used
47 by Issend. buflimit.c will give you a more reliable value */
51 process 0 process 1 process 2
54 Barrier Barrier Barrier
55 pause(2 sec) pause(2 sec) pause(1 sec)
58 sendrecv (process 1) sendrecv(process0)
62 If the test for Irecv2 never succeeds, then the waitall appears to be
63 waiting for req1 first. By using Issend, we can keep the program from
66 buf1 = (int *)malloc( cnt * sizeof(int) );
67 buf2 = (int *)malloc( cnt * sizeof(int) );
69 printf( "Could not allocate buffers of size %d\n", cnt );
70 MPI_Abort( MPI_COMM_WORLD, 1 );
74 for (i=0; i<cnt; i++) {
79 MPI_Barrier( MPI_COMM_WORLD );
81 MPI_Barrier( MPI_COMM_WORLD );
83 MPI_Irecv( buf2, cnt, MPI_INT, 2, 2, MPI_COMM_WORLD, &req[0] );
86 while (t0 + 5.0 > MPI_Wtime() && !flag)
87 MPI_Test( &req[0], &flag, &statuses[0] );
88 /* printf( "Test succeeded at %f with flag %d\n", MPI_Wtime()-t0, flag ); */
89 /* Tell process 2 to go ahead */
90 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_BYTE, 1, 3,
91 MPI_BOTTOM, 0, MPI_BYTE, 1, 3, MPI_COMM_WORLD, &statuses[0] );
94 "*ERROR: MPI_Waitall appears to be waiting for requests in the order\n\
95 they appear in the request list\n" );
96 /* We can wait now since process 2 should have allowed the wait
98 MPI_Wait( &req[0], &statuses[0] );
101 printf( " No Errors\n" ) ;
104 else if (rank == 2) {
105 MPI_Isend( buf1, cnt, MPI_INT, 1, 1, MPI_COMM_WORLD, &req[0] );
106 MPI_Isend( buf2, cnt, MPI_INT, 0, 2, MPI_COMM_WORLD, &req[1] );
107 MPI_Barrier( MPI_COMM_WORLD );
109 MPI_Waitall( 2, req, statuses );
111 else if (rank == 1) {
113 MPI_Barrier( MPI_COMM_WORLD );
114 /* Wait for process 0 to tell us to go ahead */
115 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_BYTE, 0, 3,
116 MPI_BOTTOM, 0, MPI_BYTE, 0, 3, MPI_COMM_WORLD, &statuses[0] );
117 MPI_Recv( buf1, cnt, MPI_INT, 2, 1, MPI_COMM_WORLD, &status );
120 MPI_Barrier( MPI_COMM_WORLD );