This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/49898] New: nested reduction on #pragma omp for gives incorrect result


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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]