llvm / llvm-project

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

[Flang][OpenMP] execution error when pointer variable with `private` attribute is output in `task` construct #71369

Open ohno-fj opened 8 months ago

ohno-fj commented 8 months ago
Version of flang-new : 18.0.0(1c876ff5155c4feeb2b2885eb3e6abda17c4b7f4)

When pointer variable with private attribute is output in task construct, execution terminates abnormally.

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

snes_task_016_2.f90:

PROGRAM main
  INTEGER, TARGET  ::A,B=0
  INTEGER, POINTER ::P
  call omp_set_num_threads(2)
  A=100
  B=50
!$OMP PARALLEL PRIVATE(P)
  P=>A
!$OMP TASK
  PRINT '("[TSK-1] P=",i3)',P
  P=>B
!$OMP END TASK
!$OMP END PARALLEL
end PROGRAM main
$ flang-new snes_task_016_2.f90 -fopenmp; ./a.out
[TSK-1] P=100
Segmentation fault
$
$ gfortran snes_task_016_.f90 -fopenmp; ./a.out
[TSK-1] P=100
[TSK-1] P=100
$
$ ifort snes_task_016_.f90 -qopenmp; ./a.out
[TSK-1] P=100
[TSK-1] P=100
$
llvmbot commented 8 months ago

@llvm/issue-subscribers-flang-frontend

Author: None (ohno-fj)

``` Version of flang-new : 18.0.0(1c876ff5155c4feeb2b2885eb3e6abda17c4b7f4) ``` When pointer variable with `private` attribute is output in `task` construct, execution terminates abnormally. The following are the test program, Flang-new, Gfortran and ifort compilation result. snes_task_016_2.f90: ```fortran PROGRAM main INTEGER, TARGET ::A,B=0 INTEGER, POINTER ::P call omp_set_num_threads(2) A=100 B=50 !$OMP PARALLEL PRIVATE(P) P=>A !$OMP TASK PRINT '("[TSK-1] P=",i3)',P P=>B !$OMP END TASK !$OMP END PARALLEL end PROGRAM main ``` ``` $ flang-new snes_task_016_2.f90 -fopenmp; ./a.out [TSK-1] P=100 Segmentation fault $ ``` ``` $ gfortran snes_task_016_.f90 -fopenmp; ./a.out [TSK-1] P=100 [TSK-1] P=100 $ ``` ``` $ ifort snes_task_016_.f90 -qopenmp; ./a.out [TSK-1] P=100 [TSK-1] P=100 $ ```
kiranchandramohan commented 8 months ago

Task privatisation is incomplete. @psoni2628 is working on this.

ohno-fj commented 8 months ago

Thank you for your comments on the development status.

luporl commented 1 week ago

The issue here seems to be that Flang is using the context of the thread executing the task region to perform the privatization. Then, if a thread executing a task region has already exited its enclosing parallel region, the data used in task's implicit firstprivate will no longer exist.

If !$OMP TASKWAIT is inserted right before !$OMP END PARALLEL then the issue doesn't occur.

@ergawy, you are planning to work on delayed privatization for tasks too, right? IIUC, it should fix this issue.