|
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 <stdlib.h>
|
|
Packit |
0848f5 |
#include "mpitest.h"
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#define NUM_SPAWNS 4
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int np = NUM_SPAWNS;
|
|
Packit |
0848f5 |
int my_rank, size;
|
|
Packit |
0848f5 |
int errcodes[NUM_SPAWNS];
|
|
Packit |
0848f5 |
MPI_Comm allcomm;
|
|
Packit |
0848f5 |
MPI_Comm intercomm;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Init(&argc, &argv);
|
|
Packit |
0848f5 |
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
|
|
Packit |
0848f5 |
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Comm_spawn((char *) "./spawntest_child", MPI_ARGV_NULL, np,
|
|
Packit |
0848f5 |
MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm, errcodes);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (intercomm == MPI_COMM_NULL) {
|
|
Packit |
0848f5 |
fprintf(stdout, "intercomm is null\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Intercomm_merge(intercomm, 0, &allcomm);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Comm_rank(allcomm, &my_rank);
|
|
Packit |
0848f5 |
MPI_Comm_size(allcomm, &size);
|
|
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(&intercomm);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
fprintf(stdout, "%s:%d: MTestSleep starting; children should exit\n", __FILE__, __LINE__);
|
|
Packit |
0848f5 |
fflush(stdout);
|
|
Packit |
0848f5 |
MTestSleep(30);
|
|
Packit |
0848f5 |
fprintf(stdout,
|
|
Packit |
0848f5 |
"%s:%d: MTestSleep done; all children should have already exited\n",
|
|
Packit |
0848f5 |
__FILE__, __LINE__);
|
|
Packit |
0848f5 |
fflush(stdout);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|