Skip to content

[flang][openmp] incorrect firstprivate initialization in omp task #120708

Closed
@jeanPerier

Description

@jeanPerier

It looks like firstprivate initialization is not happening as expected in the program below: i in the !omp task is not given the value of i when the task is created (it seems it is given the value of i when the task is launched because it tends to be given 5 for instance).

I expect the program below to print "in task: i=..." to print 1, 2,3 and 4 (in any order), but I see 5,5,5,5 (or sometimes 2,3,4,5).

subroutine test()
    use omp_lib, only : omp_get_thread_num
   implicit none
   integer :: i
!$omp parallel private(i)
   !$omp single
     do i = 1,4
         print '("outside: i= ",I0,"  thread_id= ",I0, "  &i= "I0)', i, omp_get_thread_num(), loc(i)
         !$omp task firstprivate(i)
            print '("in task: i= ",I0,"  thread_id= ",I0, "  &i= "I0)', i, omp_get_thread_num(), loc(i)
         !$omp end task
      end do
   !$omp end single
!$omp end parallel
end subroutine
 use omp_lib, only : omp_set_dynamic, omp_set_num_threads
 call omp_set_dynamic(.false.)
 call omp_set_num_threads(4)
 call test()
end

All of gfortran, nvfortran and ifx print 1,2,3,4 here (in random order of course).

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions