使用OpenMP将线程绑定到特定的CPU内核 [英] Bind threads to specific CPU cores using OpenMP

查看:1774
本文介绍了使用OpenMP将线程绑定到特定的CPU内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 GOMP_CPU_AFFINITY 将线程绑定到特定的内核.

但是在示例中,他们给出了此处,它给出了:

GOMP_CPU_AFFINITY ="0 3 2 1"

在这里

线程0 已附加到---> cpu0

线程1 附加到---> cpu3

线程2 附加到---> cpu2

thread3 已附加到---> cpu1

这很清楚.

但是如何同时将thread0设置为core0和core2呢?它的环境变量"GOMP_CPU_AFFINITY"的值是什么?

解决方案

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.

这篇关于使用OpenMP将线程绑定到特定的CPU内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆