Carry out parallel Monte Carlo simulation on R slaves spawned by using slavedaemon.R script and all executed results are returned back to master.
the random data generating function. See the details section
additional argument list to
the statistic function to be simulated. See the details section
the number of simulation carried on a slave which is counted as one slave job.
the number of looping. See the details section.
if TRUE, the numbers of jobs finished by slaves will be displayed.
if reproducing the same simulation is desirable, set it to the integer vector .mpi.parSim generated in previous simulation.
logical; should the result be simplified to a vector or matrix if possible?
a communicator number
optional arguments to
It is assumed that one simulation is carried out as
rand.gen(n) can return any
values as long as
statistic can take them. Additional arguments can
be passed to
rand.arg as a list. Optional
arguments can also be passed to
statistic by the argument
Each slave job consists of
i.e., each job runs
nsim number of simulation. The returned values
are transported from slaves to master.
The total number of simulation (TNS) is calculated as follows. Let
slave.num be the total number of slaves in a
comm and it is
mpi.comm.size(comm)-1. Then TNS=slave.num*nsim*run and the total
number of slave jobs is slave.num*run, where
run is the number of
looping from master perspective. If run=1, each slave will run one slave
job. If run=2, each slave will run two slaves jobs on average, and so on.
The purpose of using
run has two folds. It allows a tuneup
of slave job size and total number of slave jobs to deal with two
different cluster environments. On a cluster of slaves with equal CPU
run=1 is often enough. But if
nsim is too big, one
run=2 and the slave jog size to be
nsim/2 so that
TNS=slave.num*(nsim/2)*(2*run). This may improve R computation
efficiency slightly. On a cluster of slaves with different CPU power, one
can choose a big value of
run and a small value of
so that master can dispatch more jobs to slaves who run faster than
others. This will keep all slaves busy so that load balancing is
The sequence of slaves who deliver results to master are saved into
.mpi.parSim. It keeps track which part of results done by which slaves.
.mpi.parSim can be used to reproduce the same simulation result if the same
seed is used and the argument
sim.seq is equal to
See the warning section before you use
The returned values depend on values returned by
statistic(rand.gen(n)) and the total number of simulation
statistic returns a single value, then the result is a
vector of length TNS. If
statistic returns a vector (list) of
nrow, then the result is a matrix of dimension
It is assumed that a parallel RNG is used on all slaves. Run
mpi.setup.rngstream on the master to set up a parallel RNG. Though
works without a parallel RNG, the quality of simulation is not guarantied.
mpi.parSim will automatically transfer
statistic to slaves. However, any functions that
statistic reply on but are not on slaves
must be transfered to slaves before using
mpi.bcast.Robj2slave for that purpose. The same is
applied to required packages or C/Fortran codes. You can use either
mpi.bcast.cmd or put
simplify is TRUE, sapply style simplication is applied. Otherwise a list of length
slave.num*run is returned.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.