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 waitall2, except the incoming
7 messages come from processes 1 and 2. (no message comes from process 3).
14 #if defined(NEEDS_STDLIB_PROTOTYPES)
20 void Pause( double sec )
22 /*double t1 =*/ MPI_Wtime();
24 // while (MPI_Wtime() - t1 < sec) ;
27 int main( int argc, char **argv )
29 int size, rank, flag, i;
30 int *buf1, *buf2, cnt;
32 MPI_Status statuses[2];
35 MPI_Init( &argc, &argv );
36 MPI_Comm_size( MPI_COMM_WORLD, &size );
37 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
40 printf( "This test requires at least 3 processors\n" );
41 MPI_Abort( MPI_COMM_WORLD, 1 );
45 /* Large enough that almost certainly a rendezvous algorithm will be used
46 by Issend. buflimit.c will give you a more reliable value */
50 process 0 process 1 process 2
53 Barrier Barrier Barrier
54 pause(2 sec) pause(2 sec)
57 sendrecv (process 2) sendrecv(process0)
61 If the test for Issend2 never succeeds, then the waitall appears to be
62 waiting for req1 first. By using Issend, we can keep the program from
65 buf1 = (int *)malloc( cnt * sizeof(int) );
66 buf2 = (int *)malloc( cnt * sizeof(int) );
68 printf( "Could not allocate buffers of size %d\n", cnt );
69 MPI_Abort( MPI_COMM_WORLD, 1 );
73 for (i=0; i<cnt; i++) {
78 MPI_Barrier( MPI_COMM_WORLD );
80 MPI_Barrier( MPI_COMM_WORLD );
82 MPI_Isend( buf2, cnt, MPI_INT, 1, 2, MPI_COMM_WORLD, &req[0] );
85 while (t0 + 5.0 > MPI_Wtime() && !flag)
86 MPI_Test( &req[0], &flag, &statuses[0] );
87 /* Tell process 2 to go ahead */
88 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_BYTE, 2, 3,
89 MPI_BOTTOM, 0, MPI_BYTE, 2, 3, MPI_COMM_WORLD, &statuses[0] );
92 "*ERROR: MPI_Waitall appears to be waiting for requests in the order\n\
93 they appear in the request list\n" );
94 /* We can wait now since process 2 should have allowed the wait
96 MPI_Wait( &req[0], &statuses[0] );
99 printf( " No Errors\n" ) ;
102 else if (rank == 1) {
103 MPI_Irecv( buf1, cnt, MPI_INT, 2, 1, MPI_COMM_WORLD, &req[0] );
104 MPI_Irecv( buf2, cnt, MPI_INT, 0, 2, MPI_COMM_WORLD, &req[1] );
105 MPI_Barrier( MPI_COMM_WORLD );
107 MPI_Waitall( 2, req, statuses );
109 else if (rank == 2) {
110 MPI_Barrier( MPI_COMM_WORLD );
111 /* Wait for process 0 to tell us to go ahead */
112 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_BYTE, 0, 3,
113 MPI_BOTTOM, 0, MPI_BYTE, 0, 3, MPI_COMM_WORLD, &statuses[0] );
114 MPI_Send( buf1, cnt, MPI_INT, 1, 1, MPI_COMM_WORLD );
117 MPI_Barrier( MPI_COMM_WORLD );