[Rd] Detecting physical CPUs in detectCores() on Linux platforms
Dirk Eddelbuettel
edd @end|ng |rom deb|@n@org
Tue Aug 8 02:07:37 CEST 2023
On 8 August 2023 at 11:21, Simon Urbanek wrote:
| First, detecting HT vs cores is not necessarily possible in general, Linux may assign core id to each HT depending on circumstances:
|
| $ grep 'cpu cores' /proc/cpuinfo | uniq
| cpu cores : 32
| $ grep 'model name' /proc/cpuinfo | uniq
| model name : Intel(R) Xeon(R) Gold 6142 CPU @ 2.60GHz
|
| and you can look up that Xenon 6142 has 16 cores.
|
| Second, instead of "awk"ward contortions it's easily done in R with something like
|
| d=read.dcf("/proc/cpuinfo")
| sum(as.integer(tapply(
| d[,grep("cpu cores",colnames(d))],
| d[,grep("physical id",colnames(d))], `[`, 1)))
|
| which avoids subprocesses, quoting hell and all such issues...
Love the use of read.dcf("/proc/cpuinfo") !!
On my box a simpler
> d <- read.dcf("/proc/cpuinfo")
> as.integer(unique(d[, grep("cpu cores",colnames(d))]))
[1] 6
>
does the right thing.
Dirk
--
dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org
More information about the R-devel
mailing list