Why is the reduction in this code throwing an error:
user defined reduction not found for 'avgs'
void parallel_avg_pixel(long img[DIM_ROW][DIM_COL][DIM_RGB], long *avgs) {
int row, col, pixel;
long count = 0;
#pragma omp parallel for reduction(+:avgs)
for (row = 0; row < DIM_ROW; row++) {
for (col = 0; col < DIM_COL; col++) {
for (pixel = 0; pixel < DIM_RGB; pixel++){
avgs[pixel] += img[row][col][pixel];
count++;
}
}
}
count /= 3;
for (pixel = 0; pixel < DIM_RGB; pixel++) {
avgs[pixel] /= count;
}
}
I expected this code to make the value of avgs
private for each thread in parallel and then sum them all together at the end of execution of the for loops.
Your variable avgs
is a pointer. You can not reduce on pointers. OpenMP is telling you that if you want to reduce pointers, you need to define a reduction for them.
Ok, you're using it as an array but then the problem is OpenMP doesn't know how long it is.
Use the following syntax:
#pragma omp reduction(+:avgs[0:DIM_RGB])