MPI_COMM_SPAWN(3)
π MPI_COMM_SPAWN(3) β the Open MPI glow-up π
okay so bestie, welcome to MPI_Comm_spawn from Open MPI β yes the manual page is literally called MPI_COMM_SPAWN(3), we love a consistent queen. this is part 1 of a long one so buckle up, hydrate, and let's get into it β¨
πΈ NAME πΈ
MPI_Comm_spawn β Spawns a number of identical binaries.
likeβ¦ it makes a whole lil squad of the same program appear. iconic behavior fr fr π
β¨ SYNTAX β¨
π C Syntax
#include <mpi.h>
int MPI_Comm_spawn(const char *command, char *argv[], int maxprocs,
MPI_Info info, int root, MPI_Comm comm,
MPI_Comm *intercomm, int array_of_errcodes[])
π Fortran Syntax
USE MPI
! or the older form: INCLUDE 'mpif.h'
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
π Fortran 2008 Syntax
USE mpi_f08
MPI_Comm_spawn(command, argv, maxprocs, info, root, comm, intercomm,
array_of_errcodes, ierror)
CHARACTER(LEN=*), INTENT(IN) :: command, argv(*)
INTEGER, INTENT(IN) :: maxprocs, root
TYPE(MPI_Info), INTENT(IN) :: info
TYPE(MPI_Comm), INTENT(IN) :: comm
TYPE(MPI_Comm), INTENT(OUT) :: intercomm
INTEGER :: array_of_errcodes(*)
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π INPUT PARAMETERS π
commandβ Name of program to be spawned (string, significant only at root). so like, the name of the lil program you're summoning πͺ only the root process's opinion on this actually counts.argvβ Arguments to command (array of strings, significant only at root). the lil argument besties you're passing along π and againβ¦ only root's version of this matters, no cap.maxprocsβ Maximum number of processes to start (integer, significant only at root). the absolute max number of processes we're starting up π« root says it, root means it.infoβ A set of key-value pairs telling the runtime system where and how to start the processes (handle, significant only at root). literally the vibe check for the runtime: where + how to launch these processes π and yepβ¦ root-only energy.rootβ Rank of process in which previous arguments are examined (integer). the rank of the process whose copy of the earlier args actually gets read π everybody else's are justβ¦ there.commβ Intracommunicator containing group of spawning processes (handle). the intracommunicator holding the group of processes doing the spawning π the friend group, basically.
π¦ OUTPUT PARAMETER π¦
intercommβ Intercommunicator between original group and the newly spawned group (handle). the intercommunicator linking the OG group to the freshly spawned group π€ the group chat bridge, if you will.array_of_errcodesβ One code per process (array of integers). one error code for each process β everybody gets their own lil report card πierrorβ Fortran only: Error status (integer). Fortran girlies get an error status integer, periodt π
π DESCRIPTION π
okay so MPI_Comm_spawn literally tries to start maxprocs identical copies of the MPI program you name in command, gets them talking to you, and hands back an intercommunicator. The new lil babies are called children πΌ. They get their own MPI_COMM_WORLD β completely separate from the parents' one, no shared custody bestie.
MPI_Comm_spawn is collective over comm, and it also might not return until MPI_Init has been called over in the children. And same energy the other way: MPI_Init in the children may not return until ALL the parents have called MPI_Comm_spawn. So in that sense, MPI_Comm_spawn on the parent side + MPI_Init on the child side form one collective operation over the union of parent and child processes. Togetherness π
The intercommunicator you get back from MPI_Comm_spawn has the parent processes in the local group and the child processes in the remote group. The ordering of processes in the local and remote groups is the same as the ordering of the group of the comm in the parents and of MPI_COMM_WORLD of the children, respectively. (Yes the original really does say "the same as the as the", we love a typo era π.) And the children can grab that intercommunicator themselves with MPI_Comm_get_parent.
Quick heads up: the MPI standard allows an implementation to use the MPI_UNIVERSE_SIZE attribute of MPI_COMM_WORLD to specify how many processes will be active in a program. Although this implementation of the MPI standard does define MPI_UNIVERSE_SIZE, it does not let you set its value. So if you try to set the value of MPI_UNIVERSE_SIZE? You get an error message. No cap, it will simply refuse π.
πΈ The command Argument πΈ
command is a string holding the name of the program to be spawned. The string is null-terminated in C. In Fortran, leading and trailing spaces get stripped. MPI looks for the file first in the working directory of the spawning process. Priorities, bestie.
π¦ The argv Argument π¦
argv is an array of strings containing the arguments that get passed to the program. The first element of argv is the first argument passed to command β NOT the command itself, unlike what's conventional in some contexts. The argument list is terminated by NULL in C and by an empty string in Fortran (and yes, it is the MPI application's responsibility to make sure the last entry of the argv array is an empty string β the compiler will NOT just auto-insert it for you, she's not your mom π).
In Fortran, leading and trailing spaces are always stripped, so a string made of nothing but spaces counts as an empty string. The constant MPI_ARGV_NULL can be used in C and Fortran to mean "empty argument list". In C, that constant is the same as NULL.
In C, the MPI_Comm_spawn argv differs from main's argv in two ways:
- It's shifted by one element. Specifically,
argv[0]ofmaincontains the name of the program (given bycommand).argv[1]ofmaincorresponds toargv[0]inMPI_Comm_spawn,argv[2]ofmaintoargv[1]ofMPI_Comm_spawn, and so on and so on β¨ argvofMPI_Comm_spawnmust be null-terminated, so its length can be figured out.
Passing an argv of MPI_ARGV_NULL to MPI_Comm_spawn results in main receiving an argc of 1 and an argv whose element 0 is the name of the program.
β¨ The maxprocs Argument β¨
Open MPI tries to spawn maxprocs processes. If it can't spawn maxprocs processes, it raises an error of class MPI_ERR_SPAWN. If MPI can spawn the specified number of processes, MPI_Comm_spawn returns successfully and the number of spawned processes, m, is given by the size of the remote group of intercomm.
A spawn call with the default behavior is called hard. A spawn call for which fewer than maxprocs processes may be returned is called soft.
π The info Argument π
The info argument is an opaque handle of type MPI_Info in C and INTEGER in Fortran. It's basically a container for a bunch of user-specified (key,value) pairs. key and value are strings (null-terminated char * in C, character*(*) in Fortran). Routines to create and manipulate the info argument are described in Section 4.10 of the MPI-2 standard.
For the SPAWN calls, info provides additional, implementation-dependent instructions to MPI and the runtime system on how to start processes. An application may pass MPI_INFO_NULL in C or Fortran. Portable programs that don't need detailed control over process locations should use MPI_INFO_NULL.
The following keys for info are recognized in Open MPI. (The reserved values mentioned in Section 5.3.4 of the MPI-2 standard are not implemented. rip to them πͺ¦)
hostβchar *. Host on which the process should be spawned. See theorte_hostman page for an explanation of how this will be used.hostfileβchar *. Hostfile containing the hosts on which the processes are to be spawned. See theorte_hostfileman page for an explanation of how this will be used.add-hostβchar *. Add the specified host to the list of hosts known to this job and use it for the associated process. This will be used similarly to the-hostoption.add-hostfileβchar *. Hostfile containing hosts to be added to the list of hosts known to this job and use it for the associated process. This will be used similarly to the-hostfileoption.wdirβchar *. Directory where the executable is located. If files are to be pre-positioned, then this location is the desired working directory at time of execution β if not specified, then it will automatically be set toompi_preload_files_dest_dir.ompi_prefixβchar *. Same as the--prefixcommand line argument tompirun.ompi_preload_binaryβbool. If set to true, pre-position the specified executable onto the remote host. A destination directory must also be provided.ompi_preload_filesβchar *. A comma-separated list of files that are to be pre-positioned in addition to the executable. Note that this option does not depend uponompi_preload_binaryβ files can be moved to the target even if an executable is not moved.ompi_stdin_targetβchar *. Comma-delimited list of ranks to receive stdin when forwarded.ompi_non_mpiβbool. If set to true, launching a non-MPI application; the returned communicator will beMPI_COMM_NULL. Failure to set this flag when launching a non-MPI application will cause both the child and parent jobs to "hang". (do not do this bestie, the hang is real π)ompi_paramβchar *. Pass an OMPI MCA parameter to the child job. If that parameter already exists in the environment, the value will be overwritten by the provided value.mapperβchar *. Mapper to be used for this job.map_byβchar *. Mapping directive indicating how processes are to be mapped (slot,node,socket, etc.).rank_byβchar *. Ranking directive indicating how processes are to be ranked (slot,node,socket, etc.).bind_toβchar *. Binding directive indicating how processes are to be bound (core,slot,node,socket, etc.).pathβchar *. List of directories to search for the executable.npernodeβchar *. Number of processes to spawn on each node of the allocation.pernodeβbool. Equivalent tonpernodeof1.pprβchar *. Spawn specified number of processes on each of the identified object type.envβchar *. Newline-delimited list of envars to be passed to the spawned procs.
Okay so bool info keys are actually strings, but they get evaluated like this: if the string value is a number, it's converted to an integer and cast to a boolean (meaning zero integers are false and non-zero values are true). If the string value is (case-insensitive) "yes" or "true", the boolean is true. If the string value is (case-insensitive) "no" or "false", the boolean is false. Every other string value is unrecognized, and therefore false. girlypop the vibes must be exact π
π The root Argument π
All arguments before the root argument are examined only on the process whose rank in comm is equal to root. The value of these arguments on other processes is just ignored. Main character energy β only root gets a say.
π The array_of_errcodes Argument π
array_of_errcodes is an array of length maxprocs in which MPI reports the status of the processes that MPI was requested to start. If all maxprocs processes were spawned, array_of_errcodes is filled in with the value MPI_SUCCESS. If any of the processes are not spawned, array_of_errcodes is filled in with the value MPI_ERR_SPAWN. In C or Fortran, an application may pass MPI_ERRCODES_IGNORE if it's not interested in the error codes.
β NOTES β
Completion of MPI_Comm_spawn in the parent does not necessarily mean that MPI_Init has been called in the children. (although the returned intercommunicator can be used immediately, so like, go off π«Ά)
π¨ Important π¨
ok bestie, real talk, read this first π In Open MPI, this function only works properly when the MPI job is launched viampirun/mpiexec. Using this function in other run-time environments is currently unsupported, and may result in undefined behavior (e.g., the MPI job may hang). Not "oops teehee" undefined behavior β the kind where your job just sits there staring at you forever. π
Almost all MPI routines return an error value; C routines as the return result of the function and Fortran routines in the last argument.
Before the error value is returned, the current MPI error handler associated with the communication object (e.g., communicator, window, file) is called. If no communication object is associated with the MPI call, then the call is considered attached to MPI_COMM_SELF and will call the associated MPI error handler. When MPI_COMM_SELF is not initialized (i.e., before MPI_Init / MPI_Init_thread, after MPI_Finalize, or when using the Sessions Model exclusively) the error raises the initial error handler. The initial error handler can be changed by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when using the World model, or the mpi_initial_errhandler CLI argument to mpiexec or info key to MPI_Comm_spawn / MPI_Comm_spawn_multiple. If no other appropriate error handler has been set, then the MPI_ERRORS_RETURN error handler is called for MPI I/O functions and the MPI_ERRORS_ABORT error handler is called for all other MPI functions.
Open MPI includes three predefined error handlers that can be used:
MPI_ERRORS_ARE_FATALβ Causes the program to abort all connected MPI processes. girl, it's over. πMPI_ERRORS_ABORTβ An error handler that can be invoked on a communicator, window, file, or session. When called on a communicator, it acts as ifMPI_Abortwas called on that communicator. If called on a window or file, acts as ifMPI_Abortwas called on a communicator containing the group of processes in the corresponding window or file. If called on a session, aborts only the local process.MPI_ERRORS_RETURNβ Returns an error code to the application. the chill one, she just hands you the receipt π§Ύ
MPI applications can also implement their own error handlers by calling:
MPI_Comm_create_errhandlerthenMPI_Comm_set_errhandlerMPI_File_create_errhandlerthenMPI_File_set_errhandlerMPI_Session_create_errhandlerthenMPI_Session_set_errhandleror atMPI_Session_initMPI_Win_create_errhandlerthenMPI_Win_set_errhandler
Note that MPI does not guarantee that an MPI program can continue past an error.
See the MPI man page for a full list of MPI error codes.
See the Error Handling section of the MPI-3.1 standard for more information.
π See also π
MPI_Comm_spawn_multipleMPI_Comm_get_parentmpirun(1)
π Copyright π
2003-2026, The Open MPI Community
and that's a wrap on the whole page, bestie!! π this was page MPI_COMM_SPAWN(3) from the Open MPI crew, dated Sep 10, 2026 β go forth, spawn responsibly, and remember: launch it with mpirun / mpiexec or she simply will not behave β¨ slay π
π¦ where this page comes from
- ubuntu stonking: openmpi-doc 5.0.10-6 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms