Thread affinity with Windows, MSVC, and OpenMP

后端 未结 1 1543
傲寒
傲寒 2020-12-20 20:20

I want to bind the threads in my code to each physical core. With GCC I have successfully done this using sched_setaffinity so I no longer have to set exp

相关标签:
1条回答
  • 2020-12-20 21:07

    You should use the SetThreadAffinityMask function (see MSDN reference). You are setting the process's mask.

    You can obtain a thread ID in OpenMP with this code:

    int tid = omp_get_thread_num();
    

    However the code above provides OpenMP's internal thread ID, and not the system thread ID. This article explains more on the subject:

    http://msdn.microsoft.com/en-us/magazine/cc163717.aspx

    if you need to explicitly work with those trheads - use the explicit affinity type as explained in this Intel documentation:

    https://software.intel.com/sites/products/documentation/studio/composer/en-us/2011Update/compiler_c/optaps/common/optaps_openmp_thread_affinity.htm

    0 讨论(0)
提交回复
热议问题