Closed HenrikBengtsson closed 8 years ago
Running the second example under my Slurm setup produces similar output, same pid for everything:
> outer
[[1]]
[[1]]$outer.available
Slurm
4
[[1]]$outer.all
system Slurm
48 4
[[1]]$outer.pid
[1] 21863
[[1]]$inner1
[[1]]$inner1$available
Slurm
4
[[1]]$inner1$all
system Slurm
48 4
[[1]]$inner1$pid
[1] 21863
[[1]]$inner2
[[1]]$inner2$available
Slurm
4
[[1]]$inner2$all
system Slurm
48 4
[[1]]$inner2$pid
[1] 21863
>
Below seems to be a reproducible example that doesn't involved future.BatchJobs:
library("doFuture")
registerDoFuture()
plan(list(
tweak(multisession, workers = 2L),
tweak(multisession, workers = 3L)
))
outer <- foreach(ii = 1L) %dopar% {
info <- list(
available = availableCores(),
all = availableCores(which="all"),
pid = Sys.getpid()
)
inner <- foreach(jj = 1:2) %dopar% {
Sys.sleep(2)
list(
available = availableCores(),
all = availableCores(which="all"),
pid = Sys.getpid()
)
}
c(outer=info, inner=inner)
}
with output:
> str(outer)
List of 1
$ :List of 5
..$ outer.available: Named int 1
.. ..- attr(*, "names")= chr "mc.cores+1"
..$ outer.all : Named int [1:3] 4 1 1
.. ..- attr(*, "names")= chr [1:3] "system" "mc.cores+1" "_R_CHECK_LIMIT_CORES_"
..$ outer.pid : int 7805
..$ inner1 :List of 3
.. ..$ available: Named int 1
.. .. ..- attr(*, "names")= chr "mc.cores+1"
.. ..$ all : Named int [1:3] 4 1 1
.. .. ..- attr(*, "names")= chr [1:3] "system" "mc.cores+1" "_R_CHECK_LIMIT_CORES_"
.. ..$ pid : int 7805
..$ inner2 :List of 3
.. ..$ available: Named int 1
.. .. ..- attr(*, "names")= chr "mc.cores+1"
.. ..$ all : Named int [1:3] 4 1 1
.. .. ..- attr(*, "names")= chr [1:3] "system" "mc.cores+1" "_R_CHECK_LIMIT_CORES_"
.. ..$ pid : int 7805
> Sys.getpid()
[1] 7775
Ah... I realized why; one needs to get the foreach package to use futures also in the nested calls, i.e. specify registerDoFuture()
recursively. This should be done internally by doFuture, but a workaround until that is in place is to do it manually as in:
library("doFuture")
registerDoFuture()
plan(list(
tweak(multisession, workers = 2L),
tweak(multisession, workers = 3L)
))
outer <- foreach(ii = 1L) %dopar% {
registerDoFuture() ## FIX
info <- list(
available = availableCores(),
all = availableCores(which="all"),
pid = Sys.getpid()
)
inner <- foreach(jj = 1:2) %dopar% {
Sys.sleep(2)
list(
available = availableCores(),
all = availableCores(which="all"),
pid = Sys.getpid()
)
}
c(outer=info, inner=inner)
}
which outputs
> str(outer)
List of 1
$ :List of 5
..$ outer.available: Named int 1
.. ..- attr(*, "names")= chr "mc.cores+1"
..$ outer.all : Named int [1:3] 4 1 1
.. ..- attr(*, "names")= chr [1:3] "system" "mc.cores+1" "_R_CHECK_LIMIT_CORES_"
..$ outer.pid : int 23346
..$ inner1 :List of 3
.. ..$ available: Named int 1
.. .. ..- attr(*, "names")= chr "mc.cores+1"
.. ..$ all : Named int [1:3] 4 1 1
.. .. ..- attr(*, "names")= chr [1:3] "system" "mc.cores+1" "_R_CHECK_LIMIT_CORES_"
.. ..$ pid : int 23370
..$ inner2 :List of 3
.. ..$ available: Named int 1
.. .. ..- attr(*, "names")= chr "mc.cores+1"
.. ..$ all : Named int [1:3] 4 1 1
.. .. ..- attr(*, "names")= chr [1:3] "system" "mc.cores+1" "_R_CHECK_LIMIT_CORES_"
.. ..$ pid : int 23379
Solved in the develop branch;
source('http://callr.org/install#HenrikBengtsson/doFuture@develop')
Thanks for the fix, I will definitely try it! When are you planning to merge it to master?
My branch model follows the git flow ideas, so for me master == latest (CRAN) release.
In order for next doFuture to be submitted to CRAN, future (>= 1.1.0) had to reach CRAN first, which happen a week ago, so doFuture can now be submitted. However, would mind taking the develop branch for a serious ride on your end before submitting?
doFuture 0.3.0 is now on CRAN.
Sorry I wasn't able to test the development branch, I am testing the new release now.
Hmm... there might be a bug in doFuture preventing it from properly nesting future strategies. I'm not sure, it needs to be investigated further, but below is what I get when testing on a TORQUE / PBS cluster.
This was first reported by @alexvorobiev in Issue https://github.com/HenrikBengtsson/future/issues/95.
Nested futures work as expected
outputs
Nested futures using foreach (not correct)
Session info