15
$\begingroup$

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?

$\endgroup$
8
$\begingroup$

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.

$\endgroup$
7
$\begingroup$

You might want to look at page 5 of this document and of this document. By default, under R, each core sets is own seed (i seem to recall using high precision time).

NB: if you use foreach() from Revolution-computing under windows then i suspect something sensible will not happen. Windows is not POSIX compliant, and this should pose problems when each core needs a different high prec. starting time to set it's seed (unfortunately i don't have windows handy so i can't check this empirically).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.