且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用OpenMP将线程绑定到特定的CPU内核

更新时间:2022-10-26 09:16:10

GOMP参考可能会帮助您.要回答您的特定问题,`GOMP_CPU_AFFINITY ="0-2:2 ..."将会这样做-这意味着在任何可被2(即0和2)整除的处理器0-2上运行".

至少,如果您要问如何让core0在core0或core2的EITHER上运行,您实际提出的问题的答案是您做不到",因为线程只能以任何精确的方式在一个Core上运行及时,因此Thread0不能同时在两个内核上运行.

I know that GOMP_CPU_AFFINITY binds threads to specific cores.

But in example what they have given here, it gives:

GOMP_CPU_AFFINITY="0 3 2 1"

Here,

thread0 gets attached to---> cpu0

thread1 gets attached to---> cpu3

thread2 gets attached to---> cpu2

thread3 gets attached to---> cpu1

This is clear.

But How can I set thread0 to core0 and core2 at same time ? What will be the value of Environment variable "GOMP_CPU_AFFINITY" for it ?

This GOMP reference may help you. To answer your specific question `GOMP_CPU_AFFINITY="0-2:2 ..." would do that - it means "run on any processor 0-2, that is divisible by 2 (which is 0 and 2)".

At least if you are asking how you can let thread0 run on EITHER of core0 or core2 - the question you actually ask has the answer "you can't", because a thread can only be run on one core at any precise moment in time, so Thread0 can not run on two cores simultaneously.