openmp核心分配失败

时间:2019-06-28 15:37:31

标签: linux openmp icc

我的Centos 6 VM在显示/proc/cpuinfo的内容时显示四个核心,而/sys/devices/system/cpu/online显示0-3

我正在尝试使用KMP_AFFINITY="explicit,proclist=[2-3]"

在核心2和3上运行以下代码
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <sched.h>

int main (int argc, char *argv[]) {
int nthreads, tid, cid;

    #pragma omp parallel private(nthreads, tid)
    {
        tid = omp_get_thread_num();
        cid = sched_getcpu();
        printf("Hello from thread %d on core %d\n", tid, cid);

        if (tid == 0) {
            nthreads = omp_get_num_threads();
            printf("Number of threads = %d\n", nthreads);
        }
    }
}

使用icc (ICC) 16.0.1 20151021进行编译时,它无法检测可用的内核并在内核0上执行所有操作。

$ OMP_NUM_THREADS=4 ./a.out 
OMP: Warning #123: Ignoring invalid OS proc ID 2.
OMP: Warning #123: Ignoring invalid OS proc ID 3.
OMP: Warning #124: No valid OS proc IDs specified - not using affinity.
Hello from thread 0 on core 0
Number of threads = 1
Hello from thread 0 on core 0
Number of threads = 1
Hello from thread 0 on core 0
Number of threads = 1
Hello from thread 0 on core 0
Number of threads = 1

gcc (GCC) 4.4.7 20120313GOMP_CPU_AFFINITY="2-3"相同的位置在内核2和3上正确执行,就像set一样。

我用strace来检查引擎盖下的情况,发现有些奇怪的地方:

[...]
open("/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = 3
read(3, "0-3\n", 8192)                  = 4
[...]
sched_getaffinity(0, 1048576,  { 1 })   = 8
sched_setaffinity(0, 8,  { 4521c26fbb1c38c1 }) = -1 EFAULT (Bad addres
[...]

这可能是英特尔实施OpenMP产生的错误吗?

在这种情况下,我无法升级编译器来修复它。通过icc进行编译时,可以使用GCC OpenMP库而不使用Intel的吗?

更新:

我设法用gcc编译代码,并使用以下命令将其与iomp链接 gcc omp.c -L/opt/intel/compilers_and_libraries_2016/linux/lib/intel64_lin/ -liomp5

执行不输出警告,但仍然不正确:

$ OMP_NUM_THREADS=4 ./a.out 
Hello from thread 0 on core 0
Number of threads = 1

与先前显示的错误sched_setaffinity相同。

0 个答案:

没有答案