我使用openMP parallel for reduction子句在并行线程中对两个变量(area_inner_grain_total and perimeter_total)
求和。代码如下:
void lagrange_multiplier(const mat &LV_Psi, double
&area_inner_grain_total, double &lagrange_multiplier_vol_constr)
{
mat dirac_delta;
get_dirac_delta(LV_Psi, dirac_delta);
mat LV_heaviside_fn;
get_Heavyside_function(LV_Psi, LV_heaviside_fn);
area_inner_grain_total = 0.0;
double perimeter_total = 0.0;
for (int i = 0; i < LV_Num_Grid_Points; i++)
{
#pragma omp parallel for reduction(+:area_inner_grain_total,perimeter_total)
for (int j = 0; j < LV_Num_Grid_Points; j++)
{
area_inner_grain_total += (double)(LV_heaviside_fn(i,j) * LV_h * LV_h);
perimeter_total += (double)(dirac_delta(i,j) * LV_h * LV_h);
}
}
lagrange_multiplier_vol_constr = (double((-area_inner_grain_total+initial_area)/perimeter_total);
}
然而,我收到错误:
'area_inner_grain_total'在行中有'减少'的无效类型 #pragma omp parallel for reduction(+:area_inner_grain_total,perimeter_total)
OpenMP文档说我可以使用任何标量变量并使用reduction子句轻松执行 + 操作。为什么我收到此错误?这有什么不对?