https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77758

            Bug ID: 77758
           Summary: OpenMP sections: intermittent incorrect behavior in
                    reduction
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andrey.vul at gmail dot com
  Target Milestone: ---

gcc -fopenmp t.c && ./a.out; echo $? on the following file produces unexpected
values.

t.c:

#define aN 2
int main(int argc, char *argv[]) {
        int a[aN];
        long b = 0;
        for (int i = 0; i < aN; ++i)
                a[i] = i + 1;

        #pragma omp parallel
        #pragma omp sections reduction(+:b)
        {
                #pragma omp section
                {       b = a[0];       }
                #pragma omp section
                {       b = a[1];       }
        }

        return (a[0]+a[1])-b;
}

A non-zero return code indicates invalid reduction between sections.

The separate parallel and sections directives produce a fail rate of 90+%.
When the parallel and sections directions are combined, ie (#pragma omp
parallel sections reduction(+:b)), the fail rate drops to ~2%.

Rates were calculated from running the produced executable 1000 times and
watching how many times a non-zero return was calculated.

As the non-zero return code is exclusively 1, it appears that instead of
reduction, the second sections block executes sequentially after the first
sections block in the same task, as opposed to parallel tasks then reduction
between the final values in each task, as is expected of reduction.

gcc -v:
Using built-in specs.
COLLECT_GCC=gcc-6.2.0
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/6.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-6.2.0/work/gcc-6.2.0/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/6.2.0
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.0/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/6.2.0
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/6.2.0/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/6.2.0/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.0/include/g++-v6
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/6.2.0/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--enable-checking=release --with-bugurl=https://bugs.gentoo.org/
--with-pkgversion='Gentoo 6.2.0 p1.0' --disable-esp --enable-libstdcxx-time
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64
--disable-altivec --disable-fixed-point --enable-targets=all --disable-libgcj
--enable-libgomp --disable-libmudflap --disable-libssp --enable-libcilkrts
--disable-libmpx --enable-vtable-verify --enable-libvtv --enable-lto --with-isl
--disable-isl-version-check --enable-libsanitizer --disable-default-pie
--disable-default-ssp
Thread model: posix
gcc version 6.2.0 (Gentoo 6.2.0 p1.0)

Reply via email to