Advertisement
Guest User

Untitled

a guest
Apr 10th, 2012
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module thrust
  2.  
  3. interface thrustmin
  4.  
  5.     function min_float(input,N) bind(C,name="min_float_wrapper")
  6.     use iso_c_binding
  7.     real(c_float),device:: input(*)
  8.     integer(c_int),value:: N, min_float
  9.     end function
  10.  
  11.     function min_double(input,N) bind(C,name="min_double_wrapper")
  12.     use iso_c_binding
  13.     real(c_double),device:: input(*)
  14.     integer(c_int),value:: N, min_double
  15.     end function
  16.  
  17. !   subroutine min_double(input,N) bind(C,name="min_double_wrapper")
  18. !   use iso_c_binding
  19. !   real(c_double),device:: input(*)
  20. !   integer(c_int),value:: N
  21. !   end subroutine
  22.  
  23. end interface
  24.  
  25. end module thrust
  26.  
  27.  
  28. program GPU
  29.   use cudafor
  30.   use thrust
  31.   implicit none
  32.   real, allocatable, device :: dev_array(:)
  33.   real, allocatable :: host_array(:)
  34.   integer N / 20 /
  35.   integer :: x
  36.  
  37.   allocate(dev_array(N))
  38.   allocate(host_array(N))
  39.  
  40.   call random_seed
  41.   call random_number(host_array)
  42.  
  43.   print *, "host_array:"
  44.   print *, host_array
  45.  
  46.  
  47.   print *, "COPY!"
  48.   dev_array = host_array
  49.  
  50.   print *, "START CUDA!"
  51.   x = thrustmin(dev_array, size(dev_array))
  52.   print *, "DONE  CUDA!"
  53.  
  54.   print *, "Min:", x
  55.  
  56.   deallocate(dev_array)
  57.   deallocate(host_array)  
  58.  
  59.   end program GPU
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement