I am trying to compute mean of a 2d matrix using openmp. This 2d matrix is actually an image.
I am doing the thread-wise division of data. For example, if I have
In your case, the sum = sum + val could interpreted as val[i] = val[i-1] + val[i] in 1-d array (or val[rows][cols] = val[rows][cols-1] + val[rows][cols] in 2-d array) which is a prefix sum calculation.
Reduction is one of solution for prefix sum, you can use reduction to any commutative-associative operators like '+', '-', '*', '/'.