使用OpenMP在两个核心上设置线程关联 [英] Set thread affinity on two cores using OpenMP
问题描述
我正在使用C程序,使用OpenMP 4.0在Windows7上使用gcc 4.9.2进行编译。
我的电脑是双核心,有四个线程。
我想使用线程关联传播并使用放置在不同内核上的2个线程。所以当我用DOS设置环境变量时:
- set OMP_NUM_THREADS = 2
- 设置OMP_PROC_BIND =传播
- 设置OMP_PLACES =cores
我得到了变量OMP_DISPLAY_ENV = true,这是:
libgomp:环境变量的值无效OMP_PLACES
OPENMP DISPLAY ENVIRONMENT BEGIN
OOP_DYNAMIC ='FALSE'
b $ b OMP_SCHEDULE ='DYNAMIC'
OMP_PROC_BIND ='SPREAD'
OMP_PLACES =''
OMP_STACKSIZE ='12872703'
OMP_WAIT_POLICY ='PASSIVE'
OMP_THREAD_LIMIT =' 4294967295'
OMP_MAX_ACTIVE_LEVELS ='2147483647'
OMP_CANCELLATION ='FALSE'
OMP_DEFAULT_DEVICE ='0'
OPENMP DISPLAY环境END
看来这个了输入无效,所以我将其更改为:
- set OMP_PLACES =cores
libgomp:此配置不支持亲和性
OPENMP DISPLAY环境开始
_OPENMP ='201307'
OMP_DYNAMIC ='FALSE'
OMP_NESTED ='FALSE'
OMP_NUM_THREADS ='2'
OMP_SCHEDULE ='DYNAMIC'
OMP_PROC_BIND ='SPREAD'
OMP_PLACES =''
OMP_STACKSIZE ='3107827'
OMP_WAIT_POLICY ='PASSIVE'
OMP_THREAD_LIMIT ='4294967295'
OMP_MAX_ACTIVE_LEVELS ='2147483647'
OMP_CANCELLATION ='FALSE'
OMP_DEFAULT_DEVICE ='0'
OPENMP DISPLAY环境END
这是结果:不支持亲和力。即使有以下情况,我也会得到相同的结果:
set OMP_PLACES ={0},{2},{1},{3}
您是否有人知道如何解决这个问题?
我在Linux上用gcc 4.9.3编译了一个简单的hello世界代码,用你提出的环境变量:
$ b
〜/ tmp $ OMP_DISPLAY_ENV = true OMP_NUM_THREADS = 2 OMP_PROC_BIND =传播OMP_PLACES =核心./a.out
OPENMP DISPLAY环境开始
_OPENMP ='201307'
OMP_DYNAMIC ='FALSE'
OMP_NESTED ='FALSE'
OMP_NUM_THREADS ='2'
OMP_SCHEDULE ='DYNAMIC'
OMP_PROC_BIND ='SPREAD'
OMP_PLACES ='{ 0:2},{2:2}'
OMP_STACKSIZE ='140736864318339'
OMP_WAIT_POLICY ='PASSIVE'
OMP_THREAD_LIMIT ='4294967295'
OMP_MAX_ACTIVE_LEVELS ='2147483647'
OMP_CANCELLATION ='FALSE'
OMP_DEFAULT_DEVICE ='0'
OPENMP DISPLAY ENVIRONMENT END
您好,来自线程0/2
您好,来自线程1/2
所以基本上,它适用于我,我相信你所尝试的是合法的。然而,这个配置不支持的 Affinity消息让我相信,在您的Windows 7机器上,亲和力可能根本无法使用。我没有这样的环境来测试,但是OpenMP标准表明:
确定亲和性请求是否可以被满足是
实现定义。如果亲和力请求不能满足,
,那么团队中线程的亲和力就是实现定义的。
我猜这就是我们是......
I am using a C program, compiled with gcc 4.9.2 on Windows7, using OpenMP 4.0. My computer is dual core, with four threads. I'd like to use thread affinity spread and use 2 threads put on different cores. So when I set the environment variables from DOS with:
- set OMP_NUM_THREADS=2
- set OMP_PROC_BIND=spread
- set OMP_PLACES="cores"
I get, with the variable OMP_DISPLAY_ENV=true, this:
libgomp: Invalid value for environment variable OMP_PLACES
OPENMP DISPLAY ENVIRONMENT BEGIN
_OPENMP = '201307'
OMP_DYNAMIC = 'FALSE'
OMP_NESTED = 'FALSE'
OMP_NUM_THREADS = '2'
OMP_SCHEDULE = 'DYNAMIC'
OMP_PROC_BIND = 'SPREAD'
OMP_PLACES = ''
OMP_STACKSIZE = '12872703'
OMP_WAIT_POLICY = 'PASSIVE'
OMP_THREAD_LIMIT = '4294967295'
OMP_MAX_ACTIVE_LEVELS = '2147483647'
OMP_CANCELLATION = 'FALSE'
OMP_DEFAULT_DEVICE = '0'
OPENMP DISPLAY ENVIRONMENT END
It seems that the input is not valid, so I changed it to:
- set OMP_PLACES="cores"
libgomp: Affinity not supported on this configuration
OPENMP DISPLAY ENVIRONMENT BEGIN
_OPENMP = '201307'
OMP_DYNAMIC = 'FALSE'
OMP_NESTED = 'FALSE'
OMP_NUM_THREADS = '2'
OMP_SCHEDULE = 'DYNAMIC'
OMP_PROC_BIND = 'SPREAD'
OMP_PLACES = ''
OMP_STACKSIZE = '3107827'
OMP_WAIT_POLICY = 'PASSIVE'
OMP_THREAD_LIMIT = '4294967295'
OMP_MAX_ACTIVE_LEVELS = '2147483647'
OMP_CANCELLATION = 'FALSE'
OMP_DEFAULT_DEVICE = '0'
OPENMP DISPLAY ENVIRONMENT END
And this is the result: affinity not supported. I get the same result even with:
set OMP_PLACES="{0},{2},{1},{3}"
Does any of you know how to solve this?
I tried a simple hello world code compiled with gcc 4.9.3 on Linux, with the environment variables you proposed:
~/tmp$ OMP_DISPLAY_ENV=true OMP_NUM_THREADS=2 OMP_PROC_BIND=spread OMP_PLACES=cores ./a.out
OPENMP DISPLAY ENVIRONMENT BEGIN
_OPENMP = '201307'
OMP_DYNAMIC = 'FALSE'
OMP_NESTED = 'FALSE'
OMP_NUM_THREADS = '2'
OMP_SCHEDULE = 'DYNAMIC'
OMP_PROC_BIND = 'SPREAD'
OMP_PLACES = '{0:2},{2:2}'
OMP_STACKSIZE = '140736864318339'
OMP_WAIT_POLICY = 'PASSIVE'
OMP_THREAD_LIMIT = '4294967295'
OMP_MAX_ACTIVE_LEVELS = '2147483647'
OMP_CANCELLATION = 'FALSE'
OMP_DEFAULT_DEVICE = '0'
OPENMP DISPLAY ENVIRONMENT END
Hello from thread 0 / 2
Hello from thread 1 / 2
So basically, it works for me, and I believe that what you tried is legit. However, the message you get Affinity not supported on this configuration
let me believe that affinity might simply not be available on your Windows 7 machine. I have no such environment to test, but the OpenMP standard says that:
The determination of whether the affinity request can be fulfilled is implementation defined. If the affinity request cannot be fulfilled, then the affinity of threads in the team is implementation defined.
I guess that's were we are...
这篇关于使用OpenMP在两个核心上设置线程关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!