Assumed-shape array

Dear All,

Could you check if the following is the proper way to use the “data” directive ?

Here are two source codes. “mod.F90” and “main.F90”
In the file “main.F90”, the subroutines “alloc_on_device()” and “free_on_device()”
are called. And these subroutines are declared in the file “mod.F90”.
In the subroutine “alloc_on_device()”, the directive “enter data” is declared.
In the subroutine “free_on_device()”, the directive “exit data” is declared.
These subroutines are passed the array “x”.
In these subroutines, the assumed-shape "… dimension(:,:) … " are declared.

On the OpenACC standard, there seems to be no problem to use the assumed-size.
However I don’t know if the assumed-shape is available as follows.



------------------------------ mod.F90 ---------------------------------------------

module test
implicit none

contains
subroutine alloc_on_device(x,i,j)
integer(kind=4) :: i,j
integer(kind=4),dimension(:,:),intent(in) :: x

!$acc enter data create(x(1:i,1:j))

end subroutine alloc_on_device

subroutine free_on_device(x,i,j)
integer(kind=4) :: i,j
integer(kind=4),dimension(:,:),intent(in) :: x

!$acc exit data delete(x(1:i,1:j))

end subroutine free_on_device

end module test

-------------------------- main.F90 -----------------------------------------------------
program OpenACC_test
use test
implicit none
integer(kind=4),parameter :: n = 1024
integer(kind=4),dimension(n,n) :: a

call alloc_on_device(a,n,n)
call free_on_device(a,n,n)
end program OpenACC_test

Hi KOUCHI_Hiroyuki,

This should be fine. The only potential issue I see is if you passed in a non-contiguous sub-array into the routine. In that case, the compiler would need to create a host side temp array which would get passed into the subroutine. Hence you’d be creating a device copy of the temp array rather than the array you want.

Here, since you’re passing in the whole array, should not cause any issues.

  • Mat

Dear Mat-san,

Thank you for the reply.

Sincerely yours,