---
name: "MPI_Spawn"
section: "2"
platform: "linux"
package: "lam"
version: "6.1-11"
release: "Debian 2.1 (Slink)"
platforms: ["linux"]
url: "https://new.carta.tech/MPI_Spawn"
---

# MPI\_Spawn(2)

Spawn MPI processes under LAM.

## NAME

MPI\_Spawn - Spawn MPI processes under LAM.

## C SYNOPSIS

\#include \<mpi.h\>

int MPI\_Spawn (char \*program, char \*argv\[\], int maxprocs, MPI\_Info info, int root, MPI\_Comm parents, MPI\_Comm \*children, int errors\[\]);

## FORTRAN SYNOPSIS

subroutine MPI\_SPAWN (program, argv, maxprocs, info, root, parents, children, ierrors, ierr)

character\*(\*) program, argv(\*)\
 integer info, maxprocs, root, parents, children, ierrors(\*)

## DESCRIPTION

A group of processes can create another group of processes with *MPI\_Spawn()*. The parent group is indicated by the first communicator argument. *MPI\_Spawn()* is a collective operation 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 *MPI\_Spawn()* 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 access the same intercommunicator under the pre-defined name, MPI\_COMM\_PARENT. The remote group size of MPI\_COMM\_PARENT is zero if the process was created by [mpirun(1)](/mpirun/1.md) instead of *MPI\_Spawn()*. Both groups can decide to merge the intercommunicator into an intracommunicator and take advantage of other MPI collective operations. They can then use the merged intracommunicator to create new intercommunicators 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 *MPI\_Spawn()* 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 is the exact number of processes that will be started. If it is not possible to start *maxprocs* processes, *MPI\_Spawn()* returns 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 *MPI\_Spawn() .*

### Command-line Arguments

The *argv* parameter to *MPI\_Spawn* should not contain the program name, as given in the first parameter. The command line passed to the newly launched program will be the program name followed by the strings in *argv*.

## SEE ALSO

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