看到這個函數(矩陣,向量積):OpenMP:'共享'的預定'共享'?
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;
}
當試圖使用OpenMP編譯,編譯器失敗:
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
有什麼不對嗎?
(請注意,簡單地移除const
結果在相同的錯誤。)
我編譯你的函數沒有問題,使用'g ++ 4.6.3'。 – Massimiliano
我正在使用'i686-apple-darwin11-llvm-gcc-4.2'。這可能是這個編譯器版本的問題。我正在嘗試升級到gcc 4.7 – clstaudt
@ cls:我在開玩笑。我不使用OpenMP,所以從未見過這個GCC錯誤。所以你得到了一個贊成,只是爲了給我一個新的GCC錯誤(你並不是真的)。 –