c++ - Parallel OpenMP reduction vs. function definition? -
i'm using openmp problem i'm declaring/defining function follow:
void compute_image(double pixel[nb], double &sum) { #pragma omp parallel reduction(+:sum) (int j=0;j<640;j++) { if ... sum=sum+pixel[0]; .... } .... } what realise :
error 2 error c3030: 'sum' : variable in 'reduction' clause/directive cannot have reference type c:\users...\test.cpp 930 actually, cannot rid of openmp. solution?
instead of reduction, put sum=sum+pixel[0] under #pragma omp atomic or #pragma omp critical line.
another option have double local_sum = sum; before omp section, reduce on local_sum, , have sum = local_sum; after loop.
Comments
Post a Comment