Config: Windows 10 ,mingw-x64,Core 2(4逻辑)
以下代码
#include <cstdio>
#include <omp.h>
#include <windows.h>
int main() {
#pragma omp parallel
{
std::printf ("Doing Stuff on thread: %d on Core #%d\n", omp_get_thread_num(),\
GetCurrentProcessorNumber());
}
return 0;
}
有时会提供输出:
Doing Stuff on thread: 1 on Core #1
Doing Stuff on thread: 0 on Core #2
Doing Stuff on thread: 2 on Core #2
Doing Stuff on thread: 3 on Core #2
尽管大多数情况下都会给出
Doing Stuff on thread: 2 on Core #1
Doing Stuff on thread: 1 on Core #3
Doing Stuff on thread: 0 on Core #2
Doing Stuff on thread: 3 on Core #0
这是预期的。
如何确保对不同的核心设置了线程亲和性?有办法强制调度程序执行此操作吗?