MPIRUN(1)
MPIRUN(1) β Open MPI, bestie edition π
okay so before we even start: this is the Open MPI page, and if you're here you're probably trying to run something in parallel and you want it to go. Sit down, hydrate, we're doing this together π«Ά
β¨ NAME β¨
orterun, mpirun, mpiexec β run serial and parallel jobs in Open MPI.
oshrun, shmemrun β run serial and parallel jobs in Open SHMEM.
heads up bestie:mpirun,mpiexec, andorterunare all literally synonyms for each other, and so areoshrunandshmemrunin case Open SHMEM is installed. Any of these names does the exact same thing. Same behavior, different name. it's giving interchangeable π
β¨ SYNOPSIS β¨
Single Process Multiple Data (SPMD) Model:
mpirun [ options ] <program> [ <args> ]
Multiple Instruction Multiple Data (MIMD) Model:
mpirun [ global_options ]
[ local_options1 ] <program1> [ <args1> ] :
[ local_options2 ] <program2> [ <args2> ] :
... :
[ local_optionsN ] <programN> [ <argsN> ]
ngl there's a sneaky little rule in both of these: calling mpirun by an absolute path name is the same as passing --prefix with a <dir> equal to wherever mpirun lives, minus its last subdirectory. like, for example:
% /usr/local/bin/mpirun ...
is equivalent to
% mpirun --prefix /usr/local
same thing. no cap. π₯
β¨ QUICK SUMMARY β¨
if you're just here to run an MPI app and you don't wanna read all this (valid, but stay anyway π₯Ί), the command line you probably want is:
% mpirun [ -np X ] [ --hostfile <filename> ] <program>
This runs X copies of <program> in your current run-time environment. And here's the cute part: if you're running under a supported resource manager, Open MPI's mpirun will usually automatically use that resource manager's process starter β as opposed to, say, rsh or ssh, which need a hostfile, or which will just default to running all X copies on the localhost. Scheduling happens (by default) in a round-robin fashion by CPU slot. Rest of this page has the details π
β οΈ also please note:mpirunautomatically binds processes as of the start of the v1.8 series. Three binding patterns get used when there are no further directives: - Bind to core: when the number of processes is<= 2- Bind to socket: when the number of processes is> 2- Bind to none: when oversubscribed
if your application uses threads, you probably wanna make sure you're either not bound at all (specify --bind-to none), or bound to multiple cores using an appropriate binding level or a specific number of processing elements per application process. threads + binding = drama, avoid the drama π§
β¨ DEFINITION OF 'SLOT' β¨
okay so "slot" is a word that shows up everywhere in the rest of this page, so let's define it properly. A slot is an allocation unit for a process. The number of slots on a node tells you how many processes can potentially execute on that node. By default, Open MPI allows one process per slot. periodt.
if Open MPI isn't explicitly told how many slots are available on a node (like, if a hostfile is used and the number of slots isn't specified for a given node), it figures out a maximum number of slots for that node in one of two ways:
- Default behavior By default, Open MPI tries to discover the number of processor cores on the node, and uses that as the number of slots available.
- When
--use-hwthread-cpusis used If--use-hwthread-cpusis specified on thempiruncommand line, then Open MPI tries to discover the number of hardware threads on the node, and uses that as the number of slots available.
this default behavior also kicks in when you specify the -host option with a single host. so like, this command:
mpirun --host node1 ./a.out
launches a number of processes equal to the number of cores on node node1, whereas:
mpirun --host node1 --use-hwthread-cpus ./a.out
launches a number of processes equal to the number of hardware threads on node1. see the difference? π
when Open MPI applications get invoked in an environment managed by a resource manager (like, inside of a SLURM job) and Open MPI was built with appropriate support for that resource manager, then Open MPI gets informed of the number of slots for each node by the resource manager. for example:
mpirun ./a.out
launches one process for every slot (on every node) as dictated by the resource manager job specification. it's giving "the RM said so, so it is so" π
also note that the one-process-per-slot restriction can be overridden in unmanaged environments (e.g., when using hostfiles without a resource manager) if oversubscription is enabled (by default, it is disabled). Most MPI applications and HPC environments do not oversubscribe; for simplicity, the majority of this documentation assumes that oversubscription is not enabled.
πΈ Slots are not hardware resources πΈ
Slots are frequently incorrectly conflated with hardware resources. It is important to realize that slots are an entirely different metric than the number (and type) of hardware resources available. they're not the same thing, bestie, please stop mixing them up π
Here are some examples that may help illustrate the difference:
- More processor cores than slots
Consider a resource manager job environment that tells Open MPI that there is a single node with 20 processor cores and 2 slots available. By default, Open MPI will only let you run up to 2 processes.
Meaning: you run out of slots long before you run out of processor cores.
- More slots than processor cores
Consider a hostfile with a single node listed with a "slots=50" qualification. The node has 20 processor cores. By default, Open MPI will let you run up to 50 processes.
Meaning: you can run many more processes than you have processor cores.
β¨ DEFINITION OF 'PROCESSOR ELEMENT' β¨
By default, Open MPI defines that a "processing element" is a processor core. However, if --use-hwthread-cpus is specified on the mpirun command line, then a "processing element" is a hardware thread. simple as that π
β¨ OPTIONS β¨
mpirun will send the name of the directory where it was invoked on the local node to each of the remote nodes, and attempt to change to that directory. See the "Current Working Directory" section below for further details. (yes bestie, there's a whole section for it, we'll get there π)
<program>β The program executable. This is identified as the first non-recognized argument tompirun.<args>β Pass these run-time arguments to every new process. These must always be the last arguments tompirun. If an app context file is used,<args>will be ignored.-h,--helpβ Display help for this command.-q,--quietβ Suppress informative messages fromorterunduring application execution.-v,--verboseβ Be verbose.-V,--versionβ Print version number. If no other arguments are given, this will also causeorterunto exit.-N <num>β Launchnumprocesses per node on all allocated nodes (synonym fornpernode).-display-map,--display-mapβ Display a table showing the mapped location of each process prior to launch.-display-allocation,--display-allocationβ Display the detected resource allocation.-output-proctable,--output-proctableβ Output the debugger proctable after launch.-dvm,--dvmβ Create a persistent distributed virtual machine (DVM).-max-vm-size,--max-vm-size <size>β Number of processes to run.-novm,--novmβ Execute without creating an allocation-spanning virtual machine (only start daemons on nodes hosting application procs).-hnp,--hnp <arg0>β Specify the URI of the Head Node Process (HNP), or the name of the file (specified asfile:filename) that contains that info.
Use one of the following options to specify which hosts (nodes) of the cluster to run on.
π¨ important lore drop: as of the start of the v1.8 release, mpirun will launch a daemon onto each host in the allocation (as modified by the following options) at the very beginning of execution, regardless of whether or not application processes will eventually be mapped to execute there. This is done to allow collection of hardware topology information from the remote nodes, thus allowing us to map processes against known topology. However, it is a change from the behavior in prior releases where daemons were only launched after mapping was complete, and thus only occurred on nodes where application processes would actually be executing. so like, more daemons now. it's a whole thing π
-H,-host,--host <host1,host2,...,hostN>β List of hosts on which to invoke processes.-hostfile,--hostfile <hostfile>β Provide a hostfile to use.-default-hostfile,--default-hostfile <hostfile>β Provide a default hostfile.-machinefile,--machinefile <machinefile>β Synonym for-hostfile.-cpu-set,--cpu-set <list>β Restrict launched processes to the specified logical cpus on each node (comma-separated list). Note that the binding options will still apply within the specified envelope β e.g., you can elect to bind each process to only one cpu within the specified cpu set.
The following options specify the number of processes to launch. Note that none of the options imply a particular binding policy β e.g., requesting N processes for each socket does not imply that the processes will be bound to the socket. don't assume, bestie π
-c,-n,--n,-np <#>β Run this many copies of the program on the given nodes. This option indicates that the specified file is an executable program and not an application context. If no value is provided for the number of copies to execute (i.e., neither the"-np"nor its synonyms are provided on the command line), Open MPI will automatically execute a copy of the program on each process slot (see below for description of a "process slot"). This feature, however, can only be used in the SPMD model and will return an error (without beginning execution of the application) otherwise.βmap-by ppr:N:<object>β LaunchNtimes the number of objects of the specified type on each node.-npersocket,--npersocket <#persocket>β On each node, launch this many processes times the number of processor sockets on the node. The-npersocketoption also turns on the-bind-to-socketoption. (deprecated in favor of--map-by ppr:n:socket)-npernode,--npernode <#pernode>β On each node, launch this many processes. (deprecated in favor of--map-by ppr:n:node)-pernode,--pernodeβ On each node, launch one process β equivalent to-npernode 1. (deprecated in favor of--map-by ppr:1:node)
To map processes:
--map-by<foo> β map to the specified object, defaulting tosocket. Supported options includeslot,hwthread,core,L1cache,L2cache,L3cache,socket,numa,board,node,sequential,distance, andppr. Any object can include modifiers by adding a:and any combination ofPE=n(bindnprocessing elements to each proc),SPAN(load balance the processes across the allocation),OVERSUBSCRIBE(allow more processes on a node than processing elements), andNOOVERSUBSCRIBE. This includesPPR, where the pattern would be terminated by another colon to separate it from the modifiers. π-bycore,--bycoreβ map processes by core (deprecated in favor of--map-by core). π-byslot,--byslotβ map and rank processes round-robin by slot. β¨-nolocal,--nolocalβ do not run any copies of the launched application on the same node asorterunis running. This option will override listing the localhost with--hostor any other host-specifying mechanism. π«-nooversubscribe,--nooversubscribeβ do not oversubscribe any nodes; error (without starting any processes) if the requested number of processes would cause oversubscription. This option implicitly sets"max_slots"equal to the"slots"value for each node. (Enabled by default). π-oversubscribe,--oversubscribeβ nodes are allowed to be oversubscribed, even on a managed system, and overloading of processing elements. π«Ά-bynode,--bynodeβ launch processes one per node, cycling by node in a round-robin fashion. This spreads processes evenly among nodes and assignsMPI_COMM_WORLDranks in a round-robin,"by node"manner. π-cpu-list,--cpu-list<cpus> β comma-delimited list of processor IDs to which to bind processes [default=NULL]. Processor IDs are interpreted ashwloclogical core IDs. Run thehwloc lstopo(1)command to see a list of available cores and their logical IDs. π§
To order processes' ranks in MPI_COMM_WORLD:
--rank-by<foo> β rank in round-robin fashion according to the specified object, defaults toslot. Supported options includeslot,hwthread,core,L1cache,L2cache,L3cache,socket,numa,board, andnode. π
For process binding:
--bind-to<foo> β bind processes to the specified object, defaults tocore. Supported options includeslot,hwthread,core,l1cache,l2cache,l3cache,socket,numa,board,cpu-list, andnone. π-cpus-per-proc,--cpus-per-proc<#perproc> β bind each process to the specified number of cpus. (deprecated in favor of--map-by <obj>:PE=n). π-cpus-per-rank,--cpus-per-rank<#perrank> β alias for-cpus-per-proc. (deprecated in favor of--map-by <obj>:PE=n). π-bind-to-core,--bind-to-coreβ bind processes to cores (deprecated in favor of--bind-to core). π-bind-to-socket,--bind-to-socketβ bind processes to processor sockets (deprecated in favor of--bind-to socket). π-report-bindings,--report-bindingsβ report any bindings for launched processes. π
For rankfiles:
-rf,--rankfile<rankfile> β provide a rankfile file. π
To manage standard I/O:
-output-filename,--output-filename<filename> β redirect thestdout,stderr, andstddiagof all processes to a process-unique version of the specified filename. Any directories in the filename will automatically be created. Each output file will consist offilename.id, where theidwill be the processes' rank inMPI_COMM_WORLD, left-filled with zero's for correct ordering in listings. A relative path value will be converted to an absolute path based on thecwdwherempirunis executed. Note that this will not work on environments where the file system on compute nodes differs from that wherempirunis executed. ποΈ-stdin,--stdin<rank> β theMPI_COMM_WORLDrank of the process that is to receivestdin. The default is to forwardstdintoMPI_COMM_WORLDrank 0, but this option can be used to forwardstdinto any process. It is also acceptable to specifynone, indicating that no processes are to receivestdin. π€-merge-stderr-to-stdout,--merge-stderr-to-stdoutβ mergestderrtostdoutfor each process. π-tag-output,--tag-outputβ tag each line of output tostdout,stderr, andstddiagwith[jobid, MCW_rank]<stdxxx>indicating the process jobid andMPI_COMM_WORLDrank of the process that generated the output, and the channel which generated it. π·οΈ-timestamp-output,--timestamp-outputβ timestamp each line of output tostdout,stderr, andstddiag. β°-xml,--xmlβ provide all output tostdout,stderr, andstddiagin an xml format. π-xml-file,--xml-file<filename> β provide all output in XML format to the specified file. π-xterm,--xterm<ranks> β display the output from the processes identified by theirMPI_COMM_WORLDranks in separatextermwindows. The ranks are specified as a comma-separated list of ranges, with a-1indicating all. A separate window will be created for each specified process. Note:xtermwill normally terminate the window upon termination of the process running within it. However, by adding a"!"to the end of the list of specified ranks, the proper options will be provided to ensure thatxtermkeeps the window open after the process terminates, thus allowing you to see the process' output. Eachxtermwindow will subsequently need to be manually closed. Note: In some environments,xtermmay require that the executable be in the user's path, or be specified in absolute or relative terms. Thus, it may be necessary to specify a local executable as"./foo"instead of just"foo". Ifxtermfails to find the executable,mpirunwill hang, but still respond correctly to actrl-c. If this happens, please check that the executable is being specified correctly and try again. π₯οΈ
To manage files and runtime environment:
-path,--path<path> β <path> that will be used when attempting to locate the requested executables. This is used prior to using the localPATHsetting. π--prefix<dir> β prefix directory that will be used to set thePATHandLD_LIBRARY_PATHon the remote node before invokingOpen MPIor the target process. See the"Remote Execution"section, below. π¦--noprefixβ disable the automatic--prefixbehavior. π«-s,--preload-binaryβ copy the specified executable(s) to remote machines prior to starting remote processes. The executables will be copied to theOpen MPIsession directory and will be deleted upon completion of the job. π--preload-files<files> β preload the comma separated list of files to the current working directory of the remote machines where processes will be launched prior to starting those processes. π-set-cwd-to-session-dir,--set-cwd-to-session-dirβ set the working directory of the started processes to their session directory. π-wd<dir> β synonym for-wdir. π-wdir<dir> β change to the directory <dir> before the user's program executes. See the"Current Working Directory"section for notes on relative paths. Note: If the-wdiroption appears both on the command line and in an application context, the context will take precedence over the command line. Thus, if the path to the desiredwdiris different on the backend nodes, then it must be specified as an absolute path that is correct for the backend node. π-x<env> β export the specified environment variables to the remote nodes before executing the program. Only one environment variable can be specified per-xoption. Existing environment variables can be specified or new variable names specified with corresponding values. For example:
% mpirun -x DISPLAY -x OFILE=/tmp/out ...
The parser for the -x option is not very sophisticated; it does not even understand quoted values. Users are advised to set variables in the environment, and then use -x to export (not define) them. π
Setting MCA parameters:
-gmca,--gmca<key> <value> β pass global MCA parameters that are applicable to all contexts. <key> is the parameter name; <value> is the parameter value. π-mca,--mca<key> <value> β send arguments to various MCA modules. See the"MCA"section, below. π οΈ-am<arg0> β aggregate MCA parameter set file list. π-tune,--tune<tune_file> β specify a tune file to set arguments for various MCA modules and environment variables. See the"Setting MCA parameters and environment variables from file"section, below. π΅
For debugging:
-debug,--debugβ invoke the user-level debugger indicated by theorte_base_user_debuggerMCA parameter. π--get-stack-tracesβ when paired with the--timeoutoption,mpirunwill obtain and print out stack traces from all launched processes that are still alive when the timeout expires. Note that obtaining stack traces can take a little time and produce a lot of output, especially for large process-count jobs. π§΅-debugger,--debugger<args> β sequence of debuggers to search for when--debugis used (i.e. a synonym fororte_base_user_debuggerMCA parameter). π--timeout<seconds> β the maximum number of seconds thatmpirun(also known asmpiexec,oshrun,orterun, etc.) will run. After this many seconds,mpirunwill abort the launched job and exit with a non-zero exit status. Using--timeoutcan be also useful when combined with the--get-stack-tracesoption. β³-tv,--tvβ launch processes under theTotalViewdebugger. Deprecated backwards compatibility flag. Synonym for--debug. πΊ
There are also other options:
--allow-run-as-rootβ allowmpirunto run when executed by the root user (mpirundefaults to aborting when launched as the root user). Be sure to see theRunning as rootsection, below, for more detail. πβ οΈ--app<appfile> β provide an appfile, ignoring all other command line options. π±-cf,--cartofile<cartofile> β provide a cartography file. πΊοΈ-continuous,--continuousβ job is to run until explicitly terminated. π-disable-recovery,--disable-recoveryβ turn recovery all the way off, like it resets every recovery option back to off. π-do-not-launch,--do-not-launchβ do literally all the prep work to launch the app, then justβ¦ don't launch it. Setup, no show. π-do-not-resolve,--do-not-resolveβ don't even try to resolve interfaces. Leave that alone.-enable-recovery,--enable-recoveryβ allow recovery from a process failure. Default = disabled.-index-argv-by-rank,--index-argv-by-rankβ give each process a uniquely indexedargv[0], using its rank. cute and useful. β¨-leave-session-attached,--leave-session-attachedβ don't detach the OmpiRTE daemons this app is using. This way you actually get the error messages from the daemons and from the underlying environment (like when a daemon fails to launch) printed out. π«Ά-max-restarts,--max-restarts <num>β the max number of times a failed process gets restarted.-ompi-server,--ompi-server <uri or file>β tell it the URI of the Open MPI server (or thempirunthat's acting as the server), the name of the file containing that info (written asfile:filename), or the PID of thempirunbeing used as server (written aspid:#). The Open MPI server is what supports multi-application data exchange through the MPI-2MPI_Publish_nameandMPI_Lookup_namefunctions.-personality,--personality <list>β a comma-separated list of programming model, languages, and containers in play (default="ompi").--ppr <list>β comma-separated list of number of processes on a given resource type [default: none].-report-child-jobs-separately,--report-child-jobs-separatelyβ only give back the exit status of the primary job.-report-events,--report-events <URI>β report events to a tool that's listening at the URI you specify.-report-pid,--report-pid <channel>β print outmpirun's PID during startup. The channel has to be either a-(meaning: send the pid to stdout), a+(meaning: send the pid to stderr), or a filename to write the pid into.-report-uri,--report-uri <channel>β print outmpirun's URI during startup. Same rules: the channel is-for stdout,+for stderr, or a filename to write the URI into.-show-progress,--show-progressβ spit out a lil periodic report on how the launch is going. π-terminate,--terminateβ terminate the DVM.-use-hwthread-cpus,--use-hwthread-cpusβ treat hardware threads as independent CPUs.
Note that if Open MPI isn't given a number of slots (like via the "slots" keyword in a hostfile, or from a resource manager such as SLURM), using this option changes the default calculation of the number of slots on a node. Go look at "DEFINITION OF 'SLOT'", above. β¬οΈ
Also note that using this option changes Open MPI's definition of a "processor element" from a processor core to a hardware thread. See "DEFINITION OF 'PROCESSOR ELEMENT'", above. β¬οΈ
-use-regexp,--use-regexpβ use regular expressions for launch.
π οΈ The Developer Corner π οΈ
The following options are useful for developers; they are not generally useful to most ORTE and/or MPI users:
-d,--debug-develβ enable debugging of the OmpiRTE (the run-time layer in Open MPI). This is not generally useful for most users.--debug-daemonsβ enable debugging of any OmpiRTE daemons used by this application.--debug-daemons-fileβ enable debugging of any OmpiRTE daemons used by this application, storing the output in files.-display-devel-allocation,--display-devel-allocationβ display a detailed list of the allocation this job is using.-display-devel-map,--display-devel-mapβ display a more detailed table showing the mapped location of each process before launch.-display-diffable-map,--display-diffable-mapβ display a diffable process map right before launch.-display-topo,--display-topoβ display the topology as part of the process map right before launch.-launch-agent,--launch-agentβ name of the executable used to start processes on the remote nodes. The default is"orted". You can use this option to test new daemon concepts, or to pass options back to the daemons withoutmpirunitself ever seeing them. For example, specifying a launch agent oforted -mca odls_base_verbose 5lets the developer ask the orted for debugging output without clutter frommpirunitself.--report-state-on-timeoutβ when paired with the--timeoutcommand line option, report the run-time subsystem state of each process when the timeout expires.
There may be other options listed with mpirun --help.
πΈ Environment Variables πΈ
MPIEXEC_TIMEOUTβ a synonym for the--timeoutcommand line option.
π DESCRIPTION π
One single invocation of mpirun starts an MPI application running under Open MPI. If the app is single process multiple data (SPMD), you can just specify the application on the mpirun command line.
If the app is multiple instruction multiple data (MIMD) β meaning it's made up of multiple programs β you can specify the set of programs and arguments in one of two ways: Extended Command Line Arguments, and Application Context.
An application context describes the MIMD program set, including all the arguments, in a separate file. This file basically contains multiple mpirun command lines, minus the command name itself. Being able to specify different options for different instantiations of a program is another reason to use an application context.
Extended command line arguments let you describe the application layout right on the command line, using colons (:) to separate the specification of programs and arguments. Some options get set globally across every program you specify (like --hostfile), while others are specific to just one program (like -np). π«Ά
π Specifying Host Nodes π
Host nodes can be identified on the mpirun command line with the -host option, or in a hostfile.
For example,
mpirun -H aa,aa,bb ./a.outβ launches two processes on node aa and one on bb.
Or, consider the hostfile
% cat myhostfile
aa slots=2
bb slots=2
cc slots=2
Here, we list both the host names (aa, bb, and cc) but also how many slots there are for each.
mpirun -hostfile myhostfile ./a.outβ will launch two processes on each of the three nodes.mpirun -hostfile myhostfile -host aa ./a.outβ will launch two processes, both on node aa.mpirun -hostfile myhostfile -host dd ./a.outβ will find no hosts to run on and abort with an error. That is, the specified host dd is not in the specified hostfile.
When running under resource managers (e.g., SLURM, Torque, etc.), Open MPI will obtain both the hostnames and the number of slots directly from the resource manger. π
π Specifying Number of Processes π
As we just saw, the number of processes to run can be set using the hostfile. But bestie, other mechanisms exist too. β¨
The number of processes launched can be specified as a multiple of the number of nodes or processor sockets available. For example,
mpirun -H aa,bb -npersocket 2 ./a.outβ launches processes 0-3 on node aa and process 4-7 on node bb, where aa and bb are both dual-socket nodes. The-npersocketoption also turns on the-bind-to-socketoption, which is discussed in a later section.mpirun -H aa,bb -npernode 2 ./a.outβ launches processes 0-1 on node aa and processes 2-3 on node bb.mpirun -H aa,bb -npernode 1 ./a.outβ launches one process per host node.mpirun -H aa,bb -pernode ./a.outβ is the same as-npernode 1.
Another alternative is to specify the number of processes with the -np option. Consider now the hostfile
% cat myhostfile
aa slots=4
bb slots=4
cc slots=4
Now,
mpirun -hostfile myhostfile -np 6 ./a.outβ will launch processes 0-3 on node aa and processes 4-5 on node bb. The remaining slots in the hostfile will not be used since the-npoption indicated that only 6 processes should be launched.
πΊοΈ Mapping Processes to Nodes: Using Policies πΊοΈ
The examples above illustrate the default mapping of process processes to nodes. This mapping can also be controlled with various mpirun options that describe mapping policies.
Consider the same hostfile as above, again with -np 6:
node aa node bb node cc
mpirun 0 1 2 3 4 5
mpirun --map-by node 0 3 1 4 2 5
mpirun -nolocal 0 1 2 3 4 5
The --map-by node option will load balance the processes across the available nodes, numbering each process in a round-robin fashion. π
The -nolocal option prevents any processes from being mapped onto the local host (in this case node aa). While mpirun typically consumes few system resources, -nolocal can be helpful for launching very large jobs where mpirun may actually need to use noticeable amounts of memory and/or processing time.
Just as -np can specify fewer processes than there are slots, it can also oversubscribe the slots. For example, with the same hostfile:
mpirun -hostfile myhostfile -np 14 ./a.outβ will launch processes 0-3 on node aa, 4-7 on bb, and 8-11 on cc. It will then add the remaining two processes to whichever nodes it chooses.
One can also specify limits to oversubscription. For example, with the same hostfile:
mpirun -hostfile myhostfile -np 14 -nooversubscribe ./a.outβ will produce an error since-nooversubscribeprevents oversubscription. π«
Limits to oversubscription can also be specified in the hostfile itself:
% cat myhostfile
aa slots=4 max_slots=4
bb max_slots=4
cc slots=4
The max_slots field specifies such a limit. When it does, the slots value defaults to the limit. Now:
mpirun -hostfile myhostfile -np 14 ./a.outβ causes the first 12 processes to be launched as before, but the remaining two processes will be forced onto node cc. The other two nodes are protected by the hostfile against oversubscription by this job.
Using the --nooversubscribe option can be helpful since Open MPI currently does not get "max_slots" values from the resource manager.
Of course, -np can also be used with the -H or -host option. For example,
mpirun -H aa,bb -np 8 ./a.out
okay so this one launches 8 processes β but bestie, you only handed it two hosts (aa and bb) π. So after the first two processes get mapped, one to aa and one to bb, the rest of the processes just oversubscribe the hosts you specified. It's giving sold-out venue, standing room only π«Ά.
And here's a MIMD moment, because we love range:
mpirun -H aa -np 1 hostname : -H bb,cc -np 2 uptime
This launches process 0 running hostname on node aa, and processes 1 and 2 each running uptime on nodes bb and cc, respectively. Versatile, honestly β¨.
πΊοΈ Mapping, Ranking, and Binding: Oh My! π
Open MPI uses a three-phase procedure for assigning process locations and ranks, and it is lowkey a whole personality:
- mapping β assigns a default location to each process
- ranking β assigns an
MPI_COMM_WORLDrank value to each process - binding β constrains each process to run on specific processors
The mapping step assigns a default location to each process based on the mapper being used. Mapping by slot, node, and sequentially results in the assignment of the processes to the node level. In contrast, mapping by object lets the mapper assign the process to an actual object on each node.
Note: the location assigned to the process is independent of where it will be bound β that assignment is used solely as input to the binding algorithm. No cap π§’
The mapping of processes to nodes can be defined not just with general policies but also, if necessary, using arbitrary mappings that a simple policy can't describe. You can use the "sequential mapper," which reads the hostfile line by line, assigning processes to nodes in whatever order the hostfile specifies. Just use the -mca rmaps seq option. For example, using the same hostfile as before:
mpirun -hostfile myhostfile -mca rmaps seq ./a.out
This will launch three processes, one on each of nodes aa, bb, and cc, respectively. The slot counts don't matter here β one process is launched per line, on whatever node is listed on that line. Periodt π
Another way to specify arbitrary mappings is with a rankfile, which gives you detailed control over process binding as well. Rankfiles are discussed below π
The second phase focuses on the ranking of the process within the job's MPI_COMM_WORLD. Open MPI separates this from the mapping procedure to allow more flexibility in the relative placement of MPI processes. This is best illustrated by considering the following two cases where we used the --map-by ppr:2:socket option:
node aa node bb
rank-by core 0 1 ! 2 3 4 5 ! 6 7
rank-by socket 0 2 ! 1 3 4 6 ! 5 7
rank-by socket:span 0 4 ! 1 5 2 6 ! 3 7
Ranking by core and by slot give the identical result β a simple progression of MPI_COMM_WORLD ranks across each node. Ranking by socket does a round-robin ranking within each node until all processes have been assigned an MCW rank, and then progresses to the next node. Adding the span modifier to the ranking directive makes the ranking algorithm treat the entire allocation as a single entity β so the MCW ranks get assigned across all sockets before circling back around to the beginning. It's giving full-circle moment π
The binding phase actually binds each process to a given set of processors. This can improve performance if the operating system is placing processes suboptimally. For example, it might oversubscribe some multi-core processor sockets, leaving other sockets idle; this can lead processes to contend unnecessarily for common resources π. Or, it might spread processes out too widely; this can be suboptimal if application performance is sensitive to interprocess communication costs. Binding can also keep the operating system from migrating processes excessively, regardless of how optimally those processes were placed to begin with. Very demure, very mindful.
The processors to be used for binding can be identified in terms of topological groupings β e.g., binding to an l3cache will bind each process to all processors within the scope of a single L3 cache within their assigned location. So if a process is assigned by the mapper to a certain socket, then a --bind-to l3cache directive will cause the process to be bound to the processors that share a single L3 cache within that socket. Nested logic, we love her π§
Alternatively, processes can be assigned to processors based on their local rank on a node using the --bind-to cpu-list:ordered option with an associated --cpu-list "0,2,5". In this example, the first process on a node will be bound to cpu 0, the second process on the node will be bound to cpu 2, and the third process on the node will be bound to cpu 5. --bind-to will also accept cpulist:ortered as a synonym to cpu-list:ordered. Note that an error will result if more processes are assigned to a node than cpus are provided. Respect the supply, bestie π
To help balance loads, the binding directive uses a round-robin method when binding to levels lower than used in the mapper. For example, consider the case where a job is mapped to the socket level, and then bound to core. Each socket will have multiple cores, so if multiple processes are mapped to a given socket, the binding algorithm will assign each process located to a socket to a unique core in a round-robin manner.
Alternatively, processes mapped by l2cache and then bound to socket will simply be bound to all the processors in the socket where they are located. In this manner, users can exert detailed control over relative MCW rank location and binding. Main character energy, honestly π
Finally, --report-bindings can be used to report bindings.
As an example, consider a node with two processor sockets, each comprised of four cores, and each of those cores contains one hardware thread. We run mpirun with -np 4 --report-bindings and the following additional options:
% mpirun ... --map-by core --bind-to core
[...] ... binding child [...,0] to cpus 0001
[...] ... binding child [...,1] to cpus 0002
[...] ... binding child [...,2] to cpus 0004
[...] ... binding child [...,3] to cpus 0008
% mpirun ... --map-by socket --bind-to socket
[...] ... binding child [...,0] to socket 0 cpus 000f
[...] ... binding child [...,1] to socket 1 cpus 00f0
[...] ... binding child [...,2] to socket 0 cpus 000f
[...] ... binding child [...,3] to socket 1 cpus 00f0
% mpirun ... --map-by slot:PE=2 --bind-to core
[...] ... binding child [...,0] to cpus 0003
[...] ... binding child [...,1] to cpus 000c
[...] ... binding child [...,2] to cpus 0030
[...] ... binding child [...,3] to cpus 00c0
% mpirun ... --bind-to none
Here, --report-bindings shows the binding of each process as a mask. In the first case, the processes bind to successive cores as indicated by the masks 0001, 0002, 0004, and 0008. In the second case, processes bind to all cores on successive sockets as indicated by the masks 000f and 00f0. The processes cycle through the processor sockets in a round-robin fashion as many times as are needed.
In the third case, the masks show us that 2 cores have been bound per process. Specifically, the mapping by slot with the PE=2 qualifier indicated that each slot (i.e., process) should consume two processor elements. Since --use-hwthread-cpus was not specified, Open MPI defined "processor element" as "core", and therefore the --bind-to core caused each process to be bound to both of the cores to which it was mapped.
In the fourth case, binding is turned off and no bindings are reported. Silence, iconic πΈ
Open MPI's support for process binding depends on the underlying operating system. Therefore, certain process binding options may not be available on every system. Check your vibe, check your OS π₯
Process binding can also be set with MCA parameters. Their usage is less convenient than that of mpirun options. On the other hand, MCA parameters can be set not only on the mpirun command line, but alternatively in a system or user mca-params.conf file or as environment variables, as described in the MCA section below. Some examples include:
mpirun option MCA parameter key value
--map-by core rmaps_base_mapping_policy core
--map-by socket rmaps_base_mapping_policy socket
--rank-by core rmaps_base_ranking_policy core
--bind-to core hwloc_base_binding_policy core
--bind-to socket hwloc_base_binding_policy socket
--bind-to none hwloc_base_binding_policy none
π Rankfiles π
Rankfiles are text files that specify detailed information about how individual processes should be mapped to nodes, and to which processor(s) they should be bound. Each line of a rankfile specifies the location of one process (for MPI jobs, the process' "rank" refers to its rank in MPI_COMM_WORLD). The general form of each line in the rankfile is:
rank <N>=<hostname> slot=<slot list>
For example:
$ cat myrankfile
rank 0=aa slot=1:0-2
rank 1=bb slot=0:0,1
rank 2=cc slot=1-2
$ mpirun -H aa,bb,cc,dd -rf myrankfile ./a.out
Means that
- Rank 0 runs on node
aa, bound to logical socket 1, cores 0-2. - Rank 1 runs on node
bb, bound to logical socket 0, cores 0 and 1. - Rank 2 runs on node
cc, bound to logical cores 1 and 2.
Rankfiles can alternatively be used to specify physical processor locations. In this case, the syntax is somewhat different. Sockets are no longer recognized, and the slot number given must be the number of the physical PU, as most OS's do not assign a unique physical identifier to each core in the node. Thus, a proper physical rankfile looks something like the following:
$ cat myphysicalrankfile
rank 0=aa slot=1
rank 1=bb slot=8
rank 2=cc slot=6
This means that
- Rank 0 will run on node
aa, bound to the core that contains physical PU 1 - Rank 1 will run on node
bb, bound to the core that contains physical PU 8 - Rank 2 will run on node
cc, bound to the core that contains physical PU 6
Rankfiles are treated as logical by default, and the MCA parameter rmaps_rank_file_physical must be set to 1 to indicate that the rankfile is to be considered as physical. Don't forget the flag, bestie, or you'll be living a lie π
The hostnames listed above are "absolute," meaning that actual resolveable hostnames are specified. However, hostnames can also be specified as "relative," meaning that they are specified in relation to an externally-specified list of hostnames (e.g., by mpirun's --host argument, a hostfile, or a job scheduler).
The "relative" specification is of the form +n<X>, where X is an integer specifying the *X*th hostname in the set of all available hostnames, indexed from 0. For example:
$ cat myrankfile
rank 0=+n0 slot=1:0-2
rank 1=+n1 slot=0:0,1
rank 2=+n2 slot=1-2
$ mpirun -H aa,bb,cc,dd -rf myrankfile ./a.out
Starting with Open MPI v1.7, every socket/core slot location gets specified as a logical index β no cap, the Open MPI v1.6 series was out here using physical indexes like it was nothing. You can use tools such as HWLOC's lstopo to find the logical indexes of socket and cores. Slay. π
ποΈ Application Context or Executable Program?
Okay so to tell these two forms apart, mpirun looks on the command line for the --app option.
- If it is specified β the file named on the command line is assumed to be an application context.
- If it is not specified β the file is assumed to be an executable program.
That's it, that's the whole vibe check. π¦
π Locating Files
If no relative or absolute path is specified for a file, Open MPI will first look for files by searching the directories specified by the --path option. If there's no --path option set, or if the file just isn't found at the --path location, then Open MPI will search the user's PATH environment variable as defined on the source node(s). Fr fr, it checks both places. π
If a relative directory is specified, it must be relative to the initial working directory determined by the specific starter used. For example, when using the rsh or ssh starters, the initial directory is $HOME by default. Other starters may set the initial directory to the current working directory from the invocation of mpirun.
π Current Working Directory
The -wdir mpirun option (and its synonym, -wd) lets you change to an arbitrary directory before the program is invoked. It can also be used in application context files to specify working directories on specific nodes and/or for specific applications. Iconic, honestly. β¨
If the -wdir option appears both in a context file and on the command line, the context file directory will override the command line value. Context file stays winning. π
If the -wdir option is specified, Open MPI will attempt to change to the specified directory on all of the remote nodes. If this fails, mpirun will abort. π
If the -wdir option is not specified, Open MPI will send the directory name where mpirun was invoked to each of the remote nodes. The remote nodes will try to change to that directory. If they are unable (e.g., if the directory does not exist on that node), then Open MPI will use the default directory determined by the starter.
All directory changing occurs before the user's program is invoked; it does not wait until MPI_INIT is called. So it's giving "get your house in order first" energy. π
π¨οΈ Standard I/O
Open MPI directs UNIX standard input to /dev/null on all processes except the MPI_COMM_WORLD rank 0 process. The MPI_COMM_WORLD rank 0 process inherits standard input from mpirun. π
Note: The node that invokedmpirunneed not be the same as the node where theMPI_COMM_WORLDrank 0 process resides. Open MPI handles the redirection ofmpirun's standard input to the rank 0 process. Bestie it's doing the most so you don't have to. π
Open MPI directs UNIX standard output and error from remote nodes to the node that invoked mpirun and prints it on the standard output/error of mpirun. Local processes inherit the standard output/error of mpirun and transfer to it directly.
Thus it is possible to redirect standard I/O for Open MPI applications by using the typical shell redirection procedure on mpirun.
% mpirun -np 2 my_app < my_input > my_output
Note that in this example only the MPI_COMM_WORLD rank 0 process will receive the stream from my_input on stdin. The stdin on all the other nodes will be tied to /dev/null. However, the stdout from all nodes will be collected into the my_output file. π
π‘ Signal Propagation
When orterun receives a SIGTERM and SIGINT, it will attempt to kill the entire job by sending all processes in the job a SIGTERM, waiting a small number of seconds, then sending all processes in the job a SIGKILL. It's giving "I asked nicely, now I'm not asking." π
SIGUSR1 and SIGUSR2 signals received by orterun are propagated to all processes in the job.
A SIGTSTOP signal to mpirun will cause a SIGSTOP signal to be sent to all of the programs started by mpirun, and likewise a SIGCONT signal to mpirun will cause a SIGCONT sent.
Other signals are not currently propagated by orterun. Not me finding out the hard way π
β οΈ Process Termination / Signal Handling
During the run of an MPI application, if any process dies abnormally (either exiting before invoking MPI_FINALIZE, or dying as the result of a signal), mpirun will print out an error message and kill the rest of the MPI application. Rude but necessary. π₯
User signal handlers should probably avoid trying to cleanup MPI state (Open MPI is currently not async-signal-safe; see MPI_Init_thread(3) for details about MPI_THREAD_MULTIPLE and thread safety). For example, if a segmentation fault occurs in MPI_SEND (perhaps because a bad buffer was passed in) and a user signal handler is invoked, if this user handler attempts to invoke MPI_FINALIZE, Bad Things could happen since Open MPI was already "in" MPI when the error occurred. π
Since mpirun will notice that the process died due to a signal, it is probably not necessary (and safest) for the user to only clean up non-MPI state. So like... touch your own stuff, not MPI's. π«Ά
π± Process Environment
Processes in the MPI application inherit their environment from the Open RTE daemon upon the node on which they are running. The environment is typically inherited from the user's shell. On remote nodes, the exact environment is determined by the boot MCA module used. The rsh launch module, for example, uses either rsh/ssh to launch the Open RTE daemon on remote nodes, and typically executes one or more of the user's shell-setup files before launching the Open RTE daemon. When running dynamically linked applications which require the LD_LIBRARY_PATH environment variable to be set, care must be taken to ensure that it is correctly set when booting Open MPI. β οΈ
See the "Remote Execution" section for more details.
π°οΈ Remote Execution
Open MPI requires that the PATH environment variable be set to find executables on remote nodes (this is typically only necessary in rsh- or ssh-based environments β batch/scheduled environments typically copy the current environment to the execution of remote jobs, so if the current environment has PATH and/or LD_LIBRARY_PATH set properly, the remote nodes will also have it set properly). If Open MPI was compiled with shared library support, it may also be necessary to have the LD_LIBRARY_PATH environment variable set on remote nodes as well (especially to find the shared libraries required to run user MPI applications).
However, it is not always desirable or possible to edit shell startup files to set PATH and/or LD_LIBRARY_PATH. The --prefix option is provided for some simple configurations where this is not possible. π
The --prefix option takes a single argument: the base directory on the remote node where Open MPI is installed. Open MPI will use this directory to set the remote PATH and LD_LIBRARY_PATH before executing any Open MPI or user applications. This allows running Open MPI jobs without having pre-configured the PATH and LD_LIBRARY_PATH on the remote nodes. Chef's kiss. π
Open MPI adds the basename of the current node's "bindir" (the directory where Open MPI's executables are installed) to the prefix and uses that to set the PATH on the remote node. Similarly, Open MPI adds the basename of the current node's "libdir" (the directory where Open MPI's libraries are installed) to the prefix and uses that to set the LD_LIBRARY_PATH on the remote node. For example:
Local bindir: /local/node/directory/bin
Local libdir: /local/node/directory/lib64
If the following command line is used:
% mpirun --prefix /remote/node/directory
Open MPI will add "/remote/node/directory/bin" to the PATH and "/remote/node/directory/lib64" to the LD_LIBRARY_PATH on the remote node before attempting to execute anything.
The --prefix option is not sufficient if the installation paths on the remote node are different than the local node (e.g., if "/lib" is used on the local node, but "/lib64" is used on the remote node), or if the installation paths are something other than a subdirectory under a common prefix. π©
Note: Executingmpirunvia an absolute pathname is equivalent to specifying--prefixwithout the last subdirectory in the absolute pathname tompirun. For example:
% /usr/local/bin/mpirun ...
is equivalent to
% mpirun --prefix /usr/local
π€ Exported Environment Variables
All environment variables that are named in the form OMPI_* will automatically be exported to new processes on the local and remote nodes. Environmental parameters can also be set/forwarded to the new processes using the MCA parameter mca_base_env_list. The -x option to mpirun has been deprecated, but the syntax of the MCA param follows that prior example. While the syntax of the -x option and MCA param allows the definition of new variables, note that the parser for these options are currently not very sophisticated β it does not even understand quoted values. π
Users are advised to set variables in the environment and use the option to export them; not to define them. Iykyk. π
ποΈ Setting MCA Parameters
The -mca switch allows the passing of parameters to various MCA (Modular Component Architecture) modules. MCA modules have direct impact on MPI programs because they allow tunable parameters to be set at run time (such as which BTL communication device driver to use, what parameters to pass to that BTL, etc.). β¨
The -mca switch takes two arguments: <key> and <value>. The <key> argument generally specifies which MCA module will receive the value. For example, the <key> "btl" is used to select which BTL to be used for transporting MPI messages. The <value> argument is the value that is passed. For example:
mpirun -mca btl tcp,self -np 1 foo
Tells Open MPI to use the "tcp" and "self" BTLs, and to run a single copy of "foo" an allocated node.
mpirun -mca btl self -np 1 foo
Tells Open MPI to use the "self" BTL, and to run a single copy of "foo" an allocated node.
The -mca switch can be used multiple times to specify different <key> and/or <value> arguments. If the same <key> is specified more than once, the *<value>*s are concatenated with a comma (",") separating them. π¦
Note that the -mca switch is simply a shortcut for setting environment variables. The same effect may be accomplished by setting corresponding environment variables before running mpirun. The form of the environment variables that Open MPI sets is:
OMPI_MCA_<key>=<value>
Thus, the -mca switch overrides any previously set environment variables. The -mca settings similarly override MCA parameters set in the $OPAL_PREFIX/etc/openmpi-mca-params.conf or $HOME/.openmpi/mca-params.conf file.
Unknown <key> arguments are still set as environment variable β they are not checked (by mpirun) for correctness. Illegal or incorrect <value> arguments may or may not be reported β it depends on the specific MCA module. π
okay so real talk β if you ever need to find the available component types under the MCA architecture, or you're hunting for the available parameters for a specific component, just run the ompi_info command. it's literally the plug. the ompi_info(1) man page has all the detailed tea, so go read that for the full scoop. π
β¨ Setting MCA parameters and environment variables from file β¨
so the -tune command line option (and its synonym -mca mca_base_envar_file_prefix) lets you set mca parameters and environment variables using the syntax described below. this option requires a single file, or a list of files separated by ,, to follow. no cap.
a valid line in that file can contain zero or many -x, -mca, or --mca arguments. the following patterns are supported:
-mca var val-mca var "val"-x var=val-x var
if any argument is duplicated in the file, the last value read will be used. periodt.
also important: MCA parameters and environment variables specified on the command line have higher precedence than variables specified in the file. so command line wins, always. π
π Running as root π
the Open MPI team strongly advises against executing mpirun as the root user. MPI applications should be run as regular (non-root) users. that's the vibe they want.
reflecting this advice, mpirun will refuse to run as root by default. to override this default, you can add the --allow-run-as-root option to the mpirun command line, or you can set the environmental parameters OMPI_ALLOW_RUN_AS_ROOT=1 and OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1. note that it takes setting two environment variables to effect the same behavior as --allow-run-as-root in order to stress the Open MPI team's strong advice against running as the root user. after extended discussions with communities who use containers (where running as the root user is the default), there was a persistent desire to be able to enable root execution of mpirun via an environmental control (vs. the existing --allow-run-as-root command line parameter). the compromise of using two environment variables was reached: it allows root execution via an environmental control, but it conveys the Open MPI team's strong recommendation against this behavior.
bestie, just don't run as root unless you literally have to. they made it annoying on purpose. π
π Exit status π
there is no standard definition for what mpirun should return as an exit status. after considerable discussion, they settled on the following method for assigning the mpirun exit status. quick note: in the following description, the "primary" job is the initial application started by mpirun β all jobs that are spawned by that job are designated "secondary" jobs.
- if all processes in the primary job normally terminate with exit status
0, we return0. - if one or more processes in the primary job normally terminate with non-zero exit status, we return the exit status of the process with the lowest
MPI_COMM_WORLDrank to have a non-zero status. - if all processes in the primary job normally terminate with exit status
0, and one or more processes in a secondary job normally terminate with non-zero exit status, we (a) return the exit status of the process with the lowestMPI_COMM_WORLDrank in the lowestjobidto have a non-zero status, and (b) output a message summarizing the exit status of the primary and all secondary jobs. - if the cmd line option
--report-child-jobs-separatelyis set, we will return -only- the exit status of the primary job. any non-zero exit status in secondary jobs will be reported solely in a summary print statement.
by default, the job will abort when any process terminates with non-zero status. the MCA parameter "orte_abort_on_non_zero_status" can be set to "false" (or "0") to cause OMPI to not abort a job if one or more processes return a non-zero status. in that situation the OMPI records and notes that processes exited with non-zero termination status to report the appropriate exit status of mpirun (per bullet points above). so yeah, it keeps receipts. π
π EXAMPLES π
be sure also to see the examples throughout the sections above. but here are the main ones, bestie:
mpirun -np 4 -mca btl ib,tcp,self prog1
run 4 copies of prog1 using the "ib", "tcp", and "self" BTL's for the transport of MPI messages. slay.
mpirun -np 4 -mca btl tcp,sm,self --mca btl_tcp_if_include eth0 prog1
run 4 copies of prog1 using the "tcp", "sm" and "self" BTLs for the transport of MPI messages, with TCP using only the eth0 interface to communicate. note that other BTLs have similar if_include MCA parameters. iconic.
π RETURN VALUE π
mpirun returns 0 if all processes started by mpirun exit after calling MPI_FINALIZE. a non-zero value is returned if an internal error occurred in mpirun, or one or more processes exited before calling MPI_FINALIZE. if an internal error occurred in mpirun, the corresponding error code is returned. in the event that one or more processes exit before calling MPI_FINALIZE, the return value of the MPI_COMM_WORLD rank of the process that mpirun first notices died before calling MPI_FINALIZE will be returned. note that, in general, this will be the first process that died but is not guaranteed to be so. so don't @ me.
if the --timeout command line option is used and the timeout expires before the job completes (thereby forcing mpirun to kill the job) mpirun will return an exit status equivalent to the value of ETIMEDOUT (which is typically 110 on Linux and OS X systems). yikes, but okay. β°
π SEE ALSO π
and that's the whole page, bestie! this masterpiece is from version 4.1.6, dated Sep 30, 2023, and it's the MPIRUN(1) man page. go forth and run your MPI jobs with main character energy. mwah πβ¨
π¦ where this page comes from
- alpine 3.24: openmpi-doc 4.1.6-r1 Β· custom
- ubuntu noble: openmpi-bin 4.1.6-7ubuntu2
- Copyright (c) 2009-2018 Cisco Systems, Inc. All rights reserved
- Copyright (c) 2008-2009 Sun Microsystems, Inc. All rights reserved
- Copyright (c) 2017-2018 Intel, Inc. All rights reserved
- Copyright (c) 2017 Los Alamos National Security, LLC. All rights
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms