Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Have the communicators created together share a unique ID.
[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
24     int i = 0;
25     int randval;
26     int rank;
27     int errs = 0;
28     MPI_Comm newcomm;
29     double startTime;
30     int nLoop = 10000;
31
32     MTest_Init(&argc, &argv);
33
34     for (i = 1; i < argc; i++) {
35         if (strcmp(argv[i], "--loopcount") == 0) {
36             i++;
37             nLoop = atoi(argv[i]);
38         }
39         else {
40             fprintf(stderr, "Unrecognized argument %s\n", argv[i]);
41         }
42     }
43
44     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
45
46     startTime = MPI_Wtime();
47     for (i = 0; i < nLoop; i++) {
48
49         if (rank == 0 && (i % 100 == 0)) {
50             double rate = MPI_Wtime() - startTime;
51             if (rate > 0) {
52                 rate = i / rate;
53                 MTestPrintfMsg(10, "After %d (%f)\n", i, rate);
54             }
55             else {
56                 MTestPrintfMsg(10, "After %d\n", i);
57             }
58         }
59
60         /* FIXME: Explain the rationale behind rand in this test */
61         randval = rand();
62
63         if (randval % (rank + 2) == 0) {
64             MPI_Comm_split(MPI_COMM_WORLD, 1, rank, &newcomm);
65             MPI_Comm_free(&newcomm);
66         }
67         else {
68             MPI_Comm_split(MPI_COMM_WORLD, MPI_UNDEFINED, rank, &newcomm);
69             if (newcomm != MPI_COMM_NULL) {
70                 errs++;
71                 printf("Created a non-null communicator with MPI_UNDEFINED\n");
72             }
73         }
74
75     }
76
77     MTest_Finalize(errs);
78     MPI_Finalize();
79
80     return 0;
81 }