Clang + OpenMP on Linux uses only 1 processor core

I have the following code:

int main(int argc, char** argv) { const int64_t N = 10000000000; float* data = new float[N]; int64_t i; omp_set_dynamic(0); omp_set_num_threads(4); #pragma omp parallel for for(i = 0; i < N; ++i) data[i] = i*i; return 0; } 

If I compile it with g ++, then at runtime the code uses 4 cores:

 g++ -fopenmp -std=c++11 main.cpp 

If I compile it with clang ++ 3.7, then only 1 core is used at runtime:

 clang++-3.7 -fopenmp -std=c++11 main.cpp 

In both cases, I installed:

 OMP_NUM_THREADS=4 

Both compilers were installed from the Debian testing repository:

 sudo apt-get install g++-5 sudo apt-get install clang-3.7 

So, any ideas why clang uses only one core? Thanks in advance.

+6
source share
1 answer

See this :

OpenMP 3.1 is fully supported, but disabled by default. To enable it, use the -fopenmp = libomp command line option.

It looks like you missed -fopenmp=libomp in your compilation flags.

+5
source

All Articles