简体   繁体   English

OpenMP和CPU亲和力

[英]OpenMP and CPU affinity

Will sched_setaffinity or pthread_attr_setaffinity_np work to set thread affinity under OpenMP? sched_setaffinitypthread_attr_setaffinity_np可以在OpenMP下设置线程关联?

Related: CPU Affinity 相关: CPU亲和力

Yes, named calls will work to set thread affinity. 是的,命名调用将用于设置线程关联。 The only problem is to fix thread number and to set right affinity in right thread (you can try using static scheduling of for loop for known number of threads). 唯一的问题是修复线程编号并在正确的线程中设置正确的关联(您可以尝试使用for循环的静态调度for处理已知数量的线程)。

As I know, almost every openmp allows to set affinity via environment. 据我所知,几乎每个openmp都允许通过环境设置亲和力。 The name of environment variable varies (it was not standartized some time ago). 环境变量的名称各不相同(前一段时间没有标准化)。 I use http://www.spec.org/omp2001/results/omp2001.html page to find openMP implementation and the will search for specific environment variable name. 我使用http://www.spec.org/omp2001/results/omp2001.html页面来查找openMP实现,并将搜索特定的环境变量名称。 Affinity is set in ~half of specOMP results. 亲和力设置在specOMP结果的一半左右。 There are some additional OpenMP performance-tuning settings in results too. 结果中还有一些额外的OpenMP性能调整设置。

Eg For intel compiler the variable is 例如, 对于intel编译器 ,变量是

 export KMP_AFFINITY=compact,0

For sun compiler: 对于sun编译器:

 export SUNW_MP_PROCBIND=TRUE

For gcc (pre-openmp 3.1) 对于gcc(pre-openmp 3.1)

 export GOMP_CPU_AFFINITY=0-63

where 63 is maximum CPU number (when counted from 0) 其中63是最大CPU数(从0开始计数)

And newer OpenMP Standard, version 3.1 defines environment variable OMP_PROC_BIND (see section 4.4) which is standardized way of setting affinity in OpenMP. 较新的OpenMP Standard 3.1版定义了环境变量OMP_PROC_BIND(参见4.4节),这是在OpenMP中设置关联的标准方法。 Usage is: 用法是:

 export OMP_PROC_BIND=true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM