OpenMP: predefined "jointly" for "common"?
See this function (matrix-vector product):
std::vector<double> times(std::vector<std::vector<double> > const& A, std::vector<double> const& b, int m, int n) { std::vector<double> c; c.resize(n); int i, j; double sum; #pragma omp parallel for default(none) private(i, j, sum) shared(m, n, A, b, c) for (i = 0; i < m; ++i) { sum = 0.0; for (j = 0; j < n; j++) { sum += A[i][j] * b[j]; } c[i] = sum; } return c; } When trying to compile this using OpenMP, the compiler will fail:
Invoking: GCC C++ Compiler g++ -O0 -g3 -Wall -c -fmessage-length=0 -fopenmp -MMD -MP -MF"src/OpemMPTutorial.d" -MT"src/OpemMPTutorial.d" -o "src/OpemMPTutorial.o" "../src/OpemMPTutorial.cpp" ../src/OpemMPTutorial.cpp:127: warning: ignoring #pragma omp end ../src/OpemMPTutorial.cpp: In function 'std::vector<double, std::allocator<double> > times(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<double, std::allocator<double> >&, int, int)': ../src/OpemMPTutorial.cpp:200: error: 'b' is predetermined 'shared' for 'shared' ../src/OpemMPTutorial.cpp:200: error: 'A' is predetermined 'shared' for 'shared' make: *** [src/OpemMPTutorial.o] Error 1 What is wrong here?
(Note that simply removing const results in the same error.)
This is due to insufficient OpenMP support in gcc-4.2. The code component compiles without problems using gcc-4.7.
I had a very similar problem, and I experienced that such a program can be compiled with Apples GCC 4.2 after removing the const variables from the shared section of the OpenMP directive. They are predefined as generic because they are persistent and there is no need to make a copy for each thread. And the compiler doesn't seem to just accept it explicitly when it already knows ...
I will also remove the default(none) specification (but see the comment below ). OpenMP is designed to reduce explicit specifications, so let it do its job.