On Linux systems(*), parallel::detectCores() ignores the logical argument. For example, on my notebook with four physical CPU cores with two "processors" each, I get:
logical | Logical: if possible, use the number of physical CPUs/cores (if FALSE) or logical CPUs (if TRUE). Currently this is honoured only on macOS, Solaris and Windows.
(*) A Linux system is where R.version$os starts with linux, e.g. in R 4.2.2 on my Ubuntu 20.04 system I have R.version$os == "linux-gnu".
So, this begs the question, why doesn't parallel::detectCores() do this? I'm pretty sure this has been discussed somewhere before. The first task is to identify any discussions and rationales for the current implementation.
See also
This is related to Issue #47 (detectThreadsPerCore())
Issue
On Linux systems(*),
parallel::detectCores()
ignores thelogical
argument. For example, on my notebook with four physical CPU cores with two "processors" each, I get:I think the former should really be
4
.FWIW,
help("detectCores", package = "parallel")
acknowledges this:(*) A Linux system is where
R.version$os
starts withlinux
, e.g. in R 4.2.2 on my Ubuntu 20.04 system I haveR.version$os == "linux-gnu"
.Troubleshooting
In both cases,
detectCores()
uses the followingsystem(..., intern = TRUE)
call on Linux:to get the number of cores - logical or not.
If I look at
lscpu
(not installed on all systems), I get:on my machine. That suggests there are 8 logical CPU cores, and 4*1 = 4 physical ones. We can query the raw data for this from
/proc/cpuinfo
as:which explains:
for counting the number of logical CPU cores. However, for the physical ones, I think we should count the unique number of core IDs;
Action
So, this begs the question, why doesn't
parallel::detectCores()
do this? I'm pretty sure this has been discussed somewhere before. The first task is to identify any discussions and rationales for the current implementation.See also
detectThreadsPerCore()
)