setRngDoMPI: Setup parallel RNG on a doMPI cluster

Description Usage Arguments See Also Examples

View source: R/rng.R

Description

The setRngDoMPI function initializes the workers of a doMPI cluster to use parallel random number generation. To do this, it uses the "L'Ecuyer-CMRG" RNG support provided by the base and parallel packages. Specifically, the nextRNGStream function is used to assign each worker in the cluster to a different stream of random numbers.

This function follows the outline presented in section 6 of the vignette for the parallel package written by R-Core.

Note that the goal of setRngDoMPI is to insure that the cluster workers each generate different streams of random numbers, not to insure repeatable results. For repeatable results, use the doMPI-specific seed option via the foreach .options.mpi argument. See doMPI-package for more information.

Usage

1
setRngDoMPI(cl, seed=NULL)

Arguments

cl

The doMPI cluster to initialize.

seed

Used to seed the random number generators on the cluster workers if not NULL. Note that the use of seed does not guarantee repeatable results because the tasks are not guaranteed to be repeatably executed by the same cluster workers.

See Also

doMPI-package, startMPIcluster, nextRNGStream, RNG

Examples

1
2
3
4
5
## Not run: 
cl <- startMPIcluster(count=2)
setRngDoMPI(cl, seed=1234)

## End(Not run)

doMPI documentation built on May 2, 2019, 1:10 p.m.