grapes-dorng-grapes: Reproducible Parallel Foreach Backend

%dorng%R Documentation

Reproducible Parallel Foreach Backend

Description

%dorng% is a foreach operator that provides an alternative operator %dopar%, which enable reproducible foreach loops to be performed.

Usage

obj %dorng% ex

Arguments

obj

a foreach object as returned by a call to foreach.

ex

the R expression to evaluate.

Value

%dorng% returns the result of the foreach loop. See foreach::%dopar%. The whole sequence of RNG seeds is stored in the result object as an attribute. Use attr(res, 'rng') to retrieve it.

Global options

These options are for advanced users that develop 'foreach backends:

  • 'doRNG.rng_change_warning_skip': if set to a single logical FALSE/TRUE, it indicates whether a warning should be thrown if the RNG seed is changed by the registered parallel backend (default=FALSE). Set it to TRUE if you know that running your backend will change the RNG state and want to disable the warning. This option can also be set to a character vector that specifies the name(s) of the backend(s) for which the warning should be skipped.

See Also

foreach, doParallel , registerDoParallel, doMPI

Examples


library(doParallel)
cl <- makeCluster(2)
registerDoParallel(cl)

# standard %dopar% loops are _not_ reproducible
set.seed(1234)
s1 <- foreach(i=1:4) %dopar% { runif(1) }
set.seed(1234)
s2 <- foreach(i=1:4) %dopar% { runif(1) }
identical(s1, s2)

# single %dorng% loops are reproducible
r1 <- foreach(i=1:4, .options.RNG=1234) %dorng% { runif(1) }
r2 <- foreach(i=1:4, .options.RNG=1234) %dorng% { runif(1) }
identical(r1, r2)
# the sequence os RNG seed is stored as an attribute
attr(r1, 'rng')

# stop cluster
stopCluster(cl)

# More examples can be found in demo `doRNG`
## Not run: 
demo('doRNG')

## End(Not run)


doRNG documentation built on Jan. 16, 2023, 5:07 p.m.