-
Notifications
You must be signed in to change notification settings - Fork 1.5k
<thread>
: std::thread::hardware_concurrency
limited to 64, even on Windows 11
#5453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This does seem like a bug now, given that the OS behavior has changed. |
If I understand correctly, according to the documentation Processor Groups, starting from Windows 11, a process will have multiple groups by default if the number of processors exceeds 64. |
[`GetActiveProcessorCount`](https://learn.microsoft.com/zh-cn/windows/win32/api/winbase/nf-winbase-getactiveprocessorcount) [Raymond Chen's claim](https://devblogs.microsoft.com/oldnewthing/20200824-00/?p=104116)
@YexuanXiao if you provide instructions, I'm happy to run a test. If you're just looking to test the behavior of |
Testing the behavior of |
Confirmed, that works as expected:
That's only in x64 mode though. In x86 mode it reports 2 groups of 32 CPUs for a total of 64. I'm guessing 32-bit compatibility for systems with >64 CPUs is not a huge concern though. Aside from that, I also checked that NUMA settings don't affect the result: if I configure the system to use 4 NUMA nodes the output of the test exe is unchanged from what's shown above. I can't vouch for the behavior on multi-socket systems. |
Describe the bug
On machines with more than 64 logical processors,
std::thread::hardware_concurrency()
is capped to 64.Microsoft's documentation for this function states:
This suggests that on Windows 11 (and Windows Server 2022 and 2025),
hardware_concurrency
should return the total number of logical processors in the system. But it does not. On my Threadripper 7980X system, it returns 64 instead of 128.Command-line test case
Expected behavior
std::thread::hardware_concurrency()
should return the number of logical CPUs available on the system, in this case 128.STL version
Visual Studio version:
Additional context
This issue was previously reported as #1230. It was closed with this comment (#1230 (comment)):
The comment by sylveon that was referred to was (#1230 (comment)):
Note that this explanation no longer holds. As described in Microsoft's official STL documentation quoted above, as well as in the Windows API documentation, starting on Windows 11, all logical processors across all processor groups can be used without needing to make any special Windows API calls. Moreover, multithreaded STL code actually does make use of more than 64 logical processors. For example, if I use a parallel execution policy with an algorithm from
<algorithm>
, all 128 logical processors of my machine get fully utilized.Another similar issue was #2099. That issue was closed last September by updating the documentation (including what I quoted above), see here. However, as explained in this issue, the behavior of
hardware_concurrency
is not consistent with the updated documentation, and sohardware_concurrency
should be updated.The STL implementation of
hardware_concurrency
currently delegates to_Thrd_hardware_concurrency
, which is:On Windows 11 and above this could be updated to use
GetLogicalProcessorInformationEx
. Here is a very crude implementation that gets the logical processors in a single physical package. Though perhaps a differentRelationshipType
would be more appropriate.The text was updated successfully, but these errors were encountered: