http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49898
Summary: nested reduction on #pragma omp for gives incorrect result Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: markflorisso...@gmail.com The following example fails in gcc 4.5 but works in gcc 4.4. The inner loops has a reduction that is again a reduction in the outer loop. The result should be 450, but is always 0. If you put the reduction() clauses on the #pragma omp parallel it does work. ##################################### The code SSH [0] [10:23] ~ ➤ gcc-4.5 -g -Wall -fopenmp -lgomp testomp.c SSH [0] [10:24] ~ ➤ ./a.out sum = 0 SSH [0] [10:24] ~ ➤ gcc-4.4 -g -Wall -fopenmp -lgomp testomp.c SSH [0] [10:24] ~ ➤ ./a.out sum = 450 SSH [0] [10:24] ~ ➤ cat testomp.c #include <stdio.h> int main(void) { int i, j, sum = 0; #pragma omp parallel { #pragma omp for reduction(+:sum) for (i = 0; i < 10; i++) { #pragma omp parallel { #pragma omp for reduction(+:sum) for (j = 0; j < 10; j++) { sum += j; } } } } printf("sum = %d\n", sum); return 0; }