PSyclone: get_private_clauses of OMPParallelDirective incorrectly flagging non-array accesses as firstprivate
I have the following test in the task branch which now fails (and before the firstprivate changes did not). I’ve slightly adjusted it as previously it was easy to argue “k wasn’t set”, but now k is an input parameter and PSyclone doesn’t change its behaviour.
code = '''
subroutine my_subroutine(k)
integer :: i, ii
integer :: j, jj
integer :: k
do i = 1, 320, 32
do j = 1, 320, 32
do ii=i, i+32
do jj = j,j+32
k = k + ii
k = k * jj
end do
end do
end do
end do
end subroutine
'''
tree = fortran_reader.psyir_from_source(code)
ptrans = OMPParallelTrans()
strans = OMPSingleTrans()
tdir = DynamicOMPTaskDirective()
loops = tree.walk(Loop)
loop = loops[1].children[3].children[0]
parent = loop.parent
loop.detach()
tdir.children[0].addchild(loop)
parent.addchild(tdir, index=0)
strans.apply(loops[0])
ptrans.apply(loops[0].parent.parent)
correct = '''subroutine my_subroutine(k)
integer :: k
integer :: i
integer :: ii
integer :: j
integer :: jj
!$omp parallel default(shared), private(i,ii,j,jj)
!$omp single
do i = 1, 320, 32
do j = 1, 320, 32
!$omp task private(ii,jj), firstprivate(i,j), shared(k), \
depend(in: k), depend(out: k)
do ii = i, i + 32, 1
do jj = j, j + 32, 1
k = k + ii
k = k * jj
enddo
enddo
!$omp end task
enddo
enddo
!$omp end single
!$omp end parallel
end subroutine my_subroutine\n'''
assert fortran_writer(tree) == correct
For some reason, the access k = k + ii is being flagged as a firstprivate access - I think because its a non-array access, however since its an assignment to k, it should be shared - if this was in an OMPDoDirective then we’d obviously have a race condition (which is not allowed), however the data concurrency issue is handle by the dependency on the task.
The output from fortran_writer(tree) is instead:
subroutine my_subroutine(k)
integer :: k
integer :: i
integer :: ii
integer :: j
integer :: jj
!$omp parallel default(shared), private(i,ii,j,jj), firstprivate(k)
!$omp single
do i = 1, 320, 32
do j = 1, 320, 32
!$omp task private(ii,jj), firstprivate(i,j), shared(k), depend(in: k), depend(out: k)
do ii = i, i + 32, 1
do jj = j, j + 32, 1
k = k + ii
k = k * jj
enddo
enddo
!$omp end task
enddo
enddo
!$omp end single
!$omp end parallel
end subroutine my_subroutine
I think this affects a lot of my tests, and are instances with PSyclone generating incorrect code.
@sergisiso @nmnobre What were the rules decided for determining if a variable in PSyclone is firstprivate as opposed to shared? Maybe this needs to be smarter - perhaps variable accesses inside OMPSerialRegions need difference rules?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21 (4 by maintainers)
Ok - I guess we can do over Zoom the week after then?
Hi Nuno, Issue with your examples is providing a constant value as a parameter to a data clause in OpenMP, easier fix (works with intel 23) is just:
Since k is a dummy variable i think it causes the seg fault.
@sergisiso The issue with this a bit is that the dependencies are somewhat depending on whether we think the variable is shared or private, which was relying on the OMPParallelRegion’s computation.