Skip to content

Commit

Permalink
Multicore- and UniprocessFuture assign globals themselves; don't pass…
Browse files Browse the repository at this point in the history
… globals to evalFuture()
  • Loading branch information
HenrikBengtsson committed Jan 2, 2025
1 parent ced06c5 commit 6645fd7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: future
Version: 1.34.0-9107
Version: 1.34.0-9109
Title: Unified Parallel and Distributed Processing in R for Everyone
Imports:
digest,
Expand Down
9 changes: 6 additions & 3 deletions R/Future-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,10 @@ getExpression.Future <- local({
future:::evalFuture(core = .(core), capture = .(capture), context = .(context), split = .(split), immediateConditionClasses = .(immediateConditionClasses), forwardOptions = .(forwardOptions), local = .(local), cleanup = .(cleanup))
})

function(future, expr = future$expr, immediateConditions = FALSE, threads = NA_integer_, cleanup = TRUE, ...) {
function(future, expr = future$expr, immediateConditions = FALSE, threads = NA_integer_, ..., cleanup = TRUE) {
debug <- getOption("future.debug", FALSE)
## mdebug("getExpression() ...")
args <- list(...)

local <- future$local
split <- future$split
Expand Down Expand Up @@ -710,9 +711,11 @@ getExpression.Future <- local({
}

## Create a future core
globals <- args$globals
if (is.null(globals)) globals <- globals(future)
core <- list(
expr = expr,
globals = globals(future),
globals = globals,
packages = pkgs,
seed = future$seed
)
Expand Down Expand Up @@ -770,7 +773,7 @@ getExpression.Future <- local({
width = getOption("width")
)

mc.cores <- list(...)$mc.cores
mc.cores <- args$mc.cores
if (!is.null(mc.cores)) {
forwardOptions$mc.cores <- mc.cores
}
Expand Down
9 changes: 5 additions & 4 deletions R/MulticoreFuture-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ run.MulticoreFuture <- function(future, ...) {

mcparallel <- importParallel("mcparallel")

expr <- getExpression(future)
expr <- getExpression(future, globals = list())
envir <- future$envir
envir <- new.env(parent = envir)

t_start <- Sys.time()

## Assign globals
envir <- new.env(parent = envir)
if (length(future$globals) > 0L) {
envir <- assign_globals(envir, globals = future$globals)
globals <- future$globals
if (length(globals) > 0L) {
envir <- assign_globals(envir, globals = globals)
}

## Get a free worker
Expand Down
2 changes: 1 addition & 1 deletion R/UniprocessFuture-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ run.UniprocessFuture <- function(future, ...) {
## also the one that evaluates/resolves/queries it.
assertOwner(future)

expr <- getExpression(future)
expr <- getExpression(future, globals = list())
envir <- future$envir
envir <- new.env(parent = envir)

Expand Down

0 comments on commit 6645fd7

Please sign in to comment.