availableCores {future}R Documentation

Get number of available cores on current machine

Description

The current/main R session counts as one, meaning the minimum number of cores available is always at least one.

Usage

availableCores(
  constraints = NULL,
  methods = getOption("future.availableCores.methods", c("system", "mc.cores",
    "_R_CHECK_LIMIT_CORES_", "PBS", "SGE", "Slurm", "fallback", "custom")),
  na.rm = TRUE,
  default = c(current = 1L),
  which = c("min", "max", "all")
)

Arguments

constraints

An optional character specifying under what constraints ("purposes") we are requesting the values. For instance, on systems where multicore processing is not supported (i.e. Windows), using constrains = "multicore" will force a single core to be reported.

methods

A character vector specifying how to infer the number of available cores.

na.rm

If TRUE, only non-missing settings are considered/returned.

default

The default number of cores to return if no non-missing settings are available.

which

A character specifying which settings to return. If "min", the minimum value is returned. If "max", the maximum value is returned (be careful!) If "all", all values are returned.

Details

The following settings ("methods") for inferring the number of cores are supported:

For any other value of a methods element, the R option with the same name is queried. If that is not set, the system environment variable is queried. If neither is set, a missing value is returned.

Value

Return a positive (>= 1) integer. If which = "all", then more than one value may be returned. Together with na.rm = FALSE missing values may also be returned.

Advanced usage

It is possible to override the maximum number of cores on the machine as reported by availableCores(methods = "system"). This can be done by first specifying options(future.availableCores.methods = "mc.cores") and then the number of cores to use, e.g. options(mc.cores = 8). Having said this, it is almost always better to do this by explicitly setting the number of workers when specifying the future strategy, e.g. plan(multiprocess, workers = 8).

See Also

To get the number of available workers regardless of machine, see availableWorkers().


[Package future version 1.18.0 Index]