Random numbers and the multicore package

When programming in R, I’ve used the multicore package a few times. However, I’ve never seen a statement about how it handles it’s random numbers. When I use openMP with C, I’m careful to use a proper parallel RNG, but with R I’ve assume that something sensible happens. Can anyone confirm that something sensible does happen?

Example

From the documentation, we have

x <- foreach(icount(1000), .combine = "+") %do% rnorm(4)

How are the rnorm`s generated?

Answer

I’m not sure how the foreach works (from the doMC package, I guess), but in multicore if you did something like mclapply the mc.set.seed parameter defaults to TRUE which gives each process a different seed (e.g. mclapply(1:1000, rnorm)). I assume your code is translated into something similar, i.e. it boils down to calls to parallel which has the same convention.

But also see page 16 of the slides by Charlie Geyer, which recommends the rlecuyer package for parallel independent streams with theoretical guarantees. Geyer’s page also has sample code in R for the different setups.

Attribution
Source : Link , Question Author : csgillespie , Answer Author : ars

Leave a Comment