7 #define DEF_MAX_MSG 2000000
9 This program tests a flood of data for both unexpected and expected messages to test any internal message fragmentation or protocol shifts
11 An optional argument can change the maximum message size. For example, use
13 to stress the memory system (the size is the number of ints, not bytes)
16 void SetupData ( int *, int, int );
17 void SetupRdata ( int *, int );
18 int CheckData ( int *, int, int, MPI_Status * );
21 static int verbose = 1;
23 static int verbose = 0;
26 int main( int argc, char **argv )
29 MPI_Request r[MAX_REQ];
30 MPI_Status s[MAX_REQ];
31 int msgsize, maxmsg, root, i, size, rank, err = 0, toterr;
32 int max_msg_size = DEF_MAX_MSG;
35 MPI_Init( &argc, &argv );
37 comm = MPI_COMM_WORLD;
39 MPI_Comm_size( comm, &size );
40 MPI_Comm_rank( comm, &rank );
43 printf( "This test requires at least 2 processors\n" );
47 /* Check for a max message argument */
50 max_msg_size = atoi( argv[1] );
51 /* Correct if unrecognized argument */
52 if (max_msg_size <= 0) max_msg_size = DEF_MAX_MSG;
55 MPI_Bcast( &max_msg_size, 1, MPI_INT, 0, MPI_COMM_WORLD );
57 /* First, try large blocking sends to root */
61 maxmsg = max_msg_size;
62 if (rank == root && verbose) printf( "Blocking sends: " );
63 while (msgsize < maxmsg) {
65 if (verbose) { printf( "%d ", msgsize ); fflush( stdout ); }
66 rbuf = (int *)malloc( msgsize * sizeof(int) );
68 printf( "Could not allocate %d words\n", msgsize );
71 for (i=0; i<size; i++) {
72 if (i == rank) continue;
73 SetupRdata( rbuf, msgsize );
74 MPI_Recv( rbuf, msgsize, MPI_INT, i, 2*i, comm, s );
75 err += CheckData( rbuf, msgsize, 2*i, s );
80 sbuf = (int *)malloc( msgsize * sizeof(int) );
82 printf( "Could not allocate %d words\n", msgsize );
85 SetupData( sbuf, msgsize, 2*rank );
86 MPI_Ssend( sbuf, msgsize, MPI_INT, root, 2*rank, comm );
91 if (rank == 0 && verbose) { printf( "\n" ); fflush( stdout ); }
93 /* Next, try unexpected messages with Isends */
95 maxmsg = max_msg_size;
96 if (rank == root && verbose) printf( "Unexpected recvs: " );
97 while (msgsize < maxmsg) {
99 if (verbose) { printf( "%d ", msgsize ); fflush( stdout ); }
100 rbuf = (int *)malloc( msgsize * sizeof(int) );
102 printf( "Could not allocate %d words\n", msgsize );
103 MPI_Abort( comm, 1 );
106 for (i=0; i<size; i++) {
107 if (i == rank) continue;
108 SetupRdata( rbuf, msgsize );
109 MPI_Recv( rbuf, msgsize, MPI_INT, i, 2*i, comm, s );
110 err += CheckData( rbuf, msgsize, 2*i, s );
115 sbuf = (int *)malloc( msgsize * sizeof(int) );
117 printf( "Could not allocate %d words\n", msgsize );
118 MPI_Abort( comm, 1 );
120 SetupData( sbuf, msgsize, 2*rank );
121 MPI_Isend( sbuf, msgsize, MPI_INT, root, 2*rank, comm, r );
128 if (rank == 0 && verbose) { printf( "\n" ); fflush( stdout ); }
130 /* Try large synchronous blocking sends to root */
134 maxmsg = max_msg_size;
135 if (rank == root && verbose) printf( "Synchronous sends: " );
136 while (msgsize < maxmsg) {
138 if (verbose) { printf( "%d ", msgsize ); fflush( stdout ); }
139 rbuf = (int *)malloc( msgsize * sizeof(int) );
141 printf( "Could not allocate %d words\n", msgsize );
142 MPI_Abort( comm, 1 );
144 for (i=0; i<size; i++) {
145 if (i == rank) continue;
146 SetupRdata( rbuf, msgsize );
147 MPI_Recv( rbuf, msgsize, MPI_INT, i, 2*i, comm, s );
148 err += CheckData( rbuf, msgsize, 2*i, s );
153 sbuf = (int *)malloc( msgsize * sizeof(int) );
155 printf( "Could not allocate %d words\n", msgsize );
156 MPI_Abort( comm, 1 );
158 SetupData( sbuf, msgsize, 2*rank );
159 MPI_Send( sbuf, msgsize, MPI_INT, root, 2*rank, comm );
164 if (rank == 0 && verbose) { printf( "\n" ); fflush( stdout ); }
166 /* Next, try expected messages with Rsend */
168 maxmsg = max_msg_size;
169 if (rank == root && verbose) printf( "Expected recvs and Rsend: " );
170 while (msgsize < maxmsg) {
172 if (verbose) { printf( "%d ", msgsize ); fflush( stdout ); }
173 rbuf = (int *)malloc( msgsize * sizeof(int) );
175 printf( "Could not allocate %d words\n", msgsize );
176 MPI_Abort( comm, 1 );
178 for (i=0; i<size; i++) {
179 if (i == rank) continue;
180 SetupRdata( rbuf, msgsize );
181 MPI_Irecv( rbuf, msgsize, MPI_INT, i, 2*i, comm, r );
182 MPI_Send( MPI_BOTTOM, 0, MPI_INT, i, 2*i+1, comm );
184 err += CheckData( rbuf, msgsize, 2*i, s );
189 sbuf = (int *)malloc( msgsize * sizeof(int) );
191 printf( "Could not allocate %d words\n", msgsize );
192 MPI_Abort( comm, 1 );
194 SetupData( sbuf, msgsize, 2*rank );
195 MPI_Recv( MPI_BOTTOM, 0, MPI_INT, root, 2*rank+1, comm, s );
196 MPI_Send( sbuf, msgsize, MPI_INT, root, 2*rank, comm );
201 if (rank == 0 && verbose) { printf( "\n" ); fflush( stdout ); }
204 MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
207 if (toterr == 0) printf( " No Errors\n" );
208 else printf( "!! found %d errors\n", toterr );
211 printf( "!! found %d errors on processor %d\n", err, rank );
218 void SetupData( sbuf, n, tag )
227 int CheckData( rbuf, n, tag, s )
233 MPI_Get_count( s, MPI_INT, &act_n );
235 printf( "Received %d instead of %d ints\n", act_n, n );
238 for (i=0; i<n; i++) {
240 printf( "rbuf[%d] is %d, should be %d\n", i, rbuf[i], i );
241 printf( "rbuf[%d] is 0x%x, should be 0x%x\n", i, rbuf[i], i );
248 void SetupRdata( rbuf, n )
253 for (i=0; i<n; i++) rbuf[i] = -(i+1);