| Issue |
173584
|
| Summary |
[Flang][OpenMP] Using WHERE construct within FORALL construct inside WORKSHARE construct may cause abnormal termination and output of incorrect result at runtime
|
| Labels |
flang:openmp
|
| Assignees |
|
| Reporter |
ohno-fj
|
```
Version of flang : 22.0.0(366f6eb607dab74b7be28d3bd72736273329d647)/AArch64
```
In the attached program (`ompv2wksh050_2.f90`), when `WHERE construct` exists within `FORALL construct` inside `WORKSHARE construct`, it may cause abnormal termination or output of incorrect result at runtime. However, it occasionally executes correctly.
As shown below, out of 10 executions, 3 resulted in abnormal termination, 2 outputted incorrect result, and 5 completed normally.
The program executes normally in the following cases:
- Remove `WORKSHARE construct`, or
(The above is `ompv2wksh050_21.f90`.)
- Remove `WHERE construct`
(The above is `ompv2wksh050_22.f90`.)
The attached log shows 10 runs after the modification. I performed an additional 100 runs, but no abnormal termination occurred.
The following are the test program, Flang, Gfortran and ifx compilation/execution results.
ompv2wksh050_2.f90:
```fortran
program main
integer,dimension(2),parameter::vs=(/1,2/)
integer,dimension(2,2)::a
a=0
!$omp parallel
!$omp workshare
forall (i=1:2)
where(a(i,vs)== 0)
a(i,vs)=-1
endwhere
endforall
!$omp end workshare
!$omp end parallel
if (any(a/=-1)) print *,'error',a
print *,'pass'
end program main
```
```
$ flang -fopenmp ompv2wksh050_2.f90
$ export OMP_NUM_THREADS=16; ./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out
fatal Fortran runtime error(/work/home/ohno/ompv2wksh050_2.f90:7): temporary-stack: out of bounds access
Aborted (core dumped)
error -1 0 -1 0
pass
error -1 0 -1 0
pass
fatal Fortran runtime error(/work/home/ohno/ompv2wksh050_2.f90:7): temporary-stack: out of bounds access
Aborted (core dumped)
pass
fatal Fortran runtime error(/work/home/ohno/ompv2wksh050_2.f90:7): temporary-stack: out of bounds access
Aborted (core dumped)
pass
pass
pass
pass
$
```
```
$ gfortran -fopenmp ompv2wksh050_2.f90
$ export OMP_NUM_THREADS=16; ./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
$
```
```
$ ifx -qopenmp ompv2wksh050_2.f90
$ export OMP_NUM_THREADS=16; ./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
$
```
ompv2wksh050_21.f90:
```fortran
program main
integer,dimension(2),parameter::vs=(/1,2/)
integer,dimension(2,2)::a
a=0
!$omp parallel
! !$omp workshare
forall (i=1:2)
where(a(i,vs)== 0)
a(i,vs)=-1
endwhere
endforall
! !$omp end workshare
!$omp end parallel
if (any(a/=-1)) print *,'error',a
print *,'pass'
end program main
```
```
$ flang -fopenmp ompv2wksh050_21.f90
$ export OMP_NUM_THREADS=16; ./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
$
```
ompv2wksh050_22.f90:
```fortran
program main
integer,dimension(2),parameter::vs=(/1,2/)
integer,dimension(2,2)::a
a=0
!$omp parallel
!$omp workshare
forall (i=1:2)
! where(a(i,vs)== 0)
a(i,vs)=-1
! endwhere
endforall
!$omp end workshare
!$omp end parallel
if (any(a/=-1)) print *,'error',a
print *,'pass'
end program main
```
```
$ flang -fopenmp ompv2wksh050_22.f90
$ export OMP_NUM_THREADS=16; ./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out;./a.out
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
$
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs