Skip to content

WISH: parallelly::availableCores() instead of parallel::detectCores() #101

Description

(disclaim: I'm the author) To minimize the risk of overusing CPUs on multi-tenant and multi-process machines, but also to work in more environments, please consider changing:

get_cores <-function(num_cores){
if(is.null(num_cores)) {
parallel::detectCores()-1
} else {
min(num_cores, parallel::detectCores()-1)
}
}

to

 get_cores <-function(num_cores){  
   min(c(parallelly::availableCores(omit = 1), num_cores))
 }

This also has the benefit of working on single-core hosts, where detectCores() == 1, e.g. free RStudio Cloud accounts, some k8s/container setups, etc. For more arguments, see https://parallelly.futureverse.org/#availablecores-vs-paralleldetectcores.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions