在帖子《 OpenACC 与CUDA Fortran交互(1)》中,举了一个在openacc中嵌套cuda fortran的例子。现在举一个cuda fortran中嵌套openacc的例子。上代码: ! cuf_main.cuf program main integer, parameter :: N = 2**20 ! Allocate X and Y only on the device real, device, dimension(N) :: X, Y integer :: i real :: tmp ! CUDA Fortran will automatically convert these to run on the device X(:) = 1.0 Y(:) = 0.0 !$acc kernels deviceptr(x,y) y(:) = y(:) + 2.0*x(:) !$acc end kernels ! Copy the first element back from Y for correctness checking tmp = y(1) print *, tmp end program 编译: pgf90 -o cuda_fortran_openacc cuf_main.cuf -acc -Mcuda=cc3.5 -Minfo