ACC Compiler does not automatically recognize scalars as present inside nested loop directives

Appearing inside more than one level of nested ACC loop directives prevents the compiler from automatically recognizing and making scalar variables PRESENT in the enclosing ACC parallel region. Bug or feature?

The code below fails because the scalar integer variables MROWS, KLOWER, KUPPOER, NDOF are not automatically considered PRESENT because they only appear inside doubly nested ACC LOOP directives:

!$acc parallel vector_length(32)
  !$acc loop gang private(ib,ie)
  do ib=1,1
     !$acc loop vector private(ie)
     do ie=es,ee
        call myfunction ( mrows,klower,kupper,ndof )
     enddo
  enddo
!$acc end parallel

Adding a present clause fixes the problem:

!$acc parallel vector_length(32) present(mrows,klower,kupper,ndof)
  !$acc loop gang private(ib,ie)
  do ib=1,1
     !$acc loop vector private(ie)
     do ie=es,ee
        call myfunction ( mrows,klower,kupper,ndof )
     enddo
  enddo
!$acc end parallel

Should that be necessary? Thank you,

John

Hi John,

The reason for this is since by default Fortran arguments are passed by reference, the compiler must presume a global reference can be taken within the function itself or the variable is updated which is needed after the exit of the kernel (aka ‘live-out’). Unlikely that this is indeed the case, but it is possible.

Hence, the recommend solution for this would to either add the variable to private clause, or use the “value” attribute on declaration of the function variables so they are passed by value.

-Mat

1 Like