5 #if defined(NEEDS_STDLIB_PROTOTYPES)
14 Test to make sure that nonblocking routines actually work. This
15 stresses them by sending large numbers of requests and receiving them
18 int main( int argc, char **argv )
20 int count, tag, nsend, myid, np, rcnt, scnt, i, j;
21 int *(sbuf[MAXNP]), *(rbuf[MAXNP]);
23 MPI_Request *rsend, *rrecv;
25 MPI_Init( &argc, &argv );
26 MPI_Comm_rank( MPI_COMM_WORLD, &myid );
27 MPI_Comm_size( MPI_COMM_WORLD, &np );
31 "This test must run with at most %d processes\n", MAXNP );
32 MPI_Abort( MPI_COMM_WORLD, 1 );
36 rsend = (MPI_Request *) malloc ( nsend * sizeof(MPI_Request) );
37 rrecv = (MPI_Request *) malloc ( nsend * sizeof(MPI_Request) );
38 if (!rsend || !rrecv) {
39 fprintf( stderr, "Failed to allocate space for requests\n" );
40 MPI_Abort( MPI_COMM_WORLD, 1 );
43 for (count = 1; count < 10000; count *= 2) {
44 for (i=0; i<nsend; i++) {
45 sbuf[i] = (int *)calloc( count, sizeof(int) );
46 rbuf[i] = (int *)malloc( count * sizeof(int) );
47 if (!sbuf[i] || !rbuf[i]) {
48 fprintf( stderr, "Unable to allocate %d ints\n", count );
49 MPI_Abort( MPI_COMM_WORLD, 1 );
53 /* We'll send/recv from everyone */
56 /* The MPI standard requires that active buffers be distinct
57 in nonblocking calls */
60 for (i=0; i<np; i++) {
62 MPI_Isend( sbuf[scnt], count, MPI_INT, i,
63 tag, MPI_COMM_WORLD, &rsend[scnt] );
68 for (i=0; i<np; i++) {
70 MPI_Irecv( rbuf[rcnt], count, MPI_INT, i,
71 tag, MPI_COMM_WORLD, &rrecv[rcnt] );
76 /* In general, it would be better to use MPI_Waitall, but this should
78 for (i=0; i<rcnt; i++) {
79 MPI_Wait( &rrecv[i], &status );
81 for (i=0; i<scnt; i++) {
82 MPI_Wait( &rsend[i], &status );
85 for (i=0; i<nsend; i++) {
90 MPI_Barrier( MPI_COMM_WORLD );
91 if (myid == 0 && (count % 64) == 0) {
92 printf( "All processes completed for count = %ld ints of data\n",