gpt4 book ai didi

c - 使用 OpenMP 在两个内核上设置线程关联

转载 作者:太空宇宙 更新时间:2023-11-04 03:32:54 25 4
gpt4 key购买 nike

我正在使用 C 程序,在 Windows7 上使用 gcc 4.9.2 编译,使用 OpenMP 4.0。我的电脑是双核的,有四个线程。我想使用线程亲和性传播并使用放在不同内核上的 2 个线程。所以当我从 DOS 设置环境变量时:

  • set OMP_NUM_THREADS=2
  • set OMP_PROC_BIND=spread
  • set OMP_PLACES="cores"

我通过变量 OMP_DISPLAY_ENV=true 得到:

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

好像输入的不对,所以改成:

  • 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

这就是结果:不支持关联。即使使用以下方法,我也会得到相同的结果:

set OMP_PLACES="{0},{2},{1},{3}"

你们有谁知道如何解决这个问题吗?

最佳答案

我尝试在 Linux 上用 gcc 4.9.3 编译一个简单的 hello world 代码,使用您建议的环境变量:

~/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

所以基本上,它对我有用,我相信您尝试的是合法的。但是,您收到的消息 Affinity not supported on this configuration 让我相信 affinity 可能根本无法在您的 Windows 7 计算机上使用。我没有这样的环境来测试,但 OpenMP 标准说:

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.

我想那是我们...

关于c - 使用 OpenMP 在两个内核上设置线程关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34852911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com