I was looking for an alternative to furrr:future_map()
because when this function is run inside another function it copies all objects defined inside that function to each worker regardless of whether those objects are explicitly passed (https://github.com/DavisVaughan/furrr/issues/26).
It looks like parLapply()
does the same thing when using clusterExport()
:
fun <- function(x) {
big_obj <- 1
cl <- parallel::makeCluster(2)
parallel::clusterExport(cl, c("x"), envir = environment())
parallel::parLapply(cl, c(1), function(x) {
x + 1
env <- environment()
parent_env <- parent.env(env)
return(list(this_env = env, parent_env = parent_env))
})
}
res <- fun(1)
names(res[[1]]$parent_env)
#> [1] "cl" "big_obj" "x"
Created on 2020-01-06 by the reprex package (v0.3.0)
How can I keep big_obj
from getting copied to each worker? I am using a Windows machine so forking isn't an option.