Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove few tests which may never finish, and change one that used too much stack...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / nblock.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "mpi.h"
4
5 #if defined(NEEDS_STDLIB_PROTOTYPES)
6 #include "protofix.h"
7 #endif
8
9 #ifndef MAXNP
10 #define MAXNP 16
11 #endif
12
13 /*
14    Test to make sure that nonblocking routines actually work.  This
15    stresses them by sending large numbers of requests and receiving them
16    piecemeal.
17  */
18 int main( int argc, char **argv )
19 {
20     int count, tag, nsend, myid, np, rcnt, scnt, i, j;
21     int *(sbuf[MAXNP]), *(rbuf[MAXNP]);
22     MPI_Status status;
23     MPI_Request *rsend, *rrecv;
24
25     MPI_Init( &argc, &argv );
26     MPI_Comm_rank( MPI_COMM_WORLD, &myid );
27     MPI_Comm_size( MPI_COMM_WORLD, &np );
28
29     if (np > MAXNP) {
30         fprintf( stderr, 
31                  "This test must run with at most %d processes\n", MAXNP );
32         MPI_Abort( MPI_COMM_WORLD, 1 );
33     }
34
35     nsend = 3 * np;
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 );
41     }
42
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 );
50             }
51         }
52         
53         /* We'll send/recv from everyone */
54         scnt = 0;
55         rcnt = 0;
56         /* The MPI standard requires that active buffers be distinct
57            in nonblocking calls */
58         for (j=0; j<3; j++) {
59             tag = j;
60             for (i=0; i<np; i++) {
61                 if (i != myid) {
62                     MPI_Isend( sbuf[scnt], count, MPI_INT, i, 
63                                tag, MPI_COMM_WORLD, &rsend[scnt] );
64                     scnt++;
65                 }
66                 
67             }
68             for (i=0; i<np; i++) {
69                 if (i != myid) {
70                     MPI_Irecv( rbuf[rcnt], count, MPI_INT, i, 
71                                tag, MPI_COMM_WORLD, &rrecv[rcnt] );
72                     rcnt++;
73                 }
74             }
75         }
76         /* In general, it would be better to use MPI_Waitall, but this should
77            work as well */
78         for (i=0; i<rcnt; i++) {
79             MPI_Wait( &rrecv[i], &status );
80         }
81         for (i=0; i<scnt; i++) {
82             MPI_Wait( &rsend[i], &status );
83         }
84
85         for (i=0; i<nsend; i++) {
86             free( sbuf[i] );
87             free( rbuf[i] );
88         }
89
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", 
93                     (long)count );
94             fflush(stdout);
95         }
96     }
97     MPI_Finalize();
98     return 0;
99 }
100
101