Clang/LLVM OpenMP 程序未生成线程

Clang/LLVM OpenMP program not spawning threads

根据http://blog.llvm.org/2015/05/openmp-support_22.html,Clang 中的 OpenMP 支持已经完成。但是,我在尝试一个简单的程序时遇到了困难。

我已经按照 http://clang.llvm.org/get_started.html and the OpenMP runtime as explained in http://openmp.llvm.org/ 中的说明安装了 Clang/LLVM。

测试程序为:

#include "omp.h"
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
    #pragma omp parallel
    {
        printf("thread %d\n", omp_get_thread_num());
    }
    return 0;
}

编译行是:

clang -lomp -I/.../openmp/runtime/exports/common/include -L/.../openmp/runtime/exports/lin_32e/lib ./test-openmp.c -o ./test-openmp

使用 which,我检查我使用的是正确的 clang 二进制文件。

使用 ldd,我检查我 link 连接到正确的 OpenMP 库:

$ ldd ./test-openmp
linux-vdso.so.1 =>  (0x00007ffdaf6d7000)
libomp.so => /.../openmp/runtime/exports/lin_32e/lib/libomp.so (0x00007f7d47552000)
libc.so.6 => /lib64/libc.so.6 (0x00007f7d47191000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f7d46f8d000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f7d46d71000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7d477fb000)

但是当运行时,它只执行一个线程:

$ OMP_NUM_THREADS=4 ./test-openmp
thread 0

我 link 使用 lomp 的原因是,如果我 link 使用 fopenmp,代码会错误地 link gcc omp 库。但是在那种情况下,结果是一样的:

$ clang -fopenmp -I/.../openmp/runtime/exports/common/include -L/.../openmp/runtime/exports/lin_32e/lib ./test-openmp.c -o ./test-openmp

$ ldd ./test-openmp
linux-vdso.so.1 =>  (0x00007ffdf351f000)
libgomp.so.1 => /lib64/libgomp.so.1 (0x00007fbc1c3e1000)
librt.so.1 => /lib64/librt.so.1 (0x00007fbc1c1d9000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fbc1bfbd000)
libc.so.6 => /lib64/libc.so.6 (0x00007fbc1bbfc000)
/lib64/ld-linux-x86-64.so.2 (0x00007fbc1c5f8000)

$ OMP_NUM_THREADS=4 ./test-openmp
thread 0

使用 gcc 时,它按预期工作:

$ gcc -fopenmp ./test-openmp.c -o ./test-openmp

$ ldd ./test-openmp
linux-vdso.so.1 =>  (0x00007ffc444e0000)
libgomp.so.1 => /lib64/libgomp.so.1 (0x00007f7d425ce000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f7d423b2000)
libc.so.6 => /lib64/libc.so.6 (0x00007f7d41ff1000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7d427e5000)

$ OMP_NUM_THREADS=4 ./test-openmp
thread 0
thread 2
thread 3
thread 1

我过去使用过 http://clang-omp.github.io/ 中描述的实现,我知道其中一个可行(提供了不同的回购协议)那里有 Clang 和 LLVM,但 OpenMP 存储库是相同的)。然而,该页面(显然)已于 2014 年更新,http://blog.llvm.org/2015/05/openmp-support_22.html 中的博客是 2015 年 5 月的,这让您认为您可以将最新的 Clang/LLVM 用于 OpenMP。

所以我的问题是,我是不是遗漏了什么,或者 2015 年 5 月的博客实际上指的是 http://clang-omp.github.io 中的 Clang/LLVM 实现,而不是最新的?

谢谢

添加 -fopenmp=libomp 应该可以解决问题。

这是暂时的情况;希望很快 clang 将被更改为执行博客 post.

中描述的内容

你的, 安德烈