Search code examples
rparallel-processinghyperthreading

Check if hyperthreading is enabled from within R


Is there a way to check if hyperthreading is enabled from within R?

The best I can think of now is to run the following system call, but this requires root privileges, and has to be parsed.

system("dmidecode -t processor | grep HTT")

Solution

  • Following up on F. Privé's comment, the detectCores function from the parallel package should be able to accomplish what you want with its second argument, logical. From ?parallel::detectCores:

    logical: Logical: if possible, use the number of physical CPUs/cores (if FALSE) or logical CPUs (if TRUE). The default is TRUE on Windows and FALSE elsewhere.

    For my machine, a 4-core hyperthreaded i-7, I get

    # physical cores
    parallel::detectCores(logical=FALSE)
    [1] 4
    # logical cores (threads)
    parallel::detectCores(logical=TRUE)
    [1] 8