Attempt to detect the number of CPU cores on the current host.
Logical: if true apply all known tests.
Logical: if possible, use the number of physical CPUs/cores
This attempts to detect the number of available CPU cores.
It has methods to do so for Linux, macOS, FreeBSD, OpenBSD, Solaris,
Irix and Windows.
detectCores(TRUE) could be tried on other
NA if the answer is unknown.
Exactly what this represents is OS-dependent: where possible by default it counts logical (e.g., hyperthreaded) CPUs and not physical cores or packages.
Under macOS there is a further distinction between ‘available in the current power management mode’ and ‘could be available this boot’, and this function returns the first.
On Sparc Solaris
logical = FALSE returns the number of physical
logical = TRUE returns the number of available
hardware threads. (Some Sparc CPUs have multiple cores per CPU, others
have multiple threads per core and some have both.) For example, the
UltraSparc T2 CPU in the former CRAN check server was a single
physical CPU with 8 cores, and each core supports 8 hardware threads.
detectCores(logical = FALSE) returns 8, and
detectCores(logical = TRUE) returns 64.
Where virtual machines are in use, one would hope that the result
logical = TRUE represents the number of CPUs available (or
potentially available) to that particular VM.
This is not suitable for use directly for the
mclapply nor specifying the number of cores in
makeCluster. First because it may return
because it does not give the number of allowed cores, and third
because on Sparc Solaris and some Windows boxes it is not reasonable
to try to use all the logical CPUs at once.
Simon Urbanek and Brian Ripley
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.