7 #define MAX_MSG_CNT 32000
10 This program tests a flood of data of short messages to test handling
11 of both incoming messages and internal message queues
14 void SetupData ( int *, int, int );
15 void SetupRdata ( int *, int );
16 int CheckData ( int *, int, int, MPI_Status * );
19 static int verbose = 1;
21 static int verbose = 0;
25 int main( int argc, char **argv )
28 MPI_Request r[MAX_REQ];
29 MPI_Status s[MAX_REQ];
30 int msgsize, maxmsg, root, i, j, size, rank, err = 0, msgcnt, toterr;
33 MPI_Init( &argc, &argv );
35 comm = MPI_COMM_WORLD;
37 MPI_Comm_size( comm, &size );
38 MPI_Comm_rank( comm, &rank );
41 printf( "This test requires at least 2 processors\n" );
45 /* First, try large blocking sends to root */
51 if (rank == root && verbose) printf( "Blocking sends: " );
52 while (msgsize <= maxmsg) {
54 if (verbose) { printf( "%d ", msgsize ); fflush( stdout ); }
55 rbuf = (int *)malloc( msgsize * sizeof(int) );
57 printf( "Could not allocate %d words\n", msgsize );
60 for (i=0; i<size; i++) {
61 if (i == rank) continue;
62 for (j=0; j<msgcnt; j++) {
63 SetupRdata( rbuf, msgsize );
64 MPI_Recv( rbuf, msgsize, MPI_INT, i, 2*i, comm, s );
65 err += CheckData( rbuf, msgsize, 2*i, s );
71 sbuf = (int *)malloc( msgsize * sizeof(int) );
73 printf( "Could not allocate %d words\n", msgsize );
76 SetupData( sbuf, msgsize, 2*rank );
77 for (j=0; j<msgcnt; j++)
78 MPI_Send( sbuf, msgsize, MPI_INT, root, 2*rank, comm );
83 if (rank == 0 && verbose) { printf( "\n" ); fflush( stdout ); }
85 /* Next, try unexpected messages with Isends */
89 if (rank == root && verbose) printf( "Unexpected recvs: " );
90 while (msgsize <= maxmsg) {
92 if (verbose) { printf( "%d ", msgsize ); fflush( stdout ); }
93 rbuf = (int *)malloc( msgsize * sizeof(int) );
95 printf( "Could not allocate %d words\n", msgsize );
99 for (i=0; i<size; i++) {
100 if (i == rank) continue;
101 for (j=0; j<msgcnt; j++) {
102 SetupRdata( rbuf, msgsize );
103 MPI_Recv( rbuf, msgsize, MPI_INT, i, 2*i, comm, s );
104 err += CheckData( rbuf, msgsize, 2*i, s );
110 sbuf = (int *)malloc( msgsize * sizeof(int) );
112 printf( "Could not allocate %d words\n", msgsize );
113 MPI_Abort( comm, 1 );
115 SetupData( sbuf, msgsize, 2*rank );
116 for (j=0; j<msgcnt; j++) {
117 MPI_Isend( sbuf, msgsize, MPI_INT, root, 2*rank, comm, &r[j] );
120 MPI_Waitall( msgcnt, r, s );
125 if (rank == 0 && verbose) { printf( "\n" ); fflush( stdout ); }
127 /* Try large synchronous blocking sends to root */
132 if (rank == root && verbose) printf( "Synchronous sends: " );
133 while (msgsize <= maxmsg) {
135 if (verbose) { printf( "%d ", msgsize ); fflush( stdout ); }
136 rbuf = (int *)malloc( msgsize * sizeof(int) );
138 printf( "Could not allocate %d words\n", msgsize );
139 MPI_Abort( comm, 1 );
141 for (i=0; i<size; i++) {
142 if (i == rank) continue;
143 for (j=0; j<msgcnt; j++) {
144 SetupRdata( rbuf, msgsize );
145 MPI_Recv( rbuf, msgsize, MPI_INT, i, 2*i, comm, s );
146 err += CheckData( rbuf, msgsize, 2*i, s );
152 sbuf = (int *)malloc( msgsize * sizeof(int) );
154 printf( "Could not allocate %d words\n", msgsize );
155 MPI_Abort( comm, 1 );
157 SetupData( sbuf, msgsize, 2*rank );
158 for (j=0; j<msgcnt; j++)
159 MPI_Ssend( sbuf, msgsize, MPI_INT, root, 2*rank, comm );
164 if (rank == 0 && verbose) { printf( "\n" ); fflush( stdout ); }
166 MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
169 if (toterr == 0) printf( " No Errors\n" );
170 else printf( "!! found %d errors\n", toterr );
173 printf( "!! found %d errors on processor %d\n", err, rank );
180 void SetupData( sbuf, n, tag )
189 int CheckData( rbuf, n, tag, s )
195 MPI_Get_count( s, MPI_INT, &act_n );
197 printf( "Received %d instead of %d ints\n", act_n, n );
200 for (i=0; i<n; i++) {
202 printf( "rbuf[%d] is %d, should be %d\n", i, rbuf[i], i );
209 void SetupRdata( rbuf, n )
214 for (i=0; i<n; i++) rbuf[i] = -(i+1);