While MPI_COMM_SPAWN is sufficient for most cases, it does not allow the spawning of multiple binaries, or of the same binary with multiple sets of arguments. The following routine spawns multiple binaries or the same binary with multiple sets of arguments, establishing communication with them and placing them in the same MPI_COMM_WORLD.
MPI_COMM_SPAWN_MULTIPLE(count,
array_of_commands, array_of_argv, array_of_maxprocs,
array_of_info, root, comm, intercomm, array_of_errcodes)
MPI_COMM_SPAWN_MULTIPLE(COUNT, ARRAY_OF_COMMANDS, ARRAY_OF_ARGV, ARRAY_OF_MAXPROCS, ARRAY_OF_INFO, ROOT, COMM, INTERCOMM, ARRAY_OF_ERRCODES, IERROR)INTEGER COUNT, ARRAY_OF_INFO(*), ARRAY_OF_MAXPROCS(*), ROOT, COMM, INTERCOMM, ARRAY_OF_ERRCODES(*), IERROR
CHARACTER*(*) ARRAY_OF_COMMANDS(*), ARRAY_OF_ARGV(COUNT, *)
int MPI::Intracomm::Spawn_multiple(int count, const char* array_of_commands[], const char** array_of_argv[], const int array_of_maxprocs[], const MPI::Info array_of_info[], int root, int array_of_errcodes[])
MPI::Intercomm
int MPI::Intracomm::Spawn_multiple(int count, const char* array_of_commands[], const char** array_of_argv[], const int array_of_maxprocs[], const MPI::Info array_of_info[], int root)
MPI::Intercomm
MPI_COMM_SPAWN_MULTIPLE is identical to MPI_COMM_SPAWN except that there are multiple executable specifications. The first argument, count, gives the number of specifications. Each of the next four arguments are simply arrays of the corresponding arguments in MPI_COMM_SPAWN. For the Fortran version of array_of_argv, the element array_of_argv(i,j) is the jth argument to command number i.
In any language, an application may use the constant MPI_ARGVS_NULL (which is likely to be (char ***)0 in C) to specify that no arguments should be passed to any commands. The effect of setting individual elements of array_of_argv to MPI_ARGV_NULL is not defined. To specify arguments for some commands but not others, the commands without arguments should have a corresponding argv whose first element is null ((char *)0 in C and empty string in Fortran).
All of the spawned processes have the same
MPI_COMM_WORLD. Their ranks in MPI_COMM_WORLD
correspond directly to the order in which the commands are
specified in MPI_COMM_SPAWN_MULTIPLE. Assume
that processes are generated by the first command,
by
the second, etc.
The processes
corresponding to the first command have ranks
. The processes in the second command have ranks
. The processes in the third
have ranks
, etc.
The array_of_errcodes argument is 1-dimensional
array of size
,
where
is the
th element of array_of_maxprocs.
Command number
corresponds to the
contiguous
slots in this array from element
to
.
Error codes are treated
as for MPI_COMM_SPAWN.
To run the program ``ocean'' with arguments ``-gridfile'' and ``ocean1.grd'' and the program ``atmos'' with argument ``atmos.grd'' in C:
char *array_of_commands[2] = {"ocean", "atmos"}; char **array_of_argv[2]; char *argv0[] = {"-gridfile", "ocean1.grd", (char *)0}; char *argv1[] = {"atmos.grd", (char *)0}; array_of_argv[0] = argv0; array_of_argv[1] = argv1; MPI_Comm_spawn_multiple(2, array_of_commands, array_of_argv, ...);Here's how you do it in Fortran:
CHARACTER*25 commands(2), array_of_argv(2, 3) commands(1) = ' ocean ' array_of_argv(1, 1) = ' -gridfile ' array_of_argv(1, 2) = ' ocean1.grd' array_of_argv(1, 3) = ' ' commands(2) = ' atmos ' array_of_argv(2, 1) = ' atmos.grd ' array_of_argv(2, 2) = ' ' call MPI_COMM_SPAWN_MULTIPLE(2, commands, array_of_argv, ...)
MPI-Standard for MARMOT