0
我使用OpenMP,但問題是,我聲明/定義一個函數如下:並行OpenMP減少與功能定義?
void compute_image(double pixel[nb], double &sum)
{
#pragma omp parallel for reduction(+:sum)
for (int j=0;j<640;j++)
{
if ...
sum=sum+pixel[0];
....
}
....
}
我現在知道的是,:
Error 2 error C3030: 'sum' : variable in 'reduction' clause/directive cannot have reference type C:\Users...\test.cpp 930
其實,我無法擺脫的OpenMP。 任何解決方案?
使用第二個選項(local_sum)可能會比使用「omp atomic」或「omp critical」更好,因爲reduction子句允許每個線程都有其自己的本地版本local_sum。使用「comp critical」強制線程等待更新總和,並使用「omp atomic」使線程爭奪相同的內存位置。 – 2013-05-14 16:27:52