Simple (?) question on OpenACC host_data usage

Hi everyone, OpenACC newbie here.

When I compile the following code with PGI 13.6, I get:

on device, dq(5) = 0.000000
on host, dq(5) = 5.000000

Should the first value (“on device”) be 0.0 or 5.0? I was
expecting 5.0, but perhaps I don’t understand what’s
happening here?


program deviceptr

    implicit none

    integer :: i

    real, dimension(:), pointer :: dq

    dq(:) = 0.0

!$acc data copy(dq)

!$acc parallel present(dq)
    do i = 1, 10
      dq(i) = real(i)
    end do
!$acc end parallel

!$acc host_data use_device(dq)
    write(*,*) 'on device, dq(5) = ', dq(5)
!$acc end host_data

!$acc end data

    write(*,*) 'on host, dq(5) = ', dq(5)

end program deviceptr


Hi Eric,

host_data wont be fully supported until the 14.1 release due out soon. Hence, your example is printing out the host copy of the array. You have the right idea though.

However in 14.1 this code will seg fault since you’re trying to use a device pointer on the host. You’ll only be able to access dq within device code, such as a CUDA C/Fortran kernel or OpenACC compute region.

Hope this helps,