1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5 
6 /* This test attempts to create a large number of communicators, in an effort
7  * to exceed the number of communicators that the MPI implementation can
8  * provide.  It checks that the implementation detects this error correctly
9  * handles it.
10  */
11 
12 /* In this version, we duplicate MPI_COMM_WORLD in a non-blocking
13  * fashion until we run out of context IDs. */
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <mpi.h>
18 #include "mpitest.h"
19 
20 #define MAX_NCOMM 200000
21 
22 static const int verbose = 0;
23 
main(int argc,char ** argv)24 int main(int argc, char **argv)
25 {
26     int rank, nproc, mpi_errno;
27     int i, ncomm;
28     int errs = 1;
29     MPI_Comm *comm_hdls;
30     MPI_Request req;
31 
32     MTest_Init(&argc, &argv);
33 
34     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
35     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
36 
37     MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
38     comm_hdls = malloc(sizeof(MPI_Comm) * MAX_NCOMM);
39 
40 
41     ncomm = 0;
42     for (i = 0; i < MAX_NCOMM; i++) {
43         /* Note: the comms we create are all dups of MPI_COMM_WORLD */
44         MPI_Comm_idup(MPI_COMM_WORLD, &comm_hdls[i], &req);
45         mpi_errno = MPI_Wait(&req, MPI_STATUSES_IGNORE);
46         if (mpi_errno == MPI_SUCCESS) {
47             ncomm++;
48         } else {
49             if (verbose)
50                 printf("%d: Error creating comm %d\n", rank, i);
51             errs = 0;
52             break;
53         }
54     }
55 
56     for (i = 0; i < ncomm; i++)
57         MPI_Comm_free(&comm_hdls[i]);
58 
59     free(comm_hdls);
60     MTest_Finalize(errs);
61 
62     return MTestReturnValue(errs);
63 }
64