[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 08:02:59 CET 2013


Dear Hana,

Thanks a lot for helping. That's interesting. What package versions do you use? 

By executing your (even more) minimal example, I get this:

> library(snow)
> RNGkind("L'Ecuyer-CMRG")
> cl <- makeCluster(parallel::detectCores(), type="MPI")
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.
> .t <- snow::clusterSetupRNG(cl, seed=.Random.seed[2:7])
Loading required package: rlecuyer
Error in .lec.SetPackageSeed(seed) : 
  Seed[0] >= -1002165933, Seed is not set.
> traceback()
4: .Call("r_set_package_seed", as.double(seed), PACKAGE = "rlecuyer")
3: .lec.SetPackageSeed(seed)
2: clusterSetupRNGstream(cl, ...)
1: snow::clusterSetupRNG(cl, seed = .Random.seed[2:7])

Here is the output of sessionInfo()

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  utils     datasets  grDevices methods   base     

other attached packages:
[1] rlecuyer_0.3-3 Rmpi_0.5-9     snow_0.3-10   

loaded via a namespace (and not attached):
[1] compiler_2.15.2 parallel_2.15.2 tools_2.15.2   
> 



Hana Sevcikova writes:

> Marius,
>
> It does not fail for me. I'm doing
>
>> library(snow)
>> RNGkind("L'Ecuyer-CMRG")
>> cl <- makeCluster(parallel::detectCores(), type="MPI")
>     4 slaves are spawned successfully. 0 failed.
>> .t <- snow::clusterSetupRNG(cl, seed=.Random.seed[2:7])
>> stopCluster(cl)
>
> Hana
>
>
> On 1/22/13 4:53 PM, Marius Hofert wrote:
>> 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