Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flang][OpenMP] Issues in copyprivate #86907

Open
harishch4 opened this issue Mar 28, 2024 · 6 comments
Open

[Flang][OpenMP] Issues in copyprivate #86907

harishch4 opened this issue Mar 28, 2024 · 6 comments

Comments

@harishch4
Copy link
Contributor

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
Copy link
Contributor

luporl commented Apr 22, 2024

#88430 was merged, fixing test1.

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 22, 2024

@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)
^^



</details>

luporl added a commit to luporl/llvm-project that referenced this issue Jun 17, 2024
There are some cases in which variables used in OpenMP constructs
are predetermined as private. The semantic checks for copyprivate
were not handling those cases.

Fixes llvm#87214 and llvm#86907
@luporl
Copy link
Contributor

luporl commented Jun 17, 2024

#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
Copy link
Contributor

luporl commented Jun 17, 2024

Opened #95801 to track the lowering issue in copyprivate.

luporl added a commit that referenced this issue Jul 23, 2024
There are some cases in which variables used in OpenMP constructs
are predetermined as private. The semantic checks for copyprivate
were not handling those cases.

Besides that, shared symbols were not being properly represented
in some cases. When there was no previously declared private
(implicit) symbol, no new association symbols, representing
shared ones, were being created.

These symbols must always be inserted in constructs that may
privatize the original symbol: parallel, teams and task
generating constructs.

Fixes #87214 and #86907
@luporl
Copy link
Contributor

luporl commented Jul 23, 2024

Fixed by #95799.

@luporl luporl closed this as completed Jul 23, 2024
sgundapa pushed a commit to sgundapa/upstream_effort that referenced this issue Jul 23, 2024
There are some cases in which variables used in OpenMP constructs
are predetermined as private. The semantic checks for copyprivate
were not handling those cases.

Besides that, shared symbols were not being properly represented
in some cases. When there was no previously declared private
(implicit) symbol, no new association symbols, representing
shared ones, were being created.

These symbols must always be inserted in constructs that may
privatize the original symbol: parallel, teams and task
generating constructs.

Fixes llvm#87214 and llvm#86907
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Jul 24, 2024
There are some cases in which variables used in OpenMP constructs
are predetermined as private. The semantic checks for copyprivate
were not handling those cases.

Besides that, shared symbols were not being properly represented
in some cases. When there was no previously declared private
(implicit) symbol, no new association symbols, representing
shared ones, were being created.

These symbols must always be inserted in constructs that may
privatize the original symbol: parallel, teams and task
generating constructs.

Fixes llvm#87214 and llvm#86907

(cherry picked from commit eb9bf18)
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Jul 24, 2024
There are some cases in which variables used in OpenMP constructs
are predetermined as private. The semantic checks for copyprivate
were not handling those cases.

Besides that, shared symbols were not being properly represented
in some cases. When there was no previously declared private
(implicit) symbol, no new association symbols, representing
shared ones, were being created.

These symbols must always be inserted in constructs that may
privatize the original symbol: parallel, teams and task
generating constructs.

Fixes llvm#87214 and llvm#86907

(cherry picked from commit eb9bf18)
yuxuanchen1997 pushed a commit that referenced this issue Jul 25, 2024
There are some cases in which variables used in OpenMP constructs
are predetermined as private. The semantic checks for copyprivate
were not handling those cases.

Besides that, shared symbols were not being properly represented
in some cases. When there was no previously declared private
(implicit) symbol, no new association symbols, representing
shared ones, were being created.

These symbols must always be inserted in constructs that may
privatize the original symbol: parallel, teams and task
generating constructs.

Fixes #87214 and #86907
luporl added a commit to luporl/llvm-project that referenced this issue Jul 29, 2024
There are some cases in which variables used in OpenMP constructs
are predetermined as private. The semantic checks for copyprivate
were not handling those cases.

Besides that, shared symbols were not being properly represented
in some cases. When there was no previously declared private
(implicit) symbol, no new association symbols, representing
shared ones, were being created.

These symbols must always be inserted in constructs that may
privatize the original symbol: parallel, teams and task
generating constructs.

Fixes llvm#87214 and llvm#86907
@luporl
Copy link
Contributor

luporl commented Jul 29, 2024

#95799 was reverted. This issue should be fixed by #101009 now.

@luporl luporl reopened this Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants