| detectCores {parallel} | R Documentation |
Attempt to detect the number of CPU cores on the current host.
detectCores(all.tests = FALSE, logical = FALSE)
all.tests |
Logical: if true apply all known tests. |
logical |
Logical: if possible, use the number of physical CPUs/cores
(if |
This attempts to detect the number of CPU cores in the current machine.
It has methods to do so for Linux, Darwin (Mac OS X), FreeBSD, Solaris,
Irix and Windows. detectCores(TRUE) could be tried on other
Unix-alike systems.
An integer, NA if the answer is unknown.
Exactly what this represents is OS-dependent: where possible by default it represents physical cores and not logical (e.g. hyperthreaded) CPUs. Unfortunately on Windows only the number of logical CPUs seems to be available on non-server versions of the OS.
Currently logical only makes a difference on Solaris: there
logical = FALSE returns the number of physical CPUs (not cores)
and logical = TRUE returns the number of logical CPUs, which is
the number of cores on AMD/Intel hardware, but the number of available
hardware threads on Sparc hardware (some versions of which do have
multiple cores per CPU, and others have multiple threads per core).
For example, the UltraSparc T2 CPU in the CRAN check server is a
single physical CPU with 8 cores, and each core supports 8 hardware
threads. So detectCores(logical=FALSE) returns 1, and
detectCores(logical=TRUE) returns 64, neither of which is very
useful!
Where virtual machines are in use, one would hope that the result represents the number of CPUs available (or potentially available) to that particular VM.
Simon Urbanek and Brian Ripley
detectCores()