llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.21k stars 11.14k forks source link

[Flang][OpenMP] Execution error (Segmentation fault) when an allocatable array is used in task construct with a firstprivate clause in a parallel construct with a private clause #86621

Open ohno-fj opened 4 months ago

ohno-fj commented 4 months ago
Version of flang-new : 19.0.0(cbcdf126ccc774c063b5d5140c1393ff5305dded)/AArch64

When an allocatable array is used in task construct with a firstprivate clause in a parallel construct with a private clause, the execution terminates abnormally (Segmentation fault).

Execution terminates normally in the following cases:

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

omp3_task_firstprivate_013_232.f90:

program main
  integer(4),allocatable::a(:)
  allocate(a(10))
  a(9)=100
!$omp parallel private(a)
!$omp task firstprivate(a)
  a(9)=10
!$omp end task
!$omp end parallel
  write(6,*) "a(9) = ", a(9)
end program main
$ export OMP_NUM_THREADS=2; flang-new -fopenmp omp3_task_firstprivate_013_232.f90; ./a.out
Segmentation fault (core dumped)
$
$ export OMP_NUM_THREADS=2; gfortran -fopenmp omp3_task_firstprivate_013_232.f90; ./a.out
 a(9) =          100
$
$ export OMP_NUM_THREADS=2; ifort -qopenmp -diag-disable=10448 omp3_task_firstprivate_013_232.f90; ./a.out
 a(9) =          100
$
llvmbot commented 4 months ago

@llvm/issue-subscribers-openmp

Author: None (ohno-fj)

``` Version of flang-new : 19.0.0(cbcdf126ccc774c063b5d5140c1393ff5305dded)/AArch64 ``` When an `allocatable` array is used in `task` construct with a `firstprivate` clause in a `parallel` construct with a `private` clause, the execution terminates abnormally (Segmentation fault). Execution terminates normally in the following cases: - Array (a) is not an `allocatable` array, or - Do not write `task` construct The following are the test program, Flang-new, Gfortran and ifort compilation/execution result. omp3_task_firstprivate_013_232.f90: ```fortran program main integer(4),allocatable::a(:) allocate(a(10)) a(9)=100 !$omp parallel private(a) !$omp task firstprivate(a) a(9)=10 !$omp end task !$omp end parallel write(6,*) "a(9) = ", a(9) end program main ``` ``` $ export OMP_NUM_THREADS=2; flang-new -fopenmp omp3_task_firstprivate_013_232.f90; ./a.out Segmentation fault (core dumped) $ ``` ``` $ export OMP_NUM_THREADS=2; gfortran -fopenmp omp3_task_firstprivate_013_232.f90; ./a.out a(9) = 100 $ ``` ``` $ export OMP_NUM_THREADS=2; ifort -qopenmp -diag-disable=10448 omp3_task_firstprivate_013_232.f90; ./a.out a(9) = 100 $ ```
luporl commented 4 weeks ago

This issue probably has the same root cause as #71369. It doesn't occur if !$omp taskwait is inserted before !$omp end parallel.