When using openmp reduction with minus the results are added instead of
substracted.
Small test programm to verify:

#include <omp.h>

int main(int argc, char* argv[]) {
        int result = 15;

        #pragma omp parallel reduction(-:result) num_threads(4)
        {
                result += 2;
                // (1)
        }
        // (2)
}

At position (1) the variable result is 2 for each thread.
After the parallel block at position (2) it should be 7 (15-2-2-2-2) but the
value of result is 23 instead.
When I use + instead of - for the reduction clause the result is also 23.

I used the gcc version shipped with Ubuntu (gcc (Ubuntu 4.3.2-1ubuntu11)
4.3.2).


-- 
           Summary: Openmp reduction with - (minus) does not produce correct
                    result
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgomp
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebastian dot schlingmann at web dot de
  GCC host triplet: x86_64-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38935

Reply via email to