Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / sendflood.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2008 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include "mpi.h"
10
11 /*
12  * Run this test with 8 processes.  This test was submitted by xxx
13  * as a result of problems seen with the ch3:shm device on a Solaris 
14  * system.  The symptom is that the test hangs; this is due to losing 
15  * a message, probably due to a race condition in a message-queue update.
16  * As a test for race conditions, it may need to be run multiple times
17  * to expose a problem if a problem does exist.
18  */
19
20 #define LOOP_COUNT  10000
21 #define DATA_SIZE   4
22 #define MP_TAG      999
23
24 #define PROGRESS_COUNT 0xfff
25 static int verbose = 0;
26 static int loopProgress = 0;
27
28 int main( int argc, char *argv[] )
29 {
30     int     nProc, rank ;
31     int     i, j, status ;
32     FILE    *pf=0 ;
33
34     MPI_Init( &argc, &argv ) ;
35     MPI_Comm_size( MPI_COMM_WORLD, &nProc ) ;
36     MPI_Comm_rank( MPI_COMM_WORLD, &rank ) ;
37
38     for (i=1; i<argc; i++) {
39         if (strcmp(argv[i],"-v") == 0 ||
40             strcmp(argv[i],"--verbose") == 0) verbose = 1;
41         else if (strcmp(argv[i],"-p") == 0 ||
42                  strcmp(argv[i],"--progress") == 0) loopProgress = 1;
43         else {
44             if (rank == 0) {
45                 fprintf( stderr, "%s: [ -v | --verbose ] [ -p | --progress ]\n",
46                          argv[0] );
47                 fflush(stderr);
48             }
49         }
50     }
51
52     if (verbose) {
53         char    buf[ 128 ] ;
54         sprintf( buf, "fast_mpi_%d.dmp", rank ) ;
55         pf = fopen( buf, "w" ) ;
56     }
57     else if (loopProgress) {
58         pf = stdout;
59     }
60
61     if( !rank ) {
62        int      **psend ;
63        int      **precv ;
64        psend = (int**)calloc( nProc, sizeof( int *) ) ;
65        precv = (int**)calloc( nProc, sizeof( int *) ) ;
66        for( i = 0 ; i < nProc ; i++ ) {
67            psend[ i ] = (int*)calloc( DATA_SIZE, sizeof( int ) ) ;
68            precv[ i ] = (int*)calloc( DATA_SIZE, sizeof( int ) ) ;
69        }
70        for( i = 0 ; i < LOOP_COUNT ; i++ ) {
71            if (verbose) {
72                fprintf( pf, "Master : loop %d\n", i ) ;
73                fflush( pf ) ;
74            }
75            else if (loopProgress && (i & PROGRESS_COUNT) == 0) {
76              fprintf( pf, "Master: loop %d\n", i ); fflush( pf );
77            }
78           for( j = 1 ; j < nProc ; j++ ) {
79               if (verbose) {
80                   fprintf( pf, "  read from child %d\n", j ) ;
81                   fflush( pf ) ;
82               }
83              status = MPI_Recv( precv[ j ], DATA_SIZE, MPI_INT, j, MP_TAG,
84                                 MPI_COMM_WORLD, MPI_STATUS_IGNORE ) ;
85              if (verbose) {
86                  fprintf( pf, "  read from child %d done, status = %d\n", j,
87                           status ) ;
88                  fflush( pf ) ;
89              }
90           }
91           for( j = 1 ; j < nProc ; j++ ) {
92               if (verbose) {
93                   fprintf( pf, "  send to child %d\n", j ) ;
94                   fflush( pf ) ;
95               }
96              status = MPI_Send( psend[ j ], DATA_SIZE - 1, MPI_INT, j,
97                                 MP_TAG, MPI_COMM_WORLD ) ;
98              if (verbose) {
99                  fprintf( pf, "  send to child %d done, status = %d\n", j,
100                           status ) ;
101                  fflush( pf ) ;
102              }
103           }
104        }
105        for( i = 0 ; i < nProc ; i++ ) {
106            free( psend[ i ] );
107            free( precv[ i ] );
108        }
109        free( psend );
110        free( precv );
111     } else {
112        int  *psend ;
113        int  *precv ;
114        psend = (int*)calloc( DATA_SIZE, sizeof( int ) ) ;
115        precv = (int*)calloc( DATA_SIZE, sizeof( int ) ) ;
116        for( i = 0 ; i < LOOP_COUNT ; i++ ) {
117            if (verbose) {
118                fprintf( pf, "  send to master\n" ) ;
119                fflush( pf ) ;
120            }
121            /*
122            else if (loopProgress && (i & PROGRESS_COUNT) == 0) {
123              fprintf( pf, "Slave: loop %d\n", i ); fflush( pf );
124            }
125            */
126            status = MPI_Send( psend, DATA_SIZE - 1, MPI_INT, 0, MP_TAG,
127                               MPI_COMM_WORLD ) ;
128            if (verbose) {
129                fprintf( pf, "  send to master done, status = %d\n", status ) ;
130                fflush( pf ) ;
131                fprintf( pf, "  read from master\n" ) ;
132                fflush( pf ) ;
133            }
134            status = MPI_Recv( precv, DATA_SIZE, MPI_INT, 0, MP_TAG,
135                               MPI_COMM_WORLD, MPI_STATUS_IGNORE ) ;
136            if (verbose) {
137                fprintf( pf, "  read from master done, status = %d\n", status ) ;
138                fflush( pf ) ;
139            }
140        }
141        free( psend );
142        free( precv );
143     }
144     if (verbose) {
145         fclose( pf ) ;
146     }
147     MPI_Finalize() ;
148
149     /* This test fails if it hangs */
150     if (rank == 0) {
151         printf( " No Errors\n" );
152     }
153
154     return 0;
155 }
156