Learn R Programming

future (version 0.11.0)

availableCores: 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.availableCoresMethods", c("system",
  "mc.cores+1", "_R_CHECK_LIMIT_CORES_", "Slurm", "PBS")), 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
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.

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.

Details

The following settings ("methods") for inferring the number of cores are supported:
  • "system"- QuerydetectCores().
  • "mc.cores+1"- If available, returns the value of optionmc.cores+ 1. Note thatmc.coresis defined as the number ofadditionalR processes that can be used in addition to the main R process. This means that withmc.cores=0all calculations should be done in the main R process, i.e. we have exactly one core available for our calculations. Themc.coresoption defaults to environment variableMC_CORES(and is set accordingly when theparallelpackage is loaded). Themc.coresoption is used by for instancemclapply().
  • "PBS"- Query Torque/PBS environment variablePBS_NUM_PPN. Depending on PBS system configuration, thisresourceparameter may or may not default to one. It can be specified when submitting a job as in, for instance,qsub -l nodes=4:ppn=2, which requests four nodes each with two cores.
  • "Slurm"- Query Simple Linux Utility for Resource Management (Slurm) environment variableSLURM_CPUS_PER_TASK. This may or may not be set. It can be set when submitting a job, e.g.sbatch --cpus-per-task=2 hello.shor by adding#SBATCH --cpus-per-task=2} to the `hello.sh` script.For any other value of amethodselement, 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.
internal