OpenACC与CUDA Fortran交互(2)

来源:互联网 发布:淘宝青岛双星专卖店 编辑:程序博客网 时间:2024/05/09 20:18
在帖子《OpenACC与CUDA Fortran交互(1)》中,举了一个在openacc中嵌套cuda fortran的例子。现在举一个cuda fortran中嵌套openacc的例子。上代码:

  1. ! cuf_main.cuf
  2. program main
  3.   integer, parameter :: N = 2**20
  4.   ! Allocate X and Y only on the device
  5.   real, device, dimension(N) :: X, Y
  6.   integer :: i
  7.   real :: tmp

  8.   ! CUDA Fortran will automatically convert these to run on the device
  9.   X(:) = 1.0
  10.   Y(:) = 0.0

  11.   !$acc kernels deviceptr(x,y)
  12.   y(:) = y(:) + 2.0*x(:)
  13.   !$acc end kernels

  14.   ! Copy the first element back from Y for correctness checking
  15.   tmp = y(1)
  16.   print *, tmp
  17. end program

编译:
  1. pgf90  -o cuda_fortran_openacc cuf_main.cuf -acc -Mcuda=cc3.5 -Minfo
原创粉丝点击