Learn R Programming

npRmpi (version 0.60-20)

mpi.spawn.Rslaves: Spawn and Close R Slaves

Description

mpi.spawn.Rslaves spawns R slaves to those hosts automatically chosen by MPI or specific hosts assigned by the argument hosts. Those R slaves are running in R BATCH mode with a specific Rscript file. The default Rscript file "slavedaemon.R" provides interactive R slave environments.

mpi.close.Rslaves shuts down R slaves spawned by mpi.spawn.Rslaves.

tailslave.log view (from tail) R slave log files (assuming they are all in one working directory).

Usage

mpi.spawn.Rslaves(Rscript=system.file("slavedaemon.R", package="npRmpi"),
                  nslaves=mpi.universe.size(),
                  root = 0,
                  intercomm = 2,
                  comm = 1,
                  hosts = NULL,
                  needlog = FALSE,
                  mapdrive=TRUE,
                  quiet = FALSE,
                  nonblock=TRUE,
                  sleep=0.1)

mpi.close.Rslaves(dellog = TRUE, comm = 1, force = FALSE) tailslave.log(nlines = 3, comm = 1)

Value

Unless quiet = TRUE, mpi.spawn.Rslaves prints to stdio how many slaves are successfully spawned and where they are running.

mpi.close.Rslaves returns a status code. When options(npRmpi.reuse.slaves=TRUE)

and force=FALSE, this may be a no-op (soft-close) so that spawned daemons can be reused within the same R session.

tailslave.log returns last lines of R slave's log files.

Arguments

Rscript

an R script file used to run R in BATCH mode.

nslaves

number of slaves to be spawned.

root

the rank number of the member who spawns R slaves.

intercomm

an intercommunicator number

comm

a communicator number merged from an intercomm.

hosts

NULL or LAM node numbers to specify where R slaves are to be spawned.

needlog

a logical. If TRUE, R BATCH outputs will be saved in log files. If FALSE, the outputs will send to /dev/null.

mapdrive

a logical. If TRUE and master's working dir is on a network, mapping network drive is attemped on remote nodes under windows platform.

quiet

a logical. If TRUE, do not print anything unless an error occurs.

nonblock

a logical. If TRUE, a nonblock procedure is used on all slaves so that they will consume none or little CPUs while waiting.

sleep

a sleep interval, used when nonblock=TRUE. The smaller sleep is, the more responsive slaves are, the more CPUs consume.

dellog

a logical specifying if R slave's log files are deleted or not.

force

a logical. If TRUE, force a hard shutdown of slave daemons. When options(npRmpi.reuse.slaves=TRUE) and force=FALSE, mpi.close.Rslaves() performs a soft-close (i.e., keeps daemons alive for reuse).

nlines

number of lines to view from tail in R slave's log files.

Author

Hao Yu

Details

The R slaves that mpi.spawn.Rslaves spawns are really running a shell program which can be found in system.file("Rslaves.sh",package="npRmpi") which takes a Rscript file as one of its arguments. Other arguments are used to see if a log file (R output) is needed and how to name it. The master process id and the comm number, along with host names where R slaves are running are used to name these log files.

Once R slaves are successfully spawned, the mergers from an intercomm (default `intercomm = 2') to a comm (default `comm = 1') are automatically done on master and slaves (should be done if the default Rscript is replaced). If additional sets of R slaves are needed, please use `comm = 3', `comm = 4', etc to spawn them. At most a comm number up to 10 can be used. Notice that the default comm number for R slaves (using slavedaemon.R) is always 1 which is saved as .comm.

On some systems (notably macOS+MPICH), repeatedly spawning and tearing down slaves in the same R session can lead to hangs/crashes. To avoid this, npRmpi may reuse an existing slave pool when options(npRmpi.reuse.slaves=TRUE). In this mode, mpi.spawn.Rslaves() becomes idempotent and mpi.close.Rslaves(force=FALSE) performs a soft-close.

To spawn R slaves to specific hosts, please use the argument hosts with a list of those node numbers (an integer vector). Total node numbers along their host names can be found by using mpi.hostinfo. Notice that this is MPI implementation specific.

See Also

mpi.comm.spawn, mpi.hostinfo.

Examples

Run this code
if (FALSE) {
# Not run in checks: spawning/tearing down MPI daemons is environment-dependent
# and can interfere with later examples in the same session.
mpi.spawn.Rslaves(nslaves=2)
tailslave.log()
mpi.remote.exec(rnorm(10))
mpi.close.Rslaves()
}

Run the code above in your browser using DataLab