Win32 / stdlib detects only half the number of logical cores in C / C ++ under Windows

I have a C ++ math program compiled using mingw-w64 that determines the number of logical cores in the system to run the optimal number of workflows.

It works well on all the machines that I have tested so far, but one user reports that only 20 threads are running, while he has a machine with two Xeon with 10 hyper-threading cores, a total of 40 logical processors.

Windows 2012 Server Task Manager reports: 2 sockets, 20 cores, 40 logical processors (I have a screenshot). There are 40 graphs in the load diagram of several CPUs (I also have a screenshot)

But I always discover only 20 logical processors using one of the following three methods:

  • GetSystemInfo() from Win32 C API
  • std::thread::hardware_concurrency() from c ++ 11 stdlib
  • QThread::idealThreadCount() from Qt 5.4

In general, it is likely that the latter two are implemented using the former.

How can I correctly determine the actual number of logical cores?

Thanks!

+4
source share

Source: https://habr.com/ru/post/1620770/


All Articles