double-check DRB172-parallel-orig-no.c
chunhualiao opened this issue · 1 comments
chunhualiao commented
This code is too complex. Please reduce it further. You don't need the same statements show up 15+ times in the loop. One or two may be sufficient.
Which variables cause the tools to report data races?
loop variables j and k are shared in this code, they may cause true posive data races.
only loop variable i immediately after "omp for" will be private by some implicit rule.
I am not sure this code is really data race free.
xintin commented
As pointed by @chunhualiao, there is an obvious data race. If we use private
clause it can be fixed. We do have such examples already covered. So, I am excluding this.
Below is the simplified version of this program having the same functionality:
#include <stdio.h>
#include <omp.h>
int main(){
int i,j,k,m;
double tmp1;
double a[12][12][12];
m = 3.0;
#pragma omp parallel for private(j,k,tmp1) // use private(j,k,tmp1) to avoid data race
for (i = 0; i < 12; i++) {
for (j = 0; j < 12; j++) {
for (k = 0; k < 12; k++) {
tmp1 = 6.0/m;
a[i][j][k] = tmp1+4;
}
}
}
printf("%f\n",a[i][j][k]);
return 0;
}