Scope of directive "data" via subroutine

Dear All,

I don’t know effective scope of data directive via subroutine. Could you let me know ?
Following are test source codes.

Using the data directive, I allocate on my GPU. And then he subroutine “conj_grad” is
called in main.f. And the array “x” is passed.

In the file “sub.f”, I declare the subroutine “conj_grad”.
Using the directive “kernels”, I try to run on GPU.

As you know, the array “x” is the actual argument. the array “r” is the dummy argument.
And I do NOT allocate the array “r” in the subroutine “conj_grad”.

I don’t know if the array “r” is allocated in the subroutine “conj_grad” and if this meets on the OpenACC standard.

------------------------- main.f ------------------------------
implicit none
double precision x(10)

!$acc data create(x)
call conj_grad(x)
!$acc end data

end

------------------------- sub.f ------------------------------
subroutine conj_grad(r)
implicit none
integer i
double precision r(*)

!$acc kernels present(r)
do i = 1,10
r(i) = 0.0d0
end do
!$acc end kernels

Hi KOUCHI_Hiroyuki,

Yes, “r” will be available on the device. The present look up is done by address, not the variable name.

One caveat is when Fortran argument passing requires a temp array be created, such as when passing in a sub-array. In this case, the dummy and actual arguments are different host arrays.

  • Mat

Dear Mat-san,

Thank you for your advice.
As you said, it is important. This time I allocate a continuous array. I suppose if a temp array is not created.
When non-continuous array is passed, I will pay attention.

Sincerely yours,