Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge tag 'v3_9_90' into hypervisor
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / ctxsplit.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "mpitest.h"
12
13 /*
14  * This check is intended to fail if there is a leak of context ids.  
15  * Because this is trying to exhaust the number of context ids, it needs
16  * to run for a longer time than many tests.  The for loop uses 100,000 
17  * iterations, which is adequate for MPICH (with only about 1k context ids
18  * available).
19  */
20
21 int main(int argc, char** argv) {
22
23    int      i=0;
24    int      randval;
25    int      rank;
26    int      errs = 0;
27    MPI_Comm newcomm;
28    double   startTime;
29    int      nLoop = 100000;
30    
31    MTest_Init(&argc,&argv);
32
33    for (i=1; i<argc; i++) {
34        if (strcmp( argv[i], "--loopcount" ) == 0)  {
35            i++;
36            nLoop = atoi( argv[i] );
37        }
38        else {
39            fprintf( stderr, "Unrecognized argument %s\n", argv[i] );
40        }
41    }
42
43    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
44
45    startTime = MPI_Wtime();
46    for (i=0; i<nLoop; i++) {
47        
48        if ( rank == 0 && (i%100 == 0) ) {
49            double rate = MPI_Wtime() - startTime;
50            if (rate > 0) {
51                rate = i / rate;
52                MTestPrintfMsg( 10, "After %d (%f)\n", i, rate );
53            }
54            else {
55                MTestPrintfMsg( 10, "After %d\n", i );
56            }
57        }
58        
59        /* FIXME: Explain the rationale behind rand in this test */
60        randval=rand();
61        
62        if (randval%(rank+2) == 0) {
63            MPI_Comm_split(MPI_COMM_WORLD,1,rank,&newcomm);
64            MPI_Comm_free( &newcomm );
65        }
66        else {
67            MPI_Comm_split(MPI_COMM_WORLD,MPI_UNDEFINED,rank,&newcomm);
68            if (newcomm != MPI_COMM_NULL) {
69                errs++;
70                printf( "Created a non-null communicator with MPI_UNDEFINED\n" );
71            }
72        }
73        
74    }
75    
76    MTest_Finalize( errs );
77    MPI_Finalize();
78    
79    return 0;
80 }