在谈论多线程时,线程似乎通常被视为平等——与主线程相同,但在它旁边运行。
然而,在某些新处理器上,例如Apple M1芯片和即将推出的 Intel Alder Lake系列,并非所有线程的性能都与这些芯片的性能相同,因为这些芯片具有独立的高性能内核和高效、速度较慢的内核。
这并不是说还没有诸如超线程之类的东西,但这似乎对性能有更大的影响。
有没有办法查询std::thread的属性并强制它们在 C++ 中运行的核心?
我正在使用该start /AFFINITY [n] [.exe]命令以指定的亲缘关系启动可执行文件.我有一个带8个处理器的系统(1,2,3,4,5,6,7,8).我想设置进程使用所有奇数处理器(1,3,5,7).我无法弄清楚如何做到这一点,并想知道是否可以使用start命令.如果没有,是否有另一种命令行方式呢?
start命令的帮助不是特别有用:
AFFINITY Specifies the processor affinity mask as a hexadecimal number.
The process is restricted to running on these processors.
The affinity mask is interpreted differently when /AFFINITY and
/NODE are combined. Specify the affinity mask as if the NUMA
node's processor mask is right shifted to begin at bit zero.
The process is restricted to running on those processors in
common between the specified affinity mask and the NUMA node.
If …Run Code Online (Sandbox Code Playgroud) 我觉得我在这里错过了一些东西......
我稍微改变了一些代码,从使用到改变std::thread,std::async并注意到性能的显着增加.我写了一个简单的测试,我认为它应该std::thread像使用它一样运行几乎相同std::async.
std::atomic<int> someCount = 0;
const int THREADS = 200;
std::vector<std::thread> threadVec(THREADS);
std::vector<std::future<void>> futureVec(THREADS);
auto lam = [&]()
{
for (int i = 0; i < 100; ++i)
someCount++;
};
for (int i = 0; i < THREADS; ++i)
threadVec[i] = std::thread(lam);
for (int i = 0; i < THREADS; ++i)
threadVec[i].join();
for (int i = 0; i < THREADS; ++i)
futureVec[i] = std::async(std::launch::async, lam);
for (int i = 0; i …Run Code Online (Sandbox Code Playgroud) c++ ×2
affinity ×1
apple-m1 ×1
asynchronous ×1
c++11 ×1
command-line ×1
intel ×1
performance ×1
windows-7 ×1