请参阅此函数(矩阵向量积):
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
结果会导致相同的错误。)