This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/49898] New: nested reduction on #pragma omp for gives incorrect result
- From: "markflorisson88 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 29 Jul 2011 08:27:44 +0000
- Subject: [Bug c/49898] New: nested reduction on #pragma omp for gives incorrect result
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: markflorisson88@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;
}