user2348209
user2348209

Reputation: 156

std::thread::hardware_concurrency() does not return the correct number of Logical Processors in AMD Ryzen threadripper 3990x

I am using thread library in different machines (including Linux and Windows, and also both Intel and AMD CPUs and with clang++, GNU and MSVC). in all of them, std::thread::hardware_concurrency() returns what is called Logical Processors in Windows or the maximum number of threads including the hyper threads, however in a new machine which has AMD Ryzen threadripper 3990x CPU it returns only the number of cores which is half of the maximum number of threads (64 instead of 128). I read in the c++ reference that the return value depends on the implementation and it's only a hint, but my question is that how can I find the implementation or is there an upper bound for the number of threads that this function returns or not. Since I was getting a similar behavior across all machines that I was testing I have no clue what is the reason for this different behavior.

Upvotes: 3

Views: 1547

Answers (1)

David Schwartz
David Schwartz

Reputation: 182763

The idea of std::thread::hardware_concurrency is to tell you what kind of concurrency std::threads can experience. Since std::thread can only put threads into your default processor group, you will get the number of logical processors in your default processor group. This is not going to be greater than 64 on Windows unless you go to extreme measures.

"[A] system with 128 logical processors would have two processor groups with 64 processors in each group[.]"

"An application that requires the use of multiple groups so that it can run on more than 64 processors must explicitly determine where to run its threads and is responsible for setting the threads' processor affinities to the desired groups."

Upvotes: 8

Related Questions