Skip to content

[flang][OpenMP] Threadprivate variable in host-association #60763

@PeixinQiao

Description

@PeixinQiao

flang-compiler#1136 has the detailed info about the support status of Threadprivate directive.

Test case

$ cat hostassoc1.f90 
program main
  use omp_lib
  integer, save :: a
  !$omp threadprivate(a)
  call sub()
contains
  subroutine sub()
    a = 2
    !$omp parallel num_threads(4)
      a = omp_get_thread_num()
      print *, a, omp_get_thread_num()
    !$omp end parallel
    !$omp parallel num_threads(4)
      print *, a, omp_get_thread_num()
    !$omp end parallel
  end
end
$ cat hostassoc2.f90 
program main
  use omp_lib
  integer :: a
  !$omp threadprivate(a)
  call sub()
contains
  subroutine sub()
    a = 2
    !$omp parallel num_threads(4)
      a = omp_get_thread_num()
      print *, a, omp_get_thread_num()
    !$omp end parallel
    !$omp parallel num_threads(4)
      print *, a, omp_get_thread_num()
    !$omp end parallel
  end
end

Expected results:

           0           0
           2           2
           3           3
           1           1
           2           2
           3           3
           1           1
           0           0

GFortran 12 and ifort 2021 support hostassoc1.f90, but do not support hostassoc2.f90. For hostassoc2.f90, GFortran 12 gives wrong running results, while ifort reports the semantic error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorflang:irflang:openmp

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions