12.8.3. Starting Multiple Executables and Establishing Communication

Up: Process Manager Interface Next: Reserved Keys Previous: Starting Processes and Establishing Communication

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)
IN countnumber of commands (positive integer, significant only at root)
IN array_of_commandsprograms to be executed (array of strings, significant only at root)
IN array_of_argvarguments for commands (array of array of strings, significant only at root)
IN array_of_maxprocsmaximum number of processes to start for each command (array of integers, significant only at root)
IN array_of_infoinfo objects telling the runtime system where and how to start processes (array of handles, significant only at root)
IN rootrank of process in which previous arguments are examined (integer)
IN commintra-communicator containing group of spawning processes (handle)
OUT intercomminter-communicator between original group and the newly spawned group (handle)
OUT array_of_errcodesone error code per process (array of integers)
C binding
int MPI_Comm_spawn_multiple(int count, char *array_of_commands[], char **array_of_argv[], const int array_of_maxprocs[], const MPI_Info array_of_info[], int root, MPI_Comm comm, MPI_Comm *intercomm, int array_of_errcodes[])
Fortran 2008 binding
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, INTENT(IN) :: count, array_of_maxprocs(*), root
CHARACTER(LEN=*), INTENT(IN) :: array_of_commands(*), array_of_argv(count, *)
TYPE(MPI_Info), INTENT(IN) :: array_of_info(*)
TYPE(MPI_Comm), INTENT(IN) :: comm
TYPE(MPI_Comm), INTENT(OUT) :: intercomm
INTEGER :: array_of_errcodes(*)
Fortran binding


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 j-th argument to command number i.

This may seem backwards to Fortran programmers who are familiar with Fortran's column-major ordering. However, it is necessary to do it this way to allow MPI_COMM_SPAWN to sort out arguments. Note that the leading dimension of array_of_argv must be the same as count. Also note that Fortran rules for sequence association allow a different value in the first dimension; in this case, the sequence of array elements is interpreted by MPI_COMM_SPAWN_MULTIPLE as if the sequence is stored in an array defined with the first dimension set to count. This Fortran feature allows an implementor to define MPI_ARGVS_NULL (see below) with fixed dimensions, e.g., (1,1), or only with one dimension, e.g., (1). ( End of rationale.)

Advice to users.

The argument count is interpreted by MPI only at the root, as is array_of_argv. Since the leading dimension of array_of_argv is count, a nonpositive value of count at a nonroot node could theoretically cause a runtime bounds check error, even though array_of_argv should be ignored by the subroutine. If this happens, you should explicitly supply a reasonable value of count on the nonroot nodes. ( End of advice to users.)
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). In Fortran at nonroot processes, the count argument must be set to a value that is consistent with the provided array_of_argv although the content of these arguments has no meaning for this operation.

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 m1 MPI processes are generated by the first command, m2 by the second, etc. The MPI processes corresponding to the first command have ranks 0, 1, ..., m1-1 in MPI_COMM_WORLD. The MPI processes in the second command have ranks m1, m1+1, ..., m1+m2-1 in MPI_COMM_WORLD. The MPI processes in the third have ranks m1+m2, m1+m2+1, ..., m1+m2+m3-1 in MPI_COMM_WORLD, etc.

Advice to users.

Calling MPI_COMM_SPAWN multiple times would create many sets of children with different MPI_COMM_WORLDs whereas MPI_COMM_SPAWN_MULTIPLE creates children with a single MPI_COMM_WORLD, so the two methods are not completely equivalent. There are also two performance-related reasons why, if you need to spawn multiple executables, you may want to use MPI_COMM_SPAWN_MULTIPLE instead of calling MPI_COMM_SPAWN several times. First, spawning several things at once may be faster than spawning them sequentially. Second, in some implementations, communication between processes spawned at the same time may be faster than communication between processes spawned separately. ( End of advice to users.)
The array_of_errcodes argument is a 1-dimensional array of size Image file , where ni is the i-th element of array_of_maxprocs. Command number i corresponds to the ni contiguous slots in this array from element Image file to Image file . Error codes are treated the same as with MPI_COMM_SPAWN.

Example Examples of array_of_argv in C and Fortran To run the program ``ocean'' with arguments ``-gridfile'' and ``ocean1.grd'' and the program ``atmos'' with argument ``atmos.grd'' in C:

Image file

Here is how you do it in Fortran:

Image file

Up: Process Manager Interface Next: Reserved Keys Previous: Starting Processes and Establishing Communication

Return to MPI-4.1 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-4.1 of November 2, 2023
HTML Generated on November 19, 2023