llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Issue]: flang-new: do concurrent (host) reduction gives incorrect result.

Open RJaBi opened this issue 11 months ago • 1 comments

Problem Description

I was having some issues with do-concurrent giving wrong results on the host with some more complicated code. I reduced it down to the below which just does a sum within a do-concurrent with a reduction.

There's a reduction for an int and one for a real. In the real code, there's some actual work done here, but for this minimal example, I just add 1 each iteration.

I can compile with amdflang-new -g -O0 -fopenmp -fdo-concurrent-parallel=host

and the numbers it produces are different each time. The correct answer is given by

amdflang-new -g -O0 -fopenmp -fdo-concurrent-parallel=none

program superMWE
  use iso_c_binding, only: C_DOUBLE
  implicit none(external)
  integer, parameter :: WP=C_DOUBLE
  ! set up size
  integer :: NX, NY, NZ, NT
  ! counters
  integer :: nnt, nnx, nny, nnz
  ! sum
  real(kind=WP) :: sumTrP
  integer :: nP
  NX = 32
  NY = 32
  NZ = 32
  NT = 8
  nP = 0
  sumTrP = 0.0_WP
  do concurrent(nnx=1:nx, nny=1:ny, nnz=1:nz, nnt=1:nt) reduce(+:sumTrP, nP)
         sumTrP = sumTrP + 1.0_WP
         nP = nP + 1
   end do
   write(*,*) 'Done', sumTrP, nP
end program superMWE

Operating System

Ubuntu 22.04.5 LTS (Jammy Jellyfish)

CPU

13th Gen Intel(R) Core(TM) i5-13500

GPU

Not applicable

ROCm Version

rocm-afar-7110-drop-5.3.0

ROCm Component

flang

Steps to Reproduce

No response

(Optional for Linux users) Output of /opt/rocm/bin/rocminfo --support

No response

Additional Information

No response

RJaBi avatar Feb 27 '25 15:02 RJaBi