---
name: "MPI_Comm_spawn_multiple"
section: "2"
platform: "linux"
package: "lam2-dev"
version: "6.3.2-3"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/MPI_Comm_spawn"
---

# MPI\_Comm\_spawn\_multiple(2)

Spawn MPI processes under LAM.

Part of [MPI\_Comm\_spawn(2)](/MPI_Comm_spawn/2.md).

## NAME

MPI\_Spawn - Spawn MPI processes under LAM.

## C SYNOPSIS

\#include \<mpi.h\>

int MPI\_Comm\_spawn(char \*command, char \*argv\[\], int maxprocs, MPI\_Info info,  int root, MPI\_Comm comm, MPI\_Comm \*intercomm, int array\_of\_errcodes\[\])

int MPI\_Comm\_spawn\_multiple(int count, char \*array\_of\_commands\[\], char \*\*array\_of\_argv\[\], int array\_of\_maxprocs\[\], MPI\_Info array\_of\_info\[\], int root, MPI\_Comm comm, MPI\_Comm \*intercomm, int array\_of\_errcodes\[\])

## FORTRAN SYNOPSIS

MPI\_COMM\_SPAWN(COMMAND, ARGV, MAXPROCS, INFO, ROOT, COMM, INTERCOMM, ARRAY\_OF\_ERRCODES, IERROR)

CHARACTER\*(\*) COMMAND, ARGV(\*)  INTEGER INFO, MAXPROCS, ROOT, COMM, INTERCOMM, ARRAY\_OF\_ERRCODES(\*), IERROR

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, \*) \
 integer maxprocs, info, root, comm, intercomm, errcodes(\*), ierr

## DESCRIPTION

A group of processes can create another group of processes with *MPI\_Comm\_spawn()* or *MPI\_Comm\_spawn\_multiple()*. These two functions are collective operations over the parent processes.  The child group starts up like any MPI application.  The processes must begin by calling  *MPI\_Init()*, after which the pre-defined communicator,  *MPI\_COMM\_WORLD*, may be used.  This world communicator contains only the child processes.  It is distinct from the  *MPI\_COMM\_WORLD* of the parent processes.

### Communication With Spawned Processes

The natural communication mechanism between two groups is the intercommunicator.  The second communicator argument to both functions returns an intercommunicator whose local group contains the parent processes (same as the first communicator argument) and whose remote group contains child processes.   The child processes can access the same intercommunicator by using the *MPI\_Comm\_get\_parent()* call. The remote group size of the parent communicator is zero if the process was created by  [*mpirun*(1)](/mpirun/1.md) instead of one of the spawn functions.  Both groups can decide to merge the intercommunicator into an intracommunicator (with the *MPI\_Comm\_merge()* function) and take advantage of other MPI collective operations.  They can then use the merged intracommunicator to create new communicators and reach other processes in the MPI application.

### Resource Allocation

LAM tends not to offer MPI features that are not portable in production applications.  The *info* argument to the spawn functions is where non-portable resource specification may be made.  LAM does not interpret this parameter. The portable value  *MPI\_INFO\_NULL* should be given.

LAM schedules the given number of processes onto LAM nodes by starting with node 0 (or the lowest numbered node), and continuing through higher node numbers, placing one process on each node.  If the process count is greater than the node count, the procedure repeats.

### Process Count

The *maxprocs* parameter to  *MPI\_Comm\_spawn()*, and *maxprocs* array argument to  *MPI\_Comm\_spawn\_multiple()* specify the exact number of processes to be started.  If it is not possible to start the desired number of processes, the span routines will return an error code.

Frequently, an application wishes to chooses a process count so as to fill all processors available to a job.  MPI indicates the maximum number of processes recommended for a job in the pre-defined attribute,  *MPI\_UNIVERSE\_SIZE*, which is cached on  *MPI\_COMM\_WORLD*. The typical usage is to subtract the value of  *MPI\_UNIVERSE\_SIZE* from the number of processes currently in the job and spawn the difference.  LAM sets  *MPI\_UNIVERSE\_SIZE* to the number of nodes in the user's LAM session.

### Locating an Executable Program

The executable program file must be located on the node(s) where the process(es) will run.  On any node, the directories specified by the user's PATH environment variable are searched to find the program.

All MPI runtime options selected by  [*mpirun*(1)](/mpirun/1.md) in the initial application launch remain in effect for all child processes created by the spawn functions.

### Command-line Arguments

The *argv* parameter to *MPI\_Comm\_spawn()* should not contain the program name, since it is given in the first parameter.  The same is true for the  *array\_of\_argv* parameter to  *MPI\_Comm\_spawn\_multiple*. The command line that is passed to the newly launched program will be the program name followed by the strings in *argv* or  *array\_of\_argv*.

## SEE ALSO

[mpirun(1)](/mpirun/1.md)
