先上代码: ! openacc_main.f90 program main use saxpy_mod integer, parameter :: N = 2**20 real, dimension(N) :: X, Y X(:) = 1.0 Y(:) = 0.0 !$acc data copy(y) copyin(x) call saxpy(N, 2.0, x, y) !$acc end data print *, y(1) end program ! kernels.cuf module saxpy_mod contains attributes(global) & subroutine saxpy_kernel(n, a, x, y) real :: x(:), y(:), a integer :: n,i attributes(value) :: a,n i = threadIdx%x+(blockIdx%x-1)*blockDim%x if (i<=n) y(i) = y(i) + a*x(i) end subroutine subroutine saxpy (n, a, x, y) use cudafor real, device :: x(:), y(:) real :: a integer :: n call saxpy_kernel<<<4096,256>>>(n, a, x, y) end subroutine end module saxpy_mod 对于函数saxpy_kernel来说,变量x,y 有device属性,编译器会知道传过来的是设备数组,故不需要 host_data导语。