[R] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?
Marius Hofert
marius.hofert at math.ethz.ch
Wed Jan 23 01:53:26 CET 2013
Dear expeRts,
I struggle with the following problem using snow clusters for parallel computing: I would like to specify l'Ecuyer's random number generator. Base R creates a .Random.seed of length 7, the first value indicating the kind fo random number generator. I would thus like to use the components 2 to 7 as the seed for l'Ecuyer's random number generator.
By doing so, I receive (see the minimal example below):
,----
| > Loading required package: Rmpi
| Loading required package: grDevices
| Loading required package: grDevices
| Loading required package: grDevices
| Loading required package: grDevices
| 4 slaves are spawned successfully. 0 failed.
| Loading required package: rlecuyer
| Error in .lec.SetPackageSeed(seed) (from #11) :
| Seed[0] >= -930997252, Seed is not set.
`----
What's the problem? How can I construct a valid seed for l'Ecuyer's rng with
just the information in .Random.seed?
Thanks & Cheers,
Marius
Here is the minimal example:
require(doSNOW)
require(foreach)
doForeach <- function(n, seed=1, type="MPI")
{
## create cluster object
cl <- snow::makeCluster(parallel::detectCores(), type=type)
on.exit(snow::stopCluster(cl)) ## shut down cluster and terminate execution environment
registerDoSNOW(cl) ## register the cluster object with foreach
## seed
if(seed=="L'Ecuyer-CMRG") {
if(!exists(".Random.seed")) stop(".Random.seed does not exist - in l'Ecuyer setting")
.t <- snow::clusterSetupRNG(cl, seed=.Random.seed[2:7]) # => fails!
}
## actual work
foreach(i=seq_len(n)) %dopar% {
runif(1)
}
}
## "standard" (base) way of specifying l'Ecuyer
RNGkind("L'Ecuyer-CMRG") # => .Random.seed is of length 7
res <- doForeach(10, seed="L'Ecuyer-CMRG")
More information about the R-help
mailing list