[cfe-dev] Clang/LLVM OpenMP program not spawning threads

Jaime Arteaga jandres742 at gmail.com
Mon Jul 27 15:19:39 PDT 2015


According to http://blog.llvm.org/2015/05/openmp-support_22.html, OpenMP
support in Clang is completed. However, I'm having difficulties trying a
simple program.

I've installed Clang/LLVM as explained in
http://clang.llvm.org/get_started.html and the OpenMP runtime as explained
in http://openmp.llvm.org/.

The test program is:

#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;
}

The compilation line is:

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

Using which, I check I'm using the correct clang binary.

With ldd, I check I'm linking to the correct OpenMP library:

$ 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)

But when running, it executes only one thread:

$ OMP_NUM_THREADS=4 ./test-openmp
thread 0

The reason I'm linking with lomp is because if I link with fopenmp, the
code is wrongly linked to the gcc omp library. However in that case, the
result is the same:

$ 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

When using gcc, it works as expected:

$ 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

I've used in the past the implementation described in
http://clang-omp.github.io/ and I know that one works (a different repo is
presented there for Clang and LLVM, but the OpenMP repo is the same).
However that page was (apparently) updated in 2014, and the blog in
http://blog.llvm.org/2015/05/openmp-support_22.html is from May 2015, which
makes you think that you can use the latest Clang/LLVM for OpenMP.

So my question is, am I missing something or the blog from May 2015 is
actually referring to Clang/LLVM implementation from in
http://clang-omp.github.io and not to the latest one?

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150727/b6050ee9/attachment.html>


More information about the cfe-dev mailing list