I'm trying to vectorise a nested loop with #pragma omp simd, but the inner loop has a reduction in it. Is there any way to do this?
#pragma omp simd collapse(2) reduction(+:total[i])
for (int i=0; i<N; i++){
for (int j=0; j<N; j++){
float distance = sqrt(
(x[i][0]-x[j][0]) * (x[i][0]-x[j][0]) +
(x[i][1]-x[j][1]) * (x[i][1]-x[j][1]) +
(x[i][2]-x[j][2]) * (x[i][2]-x[j][2])
);
total[i] += distance;
}
}
at the moment, it just gives this error when compiling:
error: identifier "i" is undefined
#pragma omp simd collapse(2) reduction(+:total[i])
^