-
Notifications
You must be signed in to change notification settings - Fork 6
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
Using doFuture with packages already using foreach #21
Comments
Turns out to be a bug(*) in strucchange. Here's a minimal example in a fresh R session: > library("strucchange")
> bp.nile <- breakpoints(Nile ~ 1, hpc = "foreach")
Error in foreach::foreach(i = 1:(n - h + 1)) %dopar% RSSi(i) :
could not find function "%dopar%"
> traceback()
2: breakpoints.formula(Nile ~ 1, hpc = "foreach")
1: breakpoints(Nile ~ 1, hpc = "foreach") The workaround is to make sure 'foreach' is attached before > library("foreach")
> bp.nile <- breakpoints(Nile ~ 1, hpc = "foreach")
Warning: executing %dopar% sequentially: no parallel backend registered In your case with nested, remote futures, the workaround is to attach foreach in the R session where slopeFinder <- function (x, breaks = 2, range, h = 3, closest_to = 0, hpc = "none") {
if (hpc == "foreach") library("foreach")
...
} DetailsThe RSS.triang <- if(hpc == "none") sapply(1:(n-h+1), RSSi) else foreach::foreach(i = 1:(n-h+1)) %dopar% RSSi(i) rather than |
This is now fixed in the next release of strucchange; Achim said he'll try to submit "to CRAN in the not-so-distant future". In the meanwhile, to the workaround I suggest above. |
I tried your workaround with all different options of placing
When I check |
Ok, so the original error was solved, correct? Try with: temp.break %<-% {
doFuture::registerDoFuture()
slopeFinder(temp[,2], breaks = 6, h=20, hpc = "foreach")
} It's not a beautiful solution, but should do it. |
The original error was solved and your new suggestion works! 👍 |
FYI, I've created a todo on trying to automate |
I am trying to use a package that uses foreach (strucchange). The idea is to let a remote worker take care of the processing.
I asked a similar question a while back in the revolving Future (futureverse/future#184).
First I tested whether everything works as I want on the local machine with 4 cores as follows:
This works as planned with all cores being used.
When I want to send this to a remote machine, I used the following as a plan:
plan(list(tweak(remote, workers = "monster"), multiprocess))
and instead of
<-
I used%<-%
. If I understood it correctly, the %<-% would peel away the first layer (sending it to a remote machine) and then the function that uses foreach can run the code.However, it does not work and when I call the object (temp.break) I get the following error:
The text was updated successfully, but these errors were encountered: