[Flang][OpenMP] Incorrect execution result of a firstprivate variable in parallel construct
Version of flang-new : 18.0.0(770dc47659d41a5ca7b7daf5b3134c900ca8c33d)
The value of a firstprivate variable (a) in parallel construct executed by each thread is incorrect.
The following write statement expects that the value of variable (a) is 200 for all threads.
write(6,*) "2 : a = ", a
The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.
sngf_firstprivate11_42.f90:
subroutine sub4()
integer :: a = 100
!$omp parallel reduction(max:a)
a = 200
!$omp parallel firstprivate(a)
if (a/=200) print *,14,a
a = 300
!$omp end parallel
write(6,*) "2 : a = ", a
if (a/=200) print *,24,a
a = 400
!$omp end parallel
write(6,*) "3 : a = ", a
end subroutine sub4
program main
call sub4
end program main
$ export OMP_NUM_THREADS=2; flang-new -fopenmp sngf_firstprivate11_42.f90; ./a.out
2 : a = 200
2 : a = 400
24 400
3 : a = 400
$
$ export OMP_NUM_THREADS=2; gfortran -fopenmp sngf_firstprivate11_42.f90; ./a.out
2 : a = 200
2 : a = 200
3 : a = 400
$
$ export OMP_NUM_THREADS=2; ifort -qopenmp sngf_firstprivate11_42.f90; ./a.out
2 : a = 200
2 : a = 200
3 : a = 400
$
@llvm/issue-subscribers-openmp
Author: None (ohno-fj)
The following write statement expects that the value of variable (a) is 200 for all threads.
write(6,*) "2 : a = ", a
The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.
sngf_firstprivate11_42.f90:
subroutine sub4()
integer :: a = 100
!$omp parallel reduction(max:a)
a = 200
!$omp parallel firstprivate(a)
if (a/=200) print *,14,a
a = 300
!$omp end parallel
write(6,*) "2 : a = ", a
if (a/=200) print *,24,a
a = 400
!$omp end parallel
write(6,*) "3 : a = ", a
end subroutine sub4
program main
call sub4
end program main
$ export OMP_NUM_THREADS=2; flang-new -fopenmp sngf_firstprivate11_42.f90; ./a.out
2 : a = 200
2 : a = 400
24 400
3 : a = 400
$
$ export OMP_NUM_THREADS=2; gfortran -fopenmp sngf_firstprivate11_42.f90; ./a.out
2 : a = 200
2 : a = 200
3 : a = 400
$
$ export OMP_NUM_THREADS=2; ifort -qopenmp sngf_firstprivate11_42.f90; ./a.out
2 : a = 200
2 : a = 200
3 : a = 400
$
This seems to work alrite. Could @ohno-fj or @luporl check and close if it is fine?
This is fixed.