From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 485053858D1E; Tue, 2 May 2023 17:07:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 485053858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683047259; bh=bzAYpZwwi9PXvjeX2W3zSYGePJT+arcY6xlOG/Xs/dY=; h=From:To:Subject:Date:From; b=nLSAOAS38Rm7qjvf4RB9GsYnMMx7Sjhk5btf1J55uc+AH/geS8Zn5BQPQADRRfWJb rFV31N47km/LVSpJPeHUo7wRu+RyQgj8zsHUv7oIv1s88kpLsbh2c57dtpje71F9MX pPtMhvMO8Lktyr5/EJB15neQ8E6sRTauaTh9UAfc= From: "thomas.meltzer1 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/109701] New: I have a MWE where an omp reduction breaks if I add the option for GPU offloading (even if it isn't used). Date: Tue, 02 May 2023 17:07:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: thomas.meltzer1 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109701 Bug ID: 109701 Summary: I have a MWE where an omp reduction breaks if I add the option for GPU offloading (even if it isn't used). Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: thomas.meltzer1 at gmail dot com Target Milestone: --- Created attachment 54972 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D54972&action=3Dedit source code to reproduce bug I think I have identified a bug when using gfortran and openMP. I have test= ed on gfortran versions: * gfortran 10.3.0 * gfortran 11.3.0 * gfortran 12.2.0 I have posted a question on stackoverflow: https://stackoverflow.com/questions/76119137/potential-gfortran-or-openmp-b= ug-when-using-omp-if-and-reduction Here is mwe: ----------------------------------- program test use omp_lib implicit none integer, parameter :: N=3D3=20 integer :: i, j real :: a(N,N), b(N,N), max_diff logical :: is_GPU is_GPU =3D .false. #ifdef USEGPU is_GPU =3D .true. #endif !$omp target data if(is_GPU) map(to:a, b) !$omp target teams if(is_GPU) !$omp distribute parallel do simd collapse(2) do j =3D 1, N do i =3D 1, N a(i, j) =3D i*j=20 b(i, j) =3D i*j*0.9 end do end do !$omp end target teams max_diff =3D 0.0=20 !$omp target teams if(is_GPU) !<---- comment this !$omp distribute parallel do simd reduction(max:max_diff) collapse(2) do j =3D 1, N do i =3D 1, N max_diff =3D max(max_diff, abs(b(i, j) - a(i, j))) end do end do !$omp end target teams !<---- comment this write (*,'("max_diff =3D ", F6.3)') max_diff !$omp end target data end program ----------------------------------- Here is the command to compile and run: gfortran -cpp -fopenmp mwe.f90 && OMP_NUM_THREADS=3D2 ./a.out I have also tried with extra flags (-Wall -Wextra) and there are no reported warnings. Expected output is: max_diff =3D 0.900 but with gfortran I get: max_diff =3D 0.000 It works with nvfortran 22.5-0 (from nvhpc toolkit) but not for gfortran. Command for nvfortran is: nvfortran -cpp -mp=3Dmulticore mwe.f90 && OMP_NUM_THREADS=3D2 ./a.out I want to keep portability so that openMP handles whether I build with GPU = or not. I am aware I can workaround it without openMP "if" statements and inst= ead use pre-processor directives. If I comment out the lines marked with (!<---- comment this) and remove "distribute" from the line "!$omp distribute parallel do simd reduction(max:max_diff) collapse(2)" then the code runs as expected. Am I mis-using the openMP if statements or doing something else which is not portable or is this a bug? Please let me know if you need any further information. gfortran -v 11.3.0 output: Using built-in specs. COLLECT_GCC=3Dgfortran COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper OFFLOAD_TARGET_NAMES=3Dnvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=3D1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Ubuntu 11.3.0-1ubuntu1~22.04' --with-bugurl=3Dfile:///usr/share/doc/gcc-11/README.= Bugs --enable-languages=3Dc,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix= =3D/usr --with-gcc-major-version-only --program-suffix=3D-11 --program-prefix=3Dx86_64-linux-gnu- --enable-shared --enable-linker-build-= id --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --libdir=3D/usr/lib --enable-nls --enable-bootstrap --enable-clocale=3Dgnu --enable-libstdcxx-debug --enable-libstdcxx-time=3Dyes --with-default-libstdcxx-abi=3Dnew --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-= zlib --enable-libphobos-checking=3Drelease --with-target-system-zlib=3Dauto --enable-objc-gc=3Dauto --enable-multiarch --disable-werror --enable-cet --with-arch-32=3Di686 --with-abi=3Dm64 --with-multilib-list=3Dm32,m64,mx32 --enable-multilib --with-tune=3Dgeneric --enable-offload-targets=3Dnvptx-none=3D/build/gcc-11-xKiWfi/gcc-11-11.3.0/= debian/tmp-nvptx/usr,amdgcn-amdhsa=3D/build/gcc-11-xKiWfi/gcc-11-11.3.0/deb= ian/tmp-gcn/usr --without-cuda-driver --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linux-gnu --with-build-config=3Dbootstrap-lto-lean --enable-link-serialization=3D2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)=20 gfortran -v 12.2.0 output: Reading specs from /software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/gcc-12.2.0-7= szeaw2tk7ndv3brjeitsqmi3r6cz2sx/lib/gcc/x86_64-pc-linux-gnu/12.2.0/specs COLLECT_GCC=3Dgfortran COLLECT_LTO_WRAPPER=3D/software/spack/opt/spack/linux-ubuntu22.04-skylake/g= cc-11.3.0/gcc-12.2.0-7szeaw2tk7ndv3brjeitsqmi3r6cz2sx/libexec/gcc/x86_64-pc= -linux-gnu/12.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /tmp/melt/spack-stage/spack-stage-gcc-12.2.0-7szeaw2tk7ndv3brjeitsqmi3r6cz2= sx/spack-src/configure --prefix=3D/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/g= cc-12.2.0-7szeaw2tk7ndv3brjeitsqmi3r6cz2sx --with-pkgversion=3D'Spack GCC' --with-bugurl=3Dhttps://github.com/spack/spack/issues --disable-multilib --enable-languages=3Dc,c++,fortran --disable-nls --disable-canonical-system-headers --with-system-zlib --with-zstd-include=3D/software/spack/opt/spack/linux-ubuntu22.04-skylake/g= cc-11.3.0/zstd-1.5.2-4lqnadoditk6uhithspv7gaaleqkkzxs/include --with-zstd-lib=3D/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-1= 1.3.0/zstd-1.5.2-4lqnadoditk6uhithspv7gaaleqkkzxs/lib --enable-bootstrap --with-mpfr-include=3D/software/spack/opt/spack/linux-ubuntu22.04-skylake/g= cc-11.3.0/mpfr-4.1.0-3htwy6gdcb5iwcr6jpbev5yiltdjejfy/include --with-mpfr-lib=3D/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-1= 1.3.0/mpfr-4.1.0-3htwy6gdcb5iwcr6jpbev5yiltdjejfy/lib --with-gmp-include=3D/software/spack/opt/spack/linux-ubuntu22.04-skylake/gc= c-11.3.0/gmp-6.2.1-oc47phqrmnbll7y5xd5mgcffuy4uwewd/include --with-gmp-lib=3D/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11= .3.0/gmp-6.2.1-oc47phqrmnbll7y5xd5mgcffuy4uwewd/lib --with-mpc-include=3D/software/spack/opt/spack/linux-ubuntu22.04-skylake/gc= c-11.3.0/mpc-1.2.1-7bswqqwsnkfwa6ojrkdhxveumijpchhz/include --with-mpc-lib=3D/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11= .3.0/mpc-1.2.1-7bswqqwsnkfwa6ojrkdhxveumijpchhz/lib --without-isl --with-stage1-ldflags=3D'-Wl,-rpath,/software/spack/opt/spack/linux-ubuntu2= 2.04-skylake/gcc-11.3.0/gcc-12.2.0-7szeaw2tk7ndv3brjeitsqmi3r6cz2sx/lib -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/g= cc-12.2.0-7szeaw2tk7ndv3brjeitsqmi3r6cz2sx/lib64 -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/g= mp-6.2.1-oc47phqrmnbll7y5xd5mgcffuy4uwewd/lib -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/m= pc-1.2.1-7bswqqwsnkfwa6ojrkdhxveumijpchhz/lib -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/m= pfr-4.1.0-3htwy6gdcb5iwcr6jpbev5yiltdjejfy/lib -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/z= lib-1.2.13-kxewaohczdviv3z3yz2a45g3kwpd45yh/lib -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/z= std-1.5.2-4lqnadoditk6uhithspv7gaaleqkkzxs/lib' --with-boot-ldflags=3D'-Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.= 04-skylake/gcc-11.3.0/gcc-12.2.0-7szeaw2tk7ndv3brjeitsqmi3r6cz2sx/lib -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/g= cc-12.2.0-7szeaw2tk7ndv3brjeitsqmi3r6cz2sx/lib64 -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/g= mp-6.2.1-oc47phqrmnbll7y5xd5mgcffuy4uwewd/lib -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/m= pc-1.2.1-7bswqqwsnkfwa6ojrkdhxveumijpchhz/lib -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/m= pfr-4.1.0-3htwy6gdcb5iwcr6jpbev5yiltdjejfy/lib -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/z= lib-1.2.13-kxewaohczdviv3z3yz2a45g3kwpd45yh/lib -Wl,-rpath,/software/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-11.3.0/z= std-1.5.2-4lqnadoditk6uhithspv7gaaleqkkzxs/lib -static-libstdc++ -static-libgcc' --with-build-config=3Dspack Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.2.0 (Spack GCC)=