Hi,
I would like to use directives with a code where some allocatable arrays which may or may not be allocated are passed as argument to a subroutine. This is possible within fortran 2003. With the accelerator model I would like to use the reflected directive to avoid data transfer if they are allocated. Here is a test code:
module computation
implicit none
contains
subroutine gpu_routine(nvec,nlev,a,option)
real, allocatable, intent(inout) :: a(:,:)
integer, intent(in) :: nvec,nlev,option
integer :: i,k
!$acc reflected(a)
if (option==1) then
!$acc region do kernel
do i=1,nvec
do k=2,nlev
a(i,k)=a(i,k)*a(i,k-1)
end do
end do
!$acc end region
end if
end subroutine gpu_routine
end module computation
program main
USE computation, only: gpu_routine
implicit none
real, allocatable :: a(:,:)
!$acc mirror(a)
integer, parameter :: n1=10000, nlev=60
integer, parameter :: option=1
if (option==1) then
allocate(a(n1,nlev))
!init a
a=0.1
!$acc update device(a)
end if
call gpu_routine(n1,nlev,a,option)
if (option==1) then
!$acc update host(a)
print*, sum(a)
else
print*, 'option=', option
end if
end program main
If I compile with
pgf90 -r8 -O3 -o test test.f90
the result is:
./test
1111.111111109653
If I now compile with -ta, I got a wrong result:
pgf90 -r8 -ta=nvidia -O3 -o test test.f90
./test
58994.21009943201
One other comment, if I change the option parameter:
integer, parameter :: option=0
in this case nothing should happen
I got the following error when compiling -ta=nvidia
./test
option= 0
call to cuMemFree returned error 1: Invalid value
CUDA driver version: 4000
althoug a should not be allocated in this case.
Is this a bug, or is this just not supported with reflected directive ?
Thanks,
Xavier
note: pgi version 11.6