I try my best to find a reliable way to get the number of cores in Windows. I am running the 64-bit version of Windows 7 Professional SP1 on a machine with an Intel Xeon E5-2699 v3 @ 2.30GHz dual-core processor that summarizes 72 cores. I tried different methods to get the number of cores, and I found that only two of them seem to work exactly in a 32-bit or 64-bit process. Here are my results:
+ ------------------------------------------------ + ---------------- + ---------------- +
| Methods | 32-bit process | 64-bit process |
+ ------------------------------------------------ + ---------------- + ---------------- +
| GetSystemInfo-> dwNumberOfProcessors | 32 | 36 |
| GetNativeSystemInfo-> dwNumberOfProcessors | 36 | 36 |
| GetLogicalProcessorInformation | 36 | 36 |
| GetProcessAffinityMask.processAffinityMask | 32 | 32 |
| GetProcessAffinityMask.systemAffinityMask | 32 | 32 |
| omp_get_num_procs | 32 | 36 |
| getenv ("NUMBER_OF_PROCESSORS") | 36 | 36 |
| GetActiveProcessorCount (ALL_PROCESSOR_GROUPS) | 64 | 72 |
| GetMaximumProcessorCount (ALL_PROCESSOR_GROUPS) | 64 | 72 |
| boost :: thread :: hardware_concurrency () | 32 | 36 |
| Performance counter API | 36 | 36 |
| WMI | 72 | 72 |
| HARDWARE \ DESCRIPTION \ System \ CentralProcessor | 72 | 72 |
+ ------------------------------------------------ + ---------------- + ---------------- +
I will not explain why all these functions return different values. The only 2 methods that seem reliable to me are either using WMI (but rather complicated) or simply reading the following key in the Windows registry: HARDWARE \ DESCRIPTION \ System \ CentralProcessor.
What do you think? Do you confirm that the WMI and registry key methods are the only reliable methods?
Thanks in advance
c ++ multithreading windows winapi
ben
source share