
MPI_Comm_spawn
By: a guest on
Jun 16th, 2012 | syntax:
C | size: 1.10 KB | hits: 51 | expires: Never
//Roland Schulz roland at utk dot edu
#include <stdio.h>
#include <mpi.h>
#include <unistd.h>
int main(int argc, char** argv)
{
MPI_Init(&argc, &argv);
MPI_Comm parent;
MPI_Comm_get_parent(&parent);
if (parent==MPI_COMM_NULL) /*this is the parent*/
{
MPI_Comm children;
MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 2, MPI_INFO_NULL, 0, MPI_COMM_WORLD,
&children, MPI_ERRCODES_IGNORE);
printf("Parent done spawning\n");
MPI_Comm_disconnect(&children);
MPI_Finalize();
printf("Parent finalized\n");
//sleep(2);
}
else
{
MPI_Comm_disconnect(&parent);
int rank,size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf("Hi from %d of %d\n", rank, size);
sleep(1);
MPI_Finalize();
printf("Child finalized\n");
}
return 0;
}