detectCores(all.tests = FALSE, logical = TRUE)
FALSE
) or logical CPUs (if TRUE
). Currently this
is honoured only on Linux, OS X, Sparc Solaris and Windows.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 OS X there is a further distinction between
#ifdef windows
Only versions of Windows since XP SP3 are supported. Microsoft
documents that logical = FALSE
it will report the number of
cores on Vista or later, but the number of physical CPU packages on XP
or Server 2003: however it reported correctly on the XP systems we
tested.
#endif
On Sparc Solaris logical = FALSE
returns the number of physical
cores and logical = TRUE
returns the number of available
hardware threads. (Some Sparc CPUs which do have multiple cores per
CPU, others have multiple threads per core and some have both.) 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 8, and
detectCores(logical = TRUE)
returns 64.
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.
It has methods to do so for Linux, OS X, FreeBSD, OpenBSD, Solaris,
Irix and Windows. detectCores(TRUE)
could be tried on other
Unix-alike systems.
Prior to R3.3.0 the default was logical = FALSE
except on
Windows, but logical = TRUE
had an effect only on Sparc Solaris
and Windows (where it was the default).
detectCores()
detectCores(logical = FALSE)
Run the code above in your browser using DataLab