gpt4 book ai didi

c++ - std::thread::hardware_concurrency() 未在 AMD Ryzen threadripper 3990x 中返回正确数量的逻辑处理器

转载 作者:行者123 更新时间:2023-12-05 01:05:19 29 4
gpt4 key购买 nike

我在不同的机器(包括 Linux 和 Windows,以及 Intel 和 AMD CPU 以及 clang++、GNU 和 MSVC)中使用线程库。在所有这些中,std::thread::hardware_concurrency() 返回 Windows 中所谓的逻辑处理器或包括超线程在内的最大线程数,但是在具有 AMD Ryzen threadripper 3990x CPU 的新机器中,它只返回数字核心数是最大线程数的一半(64 而不是 128)。我在 c++ 引用中读到返回值取决于实现,这只是一个提示,但我的问题是如何找到实现,或者该函数返回的线程数是否存在上限。由于我在测试的所有机器上都出现了类似的行为,我不知道这种不同行为的原因是什么。

最佳答案

std::thread::hardware_concurrency的思想是告诉你std::thread可以体验到什么样的并发。由于 std::thread 只能将线程放入您的默认处理器组,因此您将获得默认 processor group 中的逻辑处理器数.除非您采取极端措施,否则这在 Windows 上不会大于 64。

"[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."

关于c++ - std::thread::hardware_concurrency() 未在 AMD Ryzen threadripper 3990x 中返回正确数量的逻辑处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70704458/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com