I'm not sure what's happening here.
It can be the case that you compiled with a stub OpenMP library, which provides all the OpenMP library API, but only acting as if sequential mode (see this link for example for the corresponding Intel compiler switch).
Another possibility is that the OMP_THREAD_LIMIT
environment variable is set to 1
in your environment. See for example this code:
#include <iostream>
#include <omp.h>
int main() {
omp_set_num_threads(8);
#pragma omp parallel
#pragma omp single
std::cout << "Number of threads in the current parallel region is " << omp_get_num_threads() << std::endl;
return 0;
}
When compiled with OpenMP support and run, it gives me:
$ g++ -fopenmp nbthreads.cc -o nbthreads
$ ./nbthreads
Number of threads in the current parallel region is 8
$ OMP_THREAD_LIMIT=1 ./nbthreads
Number of threads in the current parallel region is 1
Aside from these two possibilities, I've no idea.
Edit: thanks to Z boson's
comment, I'm pretty sure I've got the key of the mystery.
With the very same code as the hereabove one, here is what I've got:
$ g++ -o nbthreads nbthreads.cc -lgomp
$ ./nbthreads
Number of threads in the current parallel region is 1
So you simply mistakenly used -lgomp
instead of -fopenmp
while compiling / linking your code. This gives you an OpenMP code equivalent to having only 1 thread, even if you explicitly ask for more.