PSyclone: `OMPTaskTrans` / `InliningTrans` / ? resulting in incorrect data sharing clauses

When running OMPTaskTrans (with manually predone inlining trans) there’s an issue with renamed variables not appearing in data sharing clauses.

When inlining momentum_u_code we get the expected behaviour: firstprivate(j_out_var,j_el_inner,u_e,depe,u_w,depw,v_sc,v_s,deps,v_nc,**v_n**,depn, (there’s an argument over whether these should be firstprivate or not but thats not really important for now).

When then inlining momentum_v_code, the inlining transformation renames v_n to v_n_1 to prevent collision (makes sense), however the private/firstprivate clauses (and dependency clauses) on this task still use v_n instead of v_n_1.

I think this is happening as the parent parallel clause doesn’t seem to know anything about v_n_1, and thus it is considered to be shared by the tasks, so shouldn’t be declared private or firstprivate, however this doesn’t explain why the task’s clauses contain v_n which is never used in the task, so shouldn’t be inside the clauses unless renaming is happening later than I expect?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 26 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Let me see if I can write a test that exercises this…

code = (
    "module psy_single_invoke_test\n"
    "  use field_mod, only: r2d_field\n"
    "  use kind_params_mod\n"
    "  implicit none\n"
    "  contains\n"
    "  subroutine invoke_0_compute_cu(cu_fld, pf, u_fld)\n"
    "    type(r2d_field), intent(inout) :: cu_fld, pf, u_fld\n"
    "    integer j, i, a_clash\n"
    "    do j = cu_fld%internal%ystart, cu_fld%internal%ystop, 1\n"
    "      do i = cu_fld%internal%xstart, cu_fld%internal%xstop, 1\n"
    "        a_clash = i\n"
    "        call compute_cu_code(a_clash, j, cu_fld%data, pf%data, "
    "u_fld%data)\n"
    "      end do\n"
    "    end do\n"
    "  end subroutine invoke_0_compute_cu\n"
    "  subroutine compute_cu_code(i, j, cu, p, u)\n"
    "    implicit none\n"
    "    integer,  intent(in) :: i, j\n"
    "    real(go_wp), intent(out), dimension(:,:) :: cu\n"
    "    real(go_wp), intent(in),  dimension(:,:) :: p, u\n"
    "    real(go_wp) :: a_clash\n"
    "    a_clash = 3.0d0\n"
    "    cu(i,j) = a_clash*0.5d0*(p(i,j)+p(i-1,j))*u(i,j)\n"
    "  end subroutine compute_cu_code\n"
    "end module psy_single_invoke_test\n"
)

Doing InlineTrans (after hacking the validate) and then OMPLoopTrans, the generated code is:

integer :: a_clash
real(kind=go_wp) :: a_clash_1

!$omp parallel do default(shared), private(a_clash_1,i,j), schedule(auto)
do j = cu_fld%internal%ystart, cu_fld%internal%ystop, 1
  do i = cu_fld%internal%xstart, cu_fld%internal%xstop, 1
    a_clash = i
    a_clash_1 = 3.0d0
    cu_fld%data(a_clash,j) = a_clash_1 * 0.5d0 * (pf%data(a_clash,j) + pf%data(a_clash - 1,j)) * u_fld%data(a_clash,j)
  enddo
enddo
!$omp end parallel do

so a_clash is now shared which is wrong.