issue with opennp and clang

Greetings,

so I tried to use opennp with one of the latest version of clang, clang version 3.4.2 (tags/RELEASE_34/dot2-final). Followed the procedure to compilre and export the library PATHs, Compiling my hello.c using :

clang -fopenmp hello.c

and then running it, still it can’t use more than 1 thread:

Bash-4.1$ ./a.out 
Hello from thread 0, nthreads 1

I tried to manually export export OMP_NUM_THREADS=8 but that didn’t solve anything as well, As a workaround I define #pragma omp parallel num_threads(#noofthreads) inside the source code but still the issue is there.

Any suggestions would be appreciated.

-Amir

p.sl: This is the hello.c:

#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads

Hi,

You haven’t imported the openmp library to Clang yet. It simply ignores the pragmas.

Go to this link and follow the instructions.
clang-omp.github.io

Best Regards,
Millad

Also make your envt. variables point to the

-Sunita

I did that.

Downloaded and compiled with gcc, then export all the PATHs. Otherwise, It would have given me compile error because the “omp.h” is different here.

-Amir

​"omp.h" is not different. It is the same among all compilers.​

​You should compile it with Clang

use:

​make compiler=clang

If you build the IR with this:

clang -g -emit-llvm -S -c -fopenmp hello.c -o hello.ll

do you see "__kmpc_fork_call" in hello.ll?

Thanks Jeremy for the good call.

I think something is missing here as I have :

clang: warning: argument unused during compilation: ‘-fopenmp’

p.s (TO: Milad): I make clean and make compile=clang and check all the needed exports.

-Amir

Amir,
Official clang does not support OpenMP yet. You should use clang/LLVM from clang-omp.github.com.

Best regards,
Alexey Bataev

Amir,
You didn’t say what platform you are trying to use clang-omp on. If it is OS X, the llvm34-3.4.2-2 fink package (http://finkproject.org) has a port of the clang-omp changes at commit 13e28835a005b44481387a32666ed39a7db58eb6 over the llvm 3.4.2 release. While the fink llvm35 packaging isn’t released yet, you can obtain the necessary llvm35* packaging files to build it from http://fink.cvs.sourceforge.net/viewvc/fink/experimental/fangism/finkinfo/. This has a port of the clang-omp changes at commit 3f687cbc520a8b8f506d7941f0cebd6c5af1cef6 over llvm 3.5.0 with the openmp trunk changes at r219214.
Jack

Thanks all for their responses. I re-compile the clang with OpenMP support and the library files and set the library paths and it worked finally. I might think as Alexey mentioned, that the CentOS was using the default clang to that matter before head.

Regards,

-Amir

Jeremey,

Could you let me know if in the LLVM-openMP project we have the same opt as the default llvm-opt ?

as I am running these procedures:

1- clang(Openmp) -S -emit-llvm -fopenmp llvm_openmp.c

2- opt(Openmp) -S -o hello_opt.ll hello.ll

3- clang(Openmp) hello_opt.ll -lm

I am getting :

[ashouri@savina openmp_power]$ clang -v llvm_openmp.ll -lm

clang version 3.5.0 (https://github.com/clang-omp/clang 05ab95f7cb2779bbf20341ae6ed293106de5afda) (https://github.com/clang-omp/llvm e45b045553e027cbe400cbb8ac8c264abbbfaf83)

Target: x86_64-unknown-linux-gnu

Thread model: posix

Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.4.4

Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.4.7

Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.4

Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7

Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7

Candidate multilib: .;@m64

Candidate multilib: 32;@m32

Selected multilib: .;@m64

“~/llvm/build/Debug+Asserts/bin/clang” -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name llvm_openmp.ll -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version 2.20.51.0.2 -v -dwarf-column-info -resource-dir ~llvm/build/Debug+Asserts/bin/…/lib/clang/3.5.0 -fdebug-compilation-dir /usa/ashouri/phase_ordering/openmp_power -ferror-limit 19 -fmessage-length 204 -mstackrealign -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/llvm_openmp-3af5c7.o -x ir llvm_openmp.ll

clang -cc1 version 3.5.0 based upon LLVM 3.5.0 default target x86_64-unknown-linux-gnu

“/usr/bin/ld” --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/gcc/x86_64-redhat-linux/4.4.7/…/…/…/…/lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/…/…/…/…/lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/…/…/…/…/lib64 -L/lib/…/lib64 -L/usr/lib/…/lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/…/…/… -L/~/llvm/build/Debug+Asserts/bin/…/lib -L/lib -L/usr/lib /tmp/llvm_openmp-3af5c7.o -lm -L. -L/~/openmp/runtime/exports/lin_32e/lib -L~/openmp/runtime/exports/lin_32e/lib -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/…/…/…/…/lib64/crtn.o

/tmp/llvm_openmp-3af5c7.o: In function `main’:

llvm_openmp.ll:(.text+0x75): undefined reference to `__kmpc_fork_call’

/tmp/llvm_openmp-3af5c7.o: In function `.omp_microtask.’:

llvm_openmp.ll:(.text+0xf1): undefined reference to `omp_get_thread_num’

llvm_openmp.ll:(.text+0xf9): undefined reference to `omp_get_num_threads’

llvm_openmp.ll:(.text+0x101): undefined reference to `omp_get_max_threads’

llvm_openmp.ll:(.text+0x12d): undefined reference to `__kmpc_cancel_barrier’

its strange cuz when I dont invoke -emit-llvm and just compiler and link at once with clang(openmp) -fopenmp foo.c the executable can be run with max threads.

Appreciate any helps,

-Amir

I'm not super familiar with all the parts of clang, and I don't think
I've used opt directly before. I either don't call --emit-llvm to make
the binaries, or I call it just to generate the IR. I don't know how
to compile/run the human readable LLVMIR with omp runtime calls.

Amir, just add "-fopenmp" to your "clang -v llvm_openmp.ll -lm" command. Or add "-liomp5". It must solve your problems.

Best regards,
Alexey Bataev

Oh, yes, you are right Bataev. thanks a lot for the good call.

-Amir