Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang + OpenMP on Linux uses only 1 CPU core

Tags:

clang

openmp

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 during runtime the code uses 4 cores:

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

If I compile it with clang++3.7 then during runtime the code uses only 1 core:

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

In both cases I have set:

OMP_NUM_THREADS=4

Both compilers have been installed from the Debian Testing repository:

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

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

like image 219
AstrOne Avatar asked Sep 21 '15 13:09

AstrOne


1 Answers

See this:

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

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

like image 58
Gilles Avatar answered Oct 20 '22 15:10

Gilles