Skip to content

Commit

Permalink
ROBUSTNESS: Add unit test asserting that option future.globals.maxSiz…
Browse files Browse the repository at this point in the history
…e is carried forward in nested parallelization (fix #81)
  • Loading branch information
BHGC Website GHA Workflow Runner committed Dec 13, 2023
1 parent f93c19c commit 8cec43e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: doFuture
Version: 1.0.0-9003
Version: 1.0.0-9004
Title: Use Foreach to Parallelize via the Future Framework
Depends:
foreach (>= 1.5.0),
Expand Down
11 changes: 11 additions & 0 deletions tests/incl/start,load-only.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,15 @@ plyr <- "plyr" #nolint
BiocParallel <- "BiocParallel" #nolint
NMF <- "NMF" #nolint

supportedStrategies <- function(cores = 1L, excl = c("cluster"), ...) {
strategies <- future:::supportedStrategies(...)
strategies <- setdiff(strategies, excl)
if (cores > 1) {
strategies <- setdiff(strategies, c("sequential", "uniprocess"))
}
strategies
}

availCores <- min(2L, future::availableCores())

print(sessionInfo())
46 changes: 46 additions & 0 deletions tests/options,nested.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
source("incl/start.R")

message("*** Options in nested parallelization ...")

options(future.debug = FALSE)
options(future.apply.debug = FALSE)
options(future.globals.maxSize = 1234000)

for (cores in 1:availCores) {
message(sprintf("Testing with %d cores ...", cores))
options(mc.cores = cores)
strategies <- supportedStrategies(cores)

for (strategy1 in strategies) {
for (strategy2 in strategies) {
message(sprintf("- plan('%s') ...", strategy2))
plan(list(outer = tweak(strategy1), inner = strategy2))

v <- foreach(x = 1:2) %dofuture% {
outer <- data.frame(
label = "outer",
idx = x,
pid = Sys.getpid(),
maxSize = getOption("future.globals.maxSize", NA_real_)
)

inner <- foreach(x = 3:4) %dofuture% {
data.frame(
label = "inner",
idx = x,
pid = Sys.getpid(),
maxSize = getOption("future.globals.maxSize", NA_real_))
}
inner <- do.call(rbind, inner)
rbind(outer, inner)
}
v <- do.call(rbind, v)
print(v)
stopifnot(!anyNA(v$maxSize))
} ## for (strategy2 ...)
} ## for (strategy1 ...)
} ## for (cores in ...)

message("*** Options in nested parallelization ... done")

source("incl/end.R")

0 comments on commit 8cec43e

Please sign in to comment.