Advertisement
Guest User

Untitled

a guest
Jun 28th, 2014
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. $ cat bicgstab.cu
  2. #include <cusp/csr_matrix.h>
  3. #include <cusp/krylov/bicgstab.h>
  4.  
  5. #if defined(__cplusplus)
  6. extern "C" {
  7. #endif
  8.  
  9. void bicgstab_(int * device_I, int * device_J, float * device_V, float * device_x, float * device_b, int N, int NNZ){
  10.  
  11. // *NOTE* raw pointers must be wrapped with thrust::device_ptr!
  12. thrust::device_ptr<int> wrapped_device_I(device_I);
  13. thrust::device_ptr<int> wrapped_device_J(device_J);
  14. thrust::device_ptr<float> wrapped_device_V(device_V);
  15. thrust::device_ptr<float> wrapped_device_x(device_x);
  16. thrust::device_ptr<float> wrapped_device_b(device_b);
  17.  
  18. // use array1d_view to wrap the individual arrays
  19. typedef typename cusp::array1d_view< thrust::device_ptr<int> > DeviceIndexArrayView;
  20. typedef typename cusp::array1d_view< thrust::device_ptr<float> > DeviceValueArrayView;
  21.  
  22. DeviceIndexArrayView row_indices (wrapped_device_I, wrapped_device_I + (N+1));
  23. DeviceIndexArrayView column_indices(wrapped_device_J, wrapped_device_J + NNZ);
  24. DeviceValueArrayView values (wrapped_device_V, wrapped_device_V + NNZ);
  25. DeviceValueArrayView x (wrapped_device_x, wrapped_device_x + N);
  26. DeviceValueArrayView b (wrapped_device_b, wrapped_device_b + N);
  27.  
  28. // combine the three array1d_views into a csr_matrix_view
  29. typedef cusp::csr_matrix_view<DeviceIndexArrayView,
  30. DeviceIndexArrayView,
  31. DeviceValueArrayView> DeviceView;
  32.  
  33. // construct a csr_matrix_view from the array1d_views
  34. DeviceView A(N, N, NNZ, row_indices, column_indices, values);
  35.  
  36. // set stopping criteria:
  37. // iteration_limit = 100
  38. // relative_tolerance = 1e-5
  39. cusp::verbose_monitor<float> monitor(b, 100, 1e-5);
  40.  
  41. // solve the linear system A * x = b with the Conjugate Gradient method
  42. cusp::krylov::bicgstab(A, x, b, monitor);
  43.  
  44. }
  45.  
  46. #if defined(__cplusplus)
  47. }
  48. #endif
  49. $ cat bic.f90
  50. program test
  51.  
  52. interface
  53. subroutine bicgstab_(dI, dJ, dV, dx, db, hN, hNNZ) bind(C)
  54. use, intrinsic :: ISO_C_BINDING, ONLY: C_INT
  55. implicit none
  56. integer(C_INT) :: dI,dJ,dV,dx,db,hN,hNNZ
  57. end subroutine bicgstab_
  58. end interface
  59.  
  60. integer*4 dI,dJ
  61. integer*4 dV,dx,db
  62. integer*4 hN,hNNZ
  63. call bicgstab_(dI, dJ, dV, dx, db, hN, hNNZ)
  64.  
  65. end program
  66. $ ifort -c bic.f90
  67. $ nvcc -c bicgstab.cu -o bicgstab.o -I/home-2/robertc/misc/cusp/cusplibrary-master
  68. nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
  69. $ ifort *.o -L/shared/apps/cuda/CUDA-v6.0.37/lib64 -lcudart -o program
  70. $
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement