Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OpenMP with llvm-clang

So I tried to use OpenMP with one of the latest version of clang, clang version 3.4.2 (tags/RELEASE_34/dot2-final). Followed the procedure to compile and add the PATHs of omp.h, then Compiling my hello.c using :

clang -fopenmp hello.c

and then running it, still it can't use more than 1 threads:

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

P.S: I tried to manually export export OMP_NUM_THREADS=8 but that didn't solve anything as well. Any ideas?

UPDATE: 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());}
like image 443
Amir Avatar asked Nov 06 '14 23:11

Amir


1 Answers

Despite the fact that its kinda late regarding the time-stamp of my original question, but I would like to mention the answer here so at-least it saves people's time facing similar issue.

LLVM itself currently doesn't support Openmp right out-of-the-box. You can make it compile and run the omp tagged code with Intel Runtime Support. However, if you want to have a clean clang supporting OpenMP, there is a trunk of the project at OpenMP-Clang which you can clone and build. The current support is OpenMP 3.1 specification and they will reach to support OpenMP 4.0 specification soon:

$ git clone https://github.com/clang-omp/llvm_trunk llvm
$ git clone https://github.com/clang-omp/compiler-rt_trunk llvm/projects/compiler-rt
$ git clone https://github.com/clang-omp/clang_trunk llvm/tools/clang

Don't forget to build the Intel® OpenMP* Runtime Library after this as you need omp.h and /path/to/llvm/projects/openmp/runtime/lin_32e/lib/libomp.so

like image 186
Amir Avatar answered Sep 22 '22 16:09

Amir