Issue 181270
Summary [Flang][OpenMP] The earlier DECLARE REDUCTION declaration within a different scope takes precedence, so the execution result is incorrect
Labels flang:openmp
Assignees
Reporter ohno-fj
    ```
Version of flang : 23.0.0(a563e6bb7ed485e0ab88717bb4a8c5e8522d9792)/AArch64
```

According to `OpenMP 6.0 : 7.6.14 declare_reduction Directive`, `the visibility and accessibility of a user-defined reduction are the same as those of a variable declared at the same location in the program.`

However, as seen in the attached program (`sngg487e_22.f90`), it appears that the declaration of the `DECLARE REDUCTION directive` takes effect not only within the same scope in the program, but also within a different scope. This results in incorrect execution results being output.

The following are the test program, Flang, Gfortran and ifx compilation/execution results.

sngg487e_22.f90:
```fortran
module m
contains
  subroutine dummy
!$omp declare reduction (a:integer:omp_out=omp_out+omp_in) initializer(omp_priv=10000)
  end subroutine dummy

  subroutine test
!$omp declare reduction (a:integer:omp_out=omp_out+omp_in) initializer(omp_priv=0)
    integer::x1,i
    x1=0
!$omp parallel do reduction(a:x1)
    do i=1,10
       x1=x1+1
    end do
!$omp end parallel do
    write(6,*) "x1 = ", x1
  end subroutine test
end module m

program main
  use m
  implicit none
  call test()
end program main
```

```
$ export OMP_NUM_THREADS=2; flang -fopenmp sngg487e_22.f90; ./a.out
 x1 =  20010
$
```

```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp sngg487e_22.f90; ./a.out
 x1 =           10
$
```

```
$ export OMP_NUM_THREADS=2; ifx -qopenmp sngg487e_22.f90; ./a.out
 x1 = 10
$
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to