使用OpenMP在两个核心上设置线程关联

时间:2016-01-18 10:52:32

标签: c multithreading gcc openmp affinity

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

  
      
  • 设置OMP_NUM_THREADS = 2
  •   
  • 设置OMP_PROC_BIND =传播
  •   
  • 设置OMP_PLACES ="核心"
  •   

我得到了变量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

似乎输入无效,因此我将其更改为:

  
      
  • 设置OMP_PLACES ="核心"
  •   
  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

这就是结果:不支持亲和力。即使使用以下内容,我也得到相同的结果:

  

设置OMP_PLACES =" {0},{2},{1},{3}"

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

1 个答案:

答案 0 :(得分:1)

我尝试在Linux上使用gcc 4.9.3编译一个简单的hello world代码,其中包含你提出的环境变量:

In [259]: store = HDFStore('store.h5')

In [260]: print(store)
<class 'pandas.io.pytables.HDFStore'>
File path: store.h5
Empty
Objects can be written to the file just like adding key-value pairs to a dict:

In [261]: np.random.seed(1234)

In [262]: index = date_range('1/1/2000', periods=8)

In [263]: s = Series(randn(5), index=['a', 'b', 'c', 'd', 'e'])

In [264]: df = DataFrame(randn(8, 3), index=index,
   .....:                columns=['A', 'B', 'C'])
   .....: 

In [265]: wp = Panel(randn(2, 5, 4), items=['Item1', 'Item2'],
   .....:            major_axis=date_range('1/1/2000', periods=5),
   .....:            minor_axis=['A', 'B', 'C', 'D'])
   .....: 

# store.put('s', s) is an equivalent method
In [266]: store['s'] = s

In [267]: store['df'] = df

In [268]: store['wp'] = wp

# the type of stored data
In [269]: store.root.wp._v_attrs.pandas_type
Out[269]: 'wide'

In [270]: store
Out[270]: 
<class 'pandas.io.pytables.HDFStore'>
File path: store.h5
/df            frame        (shape->[8,3])  
/s             series       (shape->[5])    
/wp            wide         (shape->[2,5,4])

所以基本上,它适用于我,我相信你所尝试的是合法的。但是,您收到的消息~/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 让我相信您的Windows 7计算机上可能无法提供亲缘关系。我没有这样的测试环境,但OpenMP标准说:

  

确定是否可以满足亲和力请求是   实施定义。如果无法满足关联请求,   那么团队中线程的亲和力就是实现定义的。

我想我们是......