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

Please undo any changes you do to future::plan() #7

Closed
HenrikBengtsson opened this issue Dec 15, 2023 · 2 comments
Closed

Please undo any changes you do to future::plan() #7

HenrikBengtsson opened this issue Dec 15, 2023 · 2 comments

Comments

@HenrikBengtsson
Copy link

Congrats to the CRAN release.

Author of Futurverse here. I've got some comments on the parallelization code in:

if (is.null(ncores)) {ncores <- max(1, parallel::detectCores() - 1)}
if (ncores > 1) {
message(paste0("Setting up parallel computation using ", ncores, " cores... \n" ))
if (.Platform$OS.type == "windows" | parallelly::supportsMulticore() == FALSE) {
future::plan(future::multisession, workers=ncores)} else {
future::plan(future::multicore, workers=ncores)}

Please undo any changes you do to future::plan(). If not, you might break other code that the user runs. This is explained in Section 'For package developers' of ?future::plan. That section also shows how to undo settings. This one is important.

Also, for reasons that I bring up in https://www.jottr.org/2022/12/05/avoid-detectcores/,

  1. please don't use parallel::detectCores(), and
  2. please don't default to using all cores, or almost all cores. It's also a big no-no on CRAN.

Even if I cannot convince you to agree with me on the above, maybe you could replace:

if (is.null(ncores)) {ncores <- max(1, parallel::detectCores() - 1)} 

with

if (is.null(ncores)) {ncores <- parallelly::availableCores(omit = 1)}

It'll give sysadms a chance to control the number of default CPU cores.

@HenrikBengtsson
Copy link
Author

Forgot to mention that in:

if (.Platform$OS.type == "windows" | parallelly::supportsMulticore() == FALSE) {

you want to use || rather than |. You can also use ! parallelly::supportsMulticore(), which is more common.

@wangziyue57
Copy link
Owner

Thanks a lot for the suggestion! We're working on updating the package and will incorporate this in the newer version.

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

2 participants