Skip to content
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

Option mc.preschedule=F from mclapply has no effect on pblapply #72

Open
Alex-Cremers opened this issue Oct 17, 2024 · 0 comments
Open

Comments

@Alex-Cremers
Copy link

Alex-Cremers commented Oct 17, 2024

Because the input is first split into chunks of length cl, the option mc.preschedule=F has no effect (we need to wait for the chunk to finish before sending the next chunk, so workers remain idle until the longest job is done). I don't think it can easily be fixed without introducing some communication with the child processes, but it would be useful to explain this in the documentation. I'm not too familiar with the other parallel functions called by pblapply, but if they have similar options, the same would apply to them.

Minimum reprex where setting prescheduling to FALSE should cut the runtime by almost 2. It works well with mclapply but not pblapply.

library(pbapply)
library(parallel)


random_sleep <- function(x){
  duration <- sample(c(0, 2), 1)
  Sys.sleep(duration)
  return(duration)
}

microbenchmark::microbenchmark(
  mclapply(1:20, random_sleep, mc.cores = 10L, mc.preschedule = T),
  mclapply(1:20, random_sleep, mc.cores = 10L, mc.preschedule = F),
  pblapply(1:20, random_sleep, cl = 10L, mc.preschedule = T),
  pblapply(1:20, random_sleep, cl = 10L, mc.preschedule = F),
  times = 1L
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant