snowFT-rand {snowFT} | R Documentation |
Random Number Generation
Description
Initialize independent random number streams to be used in the cluster. It uses the L'Ecuyer's random number generator implemented in the rlecuyer package.
Usage
clusterSetupRNG.FT (cl, type = "RNGstream", streamper="replicate", ...)
clusterSetupRNGstreamRepli (cl, seed=rep(12345,6), n, ...)
Arguments
cl |
Cluster object. |
type |
Type of the RNG. Currently, only |
streamper |
Mode of the inititalization. Value |
... |
Arguments passed to the underlying function (see details bellow). |
seed |
A single integer or a vector of six integer values used as seed for the RNG. |
n |
Number of streams to be created. It should correspond to the number of replicates in the computation. |
Details
clusterSetupRNG.FT
calls one of
the following functions, while passing arguments (cl, ...)
: For
streamper="node"
, the snow function clusterSetupRNGstream
is
called; For
streamper="replicate"
, the function
clusterSetupRNGstreamRepli
is called. In the latter case, the
argument n
has to be given that corresponds to the total number
of streams created for the computation. This mode is used by clusterApplyFT
.
Note that when using the function
performParallel
,
the user does not need to initialize the RNG separately, since it is
accomplished within the function.
clusterSetupRNGstreamRepli
loads the rlecuyer package
and on each node it creates n
streams. The
streams are named by their ordinal number.
Examples
## Not run:
# Generate 50 independent (normally distributed) random numbers
# on 3 nodes using 10 RNG streams
cl <- makeClusterFT(3)
r <- 10
# reproducible results
for (i in 1:3) {
clusterSetupRNG.FT(cl, streamper = "replicate", n = r, seed = 123)
cat("\n")
print(unlist(clusterApplyFT(cl, rep(5,r), rnorm, gentype = "RNGstream")[[1]]))
}
# non-reproducible results (method used in snow)
for (i in 1:3) {
clusterSetupRNG.FT(cl, streamper = "node", seed = 123)
cat("\n")
print(unlist(clusterApplyFT(cl, rep(5,r), rnorm, gentype = "RNGstream")[[1]]))
}
stopClusterFT(cl)
## End(Not run)