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] Issues in copyprivate #86907

Open harishch4 opened 4 months ago

harishch4 commented 4 months ago

Here is a list of test cases that are failing in flang-new but are working in other compilers. Godbolt link

subroutine test1
    use omp_lib
    implicit none
    character xz
    common/c/xz
    !$omp threadprivate(/c/)
    !$omp parallel num_threads(4)
        !$omp single
        xz = 'c'
        !$omp end single copyprivate(/c/)
    !$omp end parallel
end

error: COMMON block must be declared in the same scoping unit in which the OpenMP directive or clause appears
          !$omp end single copyprivate(/c/)
!fails in gfortran but all other compilers accepting this

subroutine test2
    real z
    !$omp parallel private(z) num_threads(2)
    !$omp single
        z = -2
    !$omp end single copyprivate(z,z)
    !$omp end parallel
end 
subroutine test3
    use omp_lib
    !$omp parallel private(xz) num_threads(2)
    xz = f()
    !$omp end parallel
contains
    function f() result(rz)
        !$omp single
        rz = 42
        !$omp end single copyprivate(rz)
    end function
end subroutine

error: COPYPRIVATE variable 'rz' is not PRIVATE or THREADPRIVATE in outer context
          !$omp end single copyprivate(rz)
                                       ^^
subroutine test4
    use omp_lib
    implicit none
    call test
contains
    subroutine test
        real, pointer :: xz
        !$omp parallel private(xz) num_threads(2)
        xz => fz()
        !$omp end parallel
    end subroutine
    function fz()
        real, pointer :: fz
        nullify (fz)
        !$omp single
        allocate (fz)
        fz = 42
        !$omp end single copyprivate(fz)
    end function
end subroutine

 error: COPYPRIVATE variable 'fz' is not PRIVATE or THREADPRIVATE in outer context
          !$omp end single copyprivate(fz)
                                       ^^
luporl commented 3 months ago

https://github.com/llvm/llvm-project/pull/88430 was merged, fixing test1.

llvmbot commented 3 months ago

@llvm/issue-subscribers-flang-frontend

Author: None (harishch4)

Here is a list of test cases that are failing in flang-new but are working in other compilers. Godbolt [link](https://godbolt.org/z/b3hKvKjEj) ``` subroutine test1 use omp_lib implicit none character xz common/c/xz !$omp threadprivate(/c/) !$omp parallel num_threads(4) !$omp single xz = 'c' !$omp end single copyprivate(/c/) !$omp end parallel end error: COMMON block must be declared in the same scoping unit in which the OpenMP directive or clause appears !$omp end single copyprivate(/c/) ``` ``` !fails in gfortran but all other compilers accepting this subroutine test2 real z !$omp parallel private(z) num_threads(2) !$omp single z = -2 !$omp end single copyprivate(z,z) !$omp end parallel end ``` ``` subroutine test3 use omp_lib !$omp parallel private(xz) num_threads(2) xz = f() !$omp end parallel contains function f() result(rz) !$omp single rz = 42 !$omp end single copyprivate(rz) end function end subroutine error: COPYPRIVATE variable 'rz' is not PRIVATE or THREADPRIVATE in outer context !$omp end single copyprivate(rz) ^^ ``` ``` subroutine test4 use omp_lib implicit none call test contains subroutine test real, pointer :: xz !$omp parallel private(xz) num_threads(2) xz => fz() !$omp end parallel end subroutine function fz() real, pointer :: fz nullify (fz) !$omp single allocate (fz) fz = 42 !$omp end single copyprivate(fz) end function end subroutine error: COPYPRIVATE variable 'fz' is not PRIVATE or THREADPRIVATE in outer context !$omp end single copyprivate(fz) ^^ ```
luporl commented 1 month ago

95799 will fix all the remaining issues reported here.

However, in the case of test4 there is also an issue in lowering:

error: loc("test4.f90":15:15): 'fir.convert' op invalid type conversion'f32' / '!fir.box<!fir.ptr<f32>>'
error: Lowering to LLVM IR failed
error: loc("test4.f90":15:15): cannot be converted to LLVM IR: missing `LLVMTranslationDialectInterface` registration for dialect for op: func.func
error: failed to create the LLVM module

I'll open a separate issue for it.

luporl commented 1 month ago

Opened #95801 to track the lowering issue in copyprivate.

luporl commented 1 week ago

Fixed by #95799.

luporl commented 1 day ago

https://github.com/llvm/llvm-project/pull/95799 was reverted. This issue should be fixed by https://github.com/llvm/llvm-project/pull/101009 now.