OpenACC与CUDA Fortran交互(2)

在帖子《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
发布了40 篇原创文章 · 获赞 7 · 访问量 9万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章