AstrOne
AstrOne

Reputation: 3769

Clang + OpenMP on Linux uses only 1 CPU 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 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.

Upvotes: 6

Views: 1156

Answers (1)

Gilles
Gilles

Reputation: 9499

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.

Upvotes: 6

Related Questions