2 * This code tests waitall; in particular, the that ordering requirement
3 * on nonblocking communication is observed.
9 #if defined(NEEDS_STDLIB_PROTOTYPES)
21 void sleep( int secs )
24 /* Also needs include <time.h>? */
25 struct timespec rqtp = { 10, 0 };
26 nanosleep(&rqtp, NULL);
30 while (MPI_Wtime() - t < (double)secs) ;
35 int main( int argc, char **argv )
38 int i, j, count, err = 0, toterr;
39 MPI_Request r[MAX_REQ];
40 MPI_Status s[MAX_REQ];
41 int buf[MAX_REQ][MAX_REQ];
43 MPI_Init( &argc, &argv );
44 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
45 MPI_Comm_size( MPI_COMM_WORLD, &size );
48 fprintf( stderr, "This test requires at least 2 processes\n" );
49 MPI_Abort( MPI_COMM_WORLD, 1 );
51 /* First, cause the wait all to happen AFTER the Sends */
53 for (i=0; i<MAX_REQ; i++) {
54 MPI_Irecv( buf[i], i+1, MPI_INT, 1, 99, MPI_COMM_WORLD,
57 MPI_Waitall( MAX_REQ, r, s );
58 /* Check that we've received the correct data */
59 for (i=0; i<MAX_REQ; i++) {
60 MPI_Get_count( &s[MAX_REQ-1-i], MPI_INT, &count );
63 fprintf( stderr, "Wrong count (%d) for request %d\n",
69 for (i=0; i<MAX_REQ; i++) {
71 buf[i][j] = i * MAX_REQ + j;
72 MPI_Send( buf[i], i, MPI_INT, 0, 99, MPI_COMM_WORLD );
76 /* Second, cause the waitall to start BEFORE the Sends */
78 for (i=0; i<MAX_REQ; i++) {
79 MPI_Irecv( buf[i], i+1, MPI_INT, 1, 99, MPI_COMM_WORLD,
82 MPI_Send( MPI_BOTTOM, 0, MPI_INT, 1, 0, MPI_COMM_WORLD );
83 MPI_Waitall( MAX_REQ, r, s );
84 /* Check that we've received the correct data */
85 for (i=0; i<MAX_REQ; i++) {
86 MPI_Get_count( &s[MAX_REQ-1-i], MPI_INT, &count );
90 "Wrong count (%d) for request %d (waitall posted)\n",
96 MPI_Recv( MPI_BOTTOM, 0, MPI_INT, 0, 0, MPI_COMM_WORLD, &s[0] );
98 for (i=0; i<MAX_REQ; i++) {
100 buf[i][j] = i * MAX_REQ + j;
101 MPI_Send( buf[i], i, MPI_INT, 0, 99, MPI_COMM_WORLD );
106 MPI_Barrier( MPI_COMM_WORLD );
110 printf( "Test complete\n" );
112 printf( "Found %d errors in test!\n", toterr );