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

Utility functions for relaying stdout and conditions when using mclapply()/parLapply(), ... #51

Open
HenrikBengtsson opened this issue Jun 9, 2019 · 1 comment

Comments

@HenrikBengtsson
Copy link
Collaborator

HenrikBengtsson commented Jun 9, 2019

I'm adding this one to this package, but it probably belongs to a 'parallel.extras' package:

Add some type of utility functions for relaying stdout and conditions when using mclapply(), parLapply(), ... of the 'parallel' package. Not sure what such an API would look like, but it might help us support 'progressr' also in those cases, because current the following will relay nothing from the cluster nodes:

library(progressr)
options(progressr.interval = 0.0, progressr.delay = 0.01)

cl <- parallel::makeCluster(3)
with_progress({
  p <- progressor(10)
  parallel::clusterExport(cl, c("p", "slow_sum"))
  y <- parallel::parLapply(cl, X = 1:10, function(x) {
    p()
    slow_sum(x, stdout=TRUE, message=TRUE)
  })
})
parallel::stopCluster(cl)

Maybe something that will allow us to do:

res <- parallel::parLapply(cl, X = 1:10, function(x) record_output({
  p()
  slow_sum(x, stdout=TRUE, message=TRUE)
}))
y <- value(res)  ## cf. how futures work
@HenrikBengtsson
Copy link
Collaborator Author

HenrikBengtsson commented Jun 9, 2019

Value or values?

EDIT 2020-05-06: value() which is in line with how the future package now calls it.

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