llvm / llvm-project

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

[Flang][OpenMP] Incorrect execution result when an if clause is specified for a dependent task in a sibling task that has a task dependency #91926

Closed ohno-fj closed 1 month ago

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

In sibling tasks that have task dependence, when an if clause (the result is .false.) is specified for a dependent task, the execution result is incorrect.

The result is correct when line 27 of the program is changed as follows:

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

taskdepend_054_2231.f90:

module taskdepend_mod
  integer, parameter :: ans=1
contains
  subroutine init(x)
    integer :: x
    x = 2
  end subroutine init
  subroutine test(x)
    integer :: x
    if (x .ne. ans) then
       print *, "NG"
    else
       print *, "OK"
    end if
  end subroutine test
end module taskdepend_mod

program main
  use taskdepend_mod
  integer :: x
  call init(x)
!$omp parallel
!$omp single
!$omp task shared(x) depend(out: x)
  x = x - 1
!$omp end task
!$omp task shared(x) depend(in: x) if(x .eq. 0) ! if(.false.)
  call test(x)
!$omp end task
!$omp end single
!$omp end parallel
end program main
$ export OMP_NUM_THREADS=2; flang-new -fopenmp taskdepend_054_2231.f90; ./a.out
 NG
$
$ export OMP_NUM_THREADS=2; gfortran -fopenmp taskdepend_054_2231.f90; ./a.out
 OK
$
$ export OMP_NUM_THREADS=2; ifort -qopenmp -diag-disable=10448 taskdepend_054_2231.f90; ./a.out
 OK
$
llvmbot commented 4 months ago

@llvm/issue-subscribers-openmp

Author: None (ohno-fj)

``` Version of flang-new : 19.0.0(1a498103ee5c4d101e70dc49db11938d8b87b518)/AArch64 ``` In `sibling tasks` that have `task dependence`, when an `if` clause (the result is .false.) is specified for a `dependent task`, the execution result is incorrect. The result is correct when line 27 of the program is changed as follows: - Change `scalar-logical-expression` result specified in `if` clause from .false. to .true. ``` !$omp task shared(x) depend(in: x) if(x .ne. 0) ! if(.true.) ``` - Delete the `if` clause ``` !$omp task shared(x) depend(in: x) ! no if clause ``` The following are the test program, Flang-new, Gfortran and ifort compilation/execution result. taskdepend_054_2231.f90: ```fortran module taskdepend_mod integer, parameter :: ans=1 contains subroutine init(x) integer :: x x = 2 end subroutine init subroutine test(x) integer :: x if (x .ne. ans) then print *, "NG" else print *, "OK" end if end subroutine test end module taskdepend_mod program main use taskdepend_mod integer :: x call init(x) !$omp parallel !$omp single !$omp task shared(x) depend(out: x) x = x - 1 !$omp end task !$omp task shared(x) depend(in: x) if(x .eq. 0) ! if(.false.) call test(x) !$omp end task !$omp end single !$omp end parallel end program main ``` ``` $ export OMP_NUM_THREADS=2; flang-new -fopenmp taskdepend_054_2231.f90; ./a.out NG $ ``` ``` $ export OMP_NUM_THREADS=2; gfortran -fopenmp taskdepend_054_2231.f90; ./a.out OK $ ``` ``` $ export OMP_NUM_THREADS=2; ifort -qopenmp -diag-disable=10448 taskdepend_054_2231.f90; ./a.out OK $ ```
tblah commented 1 month ago

This appears to be working for me now. @ohno-fj please could you confirm

ohno-fj commented 1 month ago

@tblah, thank you for your reply Using the latest flang-new, I could confirm that it was fixed. I close this issue.

$ flang-new --version
flang-new version 20.0.0git (https://github.com/llvm/llvm-project.git 357bd61744bb8cc2b9b07447294fa977e5758550)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/groups/ssoft/compiler/llvm/aarch64/main-20240902-357bd61744bb/bin
Build config: +assertions
$
$ export OMP_NUM_THREADS=2; flang-new -fopenmp taskdepend_054_2231.f90; ./a.out
 OK
$