Blame test/mpi/manual/spawntest_child.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2009 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
/*
Packit 0848f5
 * Test code provided by Guruprasad H. Kora
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <string.h>
Packit 0848f5
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    int my_rank;
Packit 0848f5
    int size;
Packit 0848f5
    MPI_Comm parentcomm;
Packit 0848f5
    MPI_Comm allcomm;
Packit 0848f5
Packit 0848f5
    MPI_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit 0848f5
Packit 0848f5
    MPI_Comm_get_parent(&parentcomm);
Packit 0848f5
Packit 0848f5
    if (parentcomm == MPI_COMM_NULL) {
Packit 0848f5
        fprintf(stdout, "parentcomm is null\n");
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Intercomm_merge(parentcomm, 1, &allcomm);
Packit 0848f5
Packit 0848f5
    /* Without the Free of allcomm, the children *must not exit* until the
Packit 0848f5
     * master calls MPI_Finalize. */
Packit 0848f5
    MPI_Barrier(allcomm);
Packit 0848f5
    /* According to 10.5.4, case 1b in MPI2.2, the children and master are
Packit 0848f5
     * still connected unless MPI_Comm_disconnect is used with allcomm.
Packit 0848f5
     * MPI_Comm_free is not sufficient */
Packit 0848f5
    MPI_Comm_free(&allcomm);
Packit 0848f5
    MPI_Comm_disconnect(&parentcomm);
Packit 0848f5
Packit 0848f5
    fprintf(stdout, "%s:%d\n", __FILE__, __LINE__);
Packit 0848f5
    fflush(stdout);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
Packit 0848f5
    fprintf(stdout, "%d:child exiting.\n", my_rank);
Packit 0848f5
    fflush(stdout);
Packit 0848f5
    return 0;
Packit 0848f5
}