[R-sig-hpc] Getting/Saving the seed when using sfClusterSetupRNG

Tobias Kley tobias.kley at ruhr-uni-bochum.de
Tue Jan 22 11:33:06 CET 2013


Dear all,

I am doing simulations in several batches and would like to ensure that
(1) the random numbers I use are independent in each batch, and
(2) the whole procedure is reproducible.

Until I was using snowfall I proceeded as follows:

----- Example Code 1 -----

# Do the first thing with random numbers
set.seed(1234)
X1 <- rnorm(3)
seed1 <- get(".Random.seed", .GlobalEnv)

# Now do something else
Y <- runif(3)

# Some otherday go on doing the first thing
assign(".Random.seed", seed1, .GlobalEnv)
X2 <- rnorm(3)

# The above calculations are now identically to doing it in one batch:
set.seed(1234)
X <- rnorm(6)

# That is: X and c(X1,X2) will be identical.
X
c(X1,X2)

----- Ende Example Code 1 -----

I have been trying to find out where the seed that sfClusterSetupRNG and/or
sfClusterSetupRNGstream are using is stored, but failed to find it so far.
The following naive way to transfer my code failed:

----- Example Code 2 -----

library(snowfall)
library(rlecuyer)

sfInit(parallel=TRUE, cpus=2, type="SOCK")
sfClusterSetupRNG(type="RNGstream", seed = 1234)

X1 <- sfClusterCall(rnorm,n=3)

# seed1 <- get(".Random.seed", .GlobalEnv)
# --- This won't work!! ---

Y <- sfClusterCall(rnorm,n=3)

# assign(".Random.seed", seed1, .GlobalEnv)
# --- This won't work!! ---

X2 <- sfClusterCall(rnorm,n=3)

# Or do it in one go
sfClusterSetupRNG(type="RNGstream", seed = 1234)
X <- sfClusterCall(rnorm,n=6)

sfStop()

----- Ende Example Code 2 -----

Can someone tell me how to save the seed when doing parallel calculations
using snowfall?

Thanks in advance and kind regards


Tobias.



More information about the R-sig-hpc mailing list