-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Within-target parallelism fails #675
Comments
Read firstOnlookers, please jump straight to #675 (comment). Original postThanks for sharing the code. Unfortunately, I am getting a 404 error for both links. Is the repo private? Also, which The drake_hpc_template_file("slurm_batchtools.tmpl") # Edit by hand.
library(future.batchtools)
future::plan(batchtools_slurm, template = "slurm_batchtools.tmpl")
plan <- drake_plan(
a = mclapply(parallel_substeps_a, my_function, mc.cores = ignore(4))
b = mclapply(parallel_substeps_b, my_function, mc.cores = ignore(4))
)
make(plan, parallelism = "future", jobs = 2) That should use distributed computing among targets and local parallel computing within targets. Above, One last question: is there a reason why you are using |
It has been a while since I looked at #295. I will consider reopening it. |
Ah, yes 🤦♂️ . Not anymore :)
I am using So
I will use that once I have access to a cluster :) |
Yeah, I doubt However, there is a small chance nested futures might allow you to do what you want. |
I think you might have misunderstood me here.
So basically, I want to do the following:
(Sorry if I understood you wrong here and you might have already understood me correctly before.) |
Ah, now I think I understand a little better. The Also, I realized I forgot to answer your question about |
The code for the Lines 187 to 192 in 71ba8bd
And the Lines 89 to 99 in 71ba8bd
|
Hmm. While my function works fine outside of drake, it seems that there are serious clashes when using future within-target parallelism in I even tried using I guess for now I just run it sequentially (takes about 8h so not that much of a problem). However, running in parallel with 20 cores would result in a significant speed up :) To summarize, I've tried the following options:
|
You are right. I am not sure why multicore futures do not like being called library(drake)
future::plan(future::multicore, workers = 4)
plan <- drake_plan(x = furrr::future_map(list(1, 1, 1, 1), Sys.sleep))
make(plan)
#> target x
#> fail x
#> Error: Target `x` failed. Call `diagnose(x)` for details. Error message:
#> Detected an error ('fatal error in wrapper code') by the 'parallel' package while trying to retrieve the value of a MulticoreFuture ('<none>'). This could be because the forked R process that evaluates the future was terminated before it was completed: '{; ...future.f.env <- environment(...future.f); if (!is.null(...future.f.env$`~`)) {; if (is_bad_rlang_tilde(...future.f.env$`~`)) {; ...future.f.env$`~` <- base::`~`; }; ...; .out; }); }' Created on 2019-01-15 by the reprex package (v0.2.1) For now, please try multisession parallelism instead. library(drake)
future::plan(future::multisession, workers = 4)
plan <- drake_plan(x = furrr::future_map(list(1, 1, 1, 1), Sys.sleep))
make(plan)
#> target x
build_times()
#> # A tibble: 1 x 4
#> target elapsed user system
#> <chr> <S4: Duration> <S4: Duration> <S4: Duration>
#> 1 x 1.202s 0.067s 0.005s Created on 2019-01-15 by the reprex package (v0.2.1) |
Oh. Thanks for finding that out!! It works. |
Glad that works for you. Indeed, the multicore part fails even without library(drake)
library(parallel)
plan <- drake_plan(x = mclapply(1:2, sqrt, mc.cores = 2))
plan
#> # A tibble: 1 x 2
#> target command
#> <chr> <chr>
#> 1 x mclapply(1:2, sqrt, mc.cores = 2)
tmp <- mclapply(1:2, sqrt, mc.cores = 2)
make(plan)
#> target x
#> Warning: target x warnings:
#> all scheduled cores encountered errors in user code Created on 2019-01-16 by the reprex package (v0.2.1) |
Explanation: library(drake)
library(parallel)
plan <- drake_plan(x = mclapply(1:2, sqrt, mc.cores = 2))
plan
#> # A tibble: 1 x 2
#> target command
#> <chr> <chr>
#> 1 x mclapply(1:2, sqrt, mc.cores = 2)
tmp <- mclapply(1:2, sqrt, mc.cores = 2)
make(plan, lock_envir = FALSE)
#> target x Created on 2019-01-16 by the reprex package (v0.2.1) library(drake)
future::plan(future::multicore, workers = 4)
plan <- drake_plan(x = furrr::future_map(list(1, 1, 1, 1), Sys.sleep))
make(plan, lock_envir = FALSE)
#> target x``` r
library(drake)
future::plan(future::multicore, workers = 4)
plan <- drake_plan(x = furrr::future_map(list(1, 1, 1, 1), Sys.sleep))
make(plan, lock_envir = FALSE)
#> target x Created on 2019-01-16 by the reprex package (v0.2.1) |
The library(drake)
future::plan(future.callr::callr, workers = 4)
plan <- drake_plan(x = furrr::future_map(list(1, 1, 1, 1), Sys.sleep))
make(plan)
#> target x Created on 2019-01-16 by the reprex package (v0.2.1) |
I do not think this is a problem I can solve. I cannot actually change what |
Always fascinated how deep you dig into such issues. I'm fine with using |
Thanks, @pat-s! Depth is part of the joy of this project. That, and |
A recap: The problem
library(drake)
plan <- drake_plan(x = parallel::mclapply(1:2, identity, mc.cores = 2))
make(plan)
#> target x
#> Warning: target x warnings:
#> all scheduled cores encountered errors in user code Created on 2019-01-28 by the reprex package (v0.2.1) Explanation
> parallel:::mc.set.stream
function ()
{
if (RNGkind()[1L] == "L'Ecuyer-CMRG") {
assign(".Random.seed", get("LEcuyer.seed", envir = RNGenv),
envir = .GlobalEnv)
}
else {
if (exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE))
rm(".Random.seed", envir = .GlobalEnv, inherits = FALSE)
}
}
<bytecode: 0x4709808>
<environment: namespace:parallel> Workarounds
parallel::mclapply(X = 1:4, mc.cores = 4, FUN = function(i) {
set.seed(sum(.Random.seed) + i)
# Do some work...
}) Related |
Update: in 300cea8, I added an informative error message that points to workarounds. library(drake)
library(parallel)
plan <- drake_plan(x = mclapply(1:2, identity, mc.cores = 2))
make(plan)
#> target x
#> Warning: target x warnings:
#>
#> Having problems with parallel::mclapply(), future::future(), or furrr::future_map() in drake? Try one of the workarounds at https://ropenscilabs.github.io/drake-manual/hpc.html#parallel-computing-within-targets or https://github.com/ropensci/drake/issues/675.
#>
#>
#> all scheduled cores encountered errors in user code
library(future)
library(furrr)
plan(multicore)
plan <- drake_plan(x = future_map(1:2, identity))
make(plan)
#> target x
#> fail x
#> Error: Target `x` failed. Call `diagnose(x)` for details. Error message:
#>
#> Having problems with parallel::mclapply(), future::future(), or furrr::future_map() in drake? Try one of the workarounds at https://ropenscilabs.github.io/drake-manual/hpc.html#parallel-computing-within-targets or https://github.com/ropensci/drake/issues/675.
#>
#> Detected an error ('fatal error in wrapper code') by the 'parallel' package while trying to retrieve the value of a MulticoreFuture ('<none>'). This could be because the forked R process that evaluates the future was terminated before it was completed: '{; ...future.f.env <- environment(...future.f); if (!is.null(...future.f.env$`~`)) {; if (is_bad_rlang_tilde(...future.f.env$`~`)) {; ...future.f.env$`~` <- base::`~`; }; ...; .out; }); }' Created on 2019-02-05 by the reprex package (v0.2.1.9000) |
Just wanted to thank you for the very helpful error message. Made debugging this about 100x easier than if I had discovered it otherwise. |
I've read through #295 and related issue but could not find a clear answer to the question whether within-target parallelism is already supported. I saw you added
jobs_preprocess
as an argument tomake()
but I am not sure to what it applies to.Also to not clutter the other issue and have a "clean" one I decided to open a new issue.
I've tried adding a column named
"resources"
listing cpus for specific targets as mentioned here in the manual. Ran the plan withparallelism = "future", jobs = 20
but saw no parallelization going on.Note that in the code I use
furrr::future_pwalk()
andfurrr::future_imap()
to parallelize targets.Here is the drake.R file and here one of the exemplary
future_pmap()
calls.Have a great time at rstudio::conf!
The text was updated successfully, but these errors were encountered: