Learn R Programming

pbdMPI (version 0.1-5)

seed for RNG: Seed Functions for Random Number Generators

Description

These functions set/end/reset seeds to all ranks.

Usage

comm.set.seed(seed = rep(12345, 6), diff = FALSE,
                comm = .SPMD.CT$comm)
  comm.end.seed(comm = .SPMD.CT$comm)
  comm.reset.seed(comm = .SPMD.CT$comm)

Arguments

seed
six integers.
diff
if all ranks use the same stream. (default = FALSE)
comm
a communicator number.

Value

  • Several hidden objects are set in the .GlobalEnv, see ``rlecuyer'' package for details.

Details

comm.set.seed set the given seed to all ranks. If diff = FALSE, then all ranks generate one stream and use that stream. Otherwise, all ranks generate COMM.SIZE streams and use the stream according to COMM.RANK + 1.

References

Pierre L'Ecuyer, Simard, R., Chen, E.J., and Kelton, W.D. (2002) An Object-Oriented Random-Number Package with Many Long Streams and Substreams. Operations Research, 50(6), 1073-1075.

Sevcikova, H. and Rossini, T. (2012) rlecuyer: R interface to RNG with multiple streams. R Package, URL http://cran.r-project.org/package=rlecuyer

Programming with Big Data in R Website: http://r-pbd.org/

Examples

Run this code
# Save code in a file "demo.r" and run with 2 processors by
# > mpiexec -np 2 Rscript demo.r

### Initial
library(pbdMPI, quiet = TRUE)
init()

### Examples
comm.set.seed()
comm.print(rnorm(5), all.rank = TRUE)
comm.reset.seed()
comm.print(rnorm(5), all.rank = TRUE)
comm.end.seed()

comm.set.seed(diff = TRUE)
comm.print(rnorm(5), all.rank = TRUE)
comm.end.seed()

### Finish
finalize()

Run the code above in your browser using DataLab