Blame test/mpi/errors/comm/too_many_comms3.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2012 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
/* This test attempts to create a large number of communicators, in an effort
Packit 0848f5
 * to exceed the number of communicators that the MPI implementation can
Packit 0848f5
 * provide.  It checks that the implementation detects this error correctly
Packit 0848f5
 * handles it.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
/* In this version, we create communicators that contain ranks {0}, {0}, ...,
Packit 0848f5
 * {P} from MPI_COMM_WORLD until we run out of context IDs.  This test
Packit 0848f5
 * fragments the context ID space, resulting in a context ID allocation that
Packit 0848f5
 * fails because there is no common free ID, even though all processes have
Packit 0848f5
 * unused context IDs. */
Packit 0848f5
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include <mpi.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
Packit 0848f5
#define MAX_NCOMM 100000
Packit 0848f5
Packit 0848f5
static const int verbose = 0;
Packit 0848f5
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    int rank, nproc, mpi_errno;
Packit 0848f5
    int i, ncomm, *ranks;
Packit 0848f5
    int errors = 1;
Packit 0848f5
    MPI_Comm *comm_hdls;
Packit 0848f5
    MPI_Group world_group;
Packit 0848f5
Packit 0848f5
    MPI_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
Packit 0848f5
    MPI_Comm_group(MPI_COMM_WORLD, &world_group);
Packit 0848f5
Packit 0848f5
    MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
Packit 0848f5
    comm_hdls = malloc(sizeof(MPI_Comm) * MAX_NCOMM);
Packit 0848f5
    ranks = malloc(sizeof(int) * nproc);
Packit 0848f5
Packit 0848f5
    ncomm = 0;
Packit 0848f5
    for (i = 0; i < MAX_NCOMM; i++) {
Packit 0848f5
        int incl = i % nproc;
Packit 0848f5
        MPI_Group comm_group;
Packit 0848f5
Packit 0848f5
        /* Comms include ranks: 0; 1; 2; ...; 0; 1; ... */
Packit 0848f5
        MPI_Group_incl(world_group, 1, &incl, &comm_group);
Packit 0848f5
Packit 0848f5
        /* Note: the comms we create all contain one rank from MPI_COMM_WORLD */
Packit 0848f5
        mpi_errno = MPI_Comm_create(MPI_COMM_WORLD, comm_group, &comm_hdls[i]);
Packit 0848f5
Packit 0848f5
        if (mpi_errno == MPI_SUCCESS) {
Packit 0848f5
            if (verbose)
Packit 0848f5
                printf("%d: Created comm %d\n", rank, i);
Packit 0848f5
            ncomm++;
Packit 0848f5
        }
Packit 0848f5
        else {
Packit 0848f5
            if (verbose)
Packit 0848f5
                printf("%d: Error creating comm %d\n", rank, i);
Packit 0848f5
            MPI_Group_free(&comm_group);
Packit 0848f5
            errors = 0;
Packit 0848f5
            break;
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        MPI_Group_free(&comm_group);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    for (i = 0; i < ncomm; i++)
Packit 0848f5
        MPI_Comm_free(&comm_hdls[i]);
Packit 0848f5
Packit 0848f5
    free(comm_hdls);
Packit 0848f5
    free(ranks);
Packit 0848f5
    MPI_Group_free(&world_group);
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errors);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
Packit 0848f5
    return 0;
Packit 0848f5
}