Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat bicgstab.cu
- #include <cusp/csr_matrix.h>
- #include <cusp/krylov/bicgstab.h>
- #if defined(__cplusplus)
- extern "C" {
- #endif
- void bicgstab_(int * device_I, int * device_J, float * device_V, float * device_x, float * device_b, int N, int NNZ){
- // *NOTE* raw pointers must be wrapped with thrust::device_ptr!
- thrust::device_ptr<int> wrapped_device_I(device_I);
- thrust::device_ptr<int> wrapped_device_J(device_J);
- thrust::device_ptr<float> wrapped_device_V(device_V);
- thrust::device_ptr<float> wrapped_device_x(device_x);
- thrust::device_ptr<float> wrapped_device_b(device_b);
- // use array1d_view to wrap the individual arrays
- typedef typename cusp::array1d_view< thrust::device_ptr<int> > DeviceIndexArrayView;
- typedef typename cusp::array1d_view< thrust::device_ptr<float> > DeviceValueArrayView;
- DeviceIndexArrayView row_indices (wrapped_device_I, wrapped_device_I + (N+1));
- DeviceIndexArrayView column_indices(wrapped_device_J, wrapped_device_J + NNZ);
- DeviceValueArrayView values (wrapped_device_V, wrapped_device_V + NNZ);
- DeviceValueArrayView x (wrapped_device_x, wrapped_device_x + N);
- DeviceValueArrayView b (wrapped_device_b, wrapped_device_b + N);
- // combine the three array1d_views into a csr_matrix_view
- typedef cusp::csr_matrix_view<DeviceIndexArrayView,
- DeviceIndexArrayView,
- DeviceValueArrayView> DeviceView;
- // construct a csr_matrix_view from the array1d_views
- DeviceView A(N, N, NNZ, row_indices, column_indices, values);
- // set stopping criteria:
- // iteration_limit = 100
- // relative_tolerance = 1e-5
- cusp::verbose_monitor<float> monitor(b, 100, 1e-5);
- // solve the linear system A * x = b with the Conjugate Gradient method
- cusp::krylov::bicgstab(A, x, b, monitor);
- }
- #if defined(__cplusplus)
- }
- #endif
- $ cat bic.f90
- program test
- interface
- subroutine bicgstab_(dI, dJ, dV, dx, db, hN, hNNZ) bind(C)
- use, intrinsic :: ISO_C_BINDING, ONLY: C_INT
- implicit none
- integer(C_INT) :: dI,dJ,dV,dx,db,hN,hNNZ
- end subroutine bicgstab_
- end interface
- integer*4 dI,dJ
- integer*4 dV,dx,db
- integer*4 hN,hNNZ
- call bicgstab_(dI, dJ, dV, dx, db, hN, hNNZ)
- end program
- $ ifort -c bic.f90
- $ nvcc -c bicgstab.cu -o bicgstab.o -I/home-2/robertc/misc/cusp/cusplibrary-master
- nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
- $ ifort *.o -L/shared/apps/cuda/CUDA-v6.0.37/lib64 -lcudart -o program
- $
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement