[Rd] 'parallel' package changes '.Random.seed'
nilsson.henric at gmail.com
Thu Mar 6 11:17:36 CET 2014
I've implemented parallelization in one of my packages using the
'parallel' package -- many thanks for providing it!
In my package I'm importing 'parallel' and so added it to the
DESCRIPTION file's 'Import:' tag and also added a
'importFrom("parallel", ...)' statement in the NAMESPACE file.
Parallelization works nicely, but my package no longer passes any parts
of its (unparallelized) checks that depends on random number generation,
e.g., the simulated data in the check suite are no longer the same as
before parallelization was added. This seems to be due to 'parallel'
changing '.Random.seed' when loading its name space:
> rs1 <- .Random.seed
> rs2 <- .Random.seed
> identical(rs1, rs2)
> rs3 <- .Random.seed
> identical(rs1, rs3)
> rs4 <- .Random.seed
> identical(rs1, rs4)
I've taken a look at the 'parallel' source code, and in a few places a
call to 'runif(1)' is issued. So, what effectively seems to happen when
'parallel' is loaded is
which reproduces the above. But is this really necessary? And more
importantly (at least to me): Can it somehow be avoided?
The current state of affairs is a bit unfortunate, since it implies that
a user just by loading the new parallelized version of my package can no
longer reproduce any subsequent results depending on random number
generation (unless a call to 'set.seed' was issued *after* attaching my
I'd be most grateful for any help that you're able to provide here.
R Under development (unstable) (2014-01-26 r64897)
Platform: x86_64-redhat-linux-gnu (64-bit)
 LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
 LC_TIME=sv_SE.UTF-8 LC_COLLATE=en_US.UTF-8
 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
 LC_PAPER=en_US.UTF-8 LC_NAME=C
 LC_ADDRESS=C LC_TELEPHONE=C
 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
 stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
 compiler_3.1.0 parallel_3.1.0 tools_3.1.0
More information about the R-devel