Posted By

initiationone on 11/19/10


Tagged

thrust


Versions (?)

thrust usage example


 / Published in: C++
 

  1. #include <thrust/host_vector.h>
  2. #include <thrust/device_vector.h>
  3. #include <thrust/sort.h>
  4. #include <cstdlib.h>
  5. int main(void)
  6. {
  7. // generate 32M random numbers on the host
  8. thrust::host_vector<int> h_vec(32 << 20);
  9. thrust::generate(h_vec.begin(), h_vec.end(), rand);
  10. // transfer data to the device
  11. thrust::device_vector<int> d_vec= h_vec;
  12. // sort data on the device (846M keys per sec on GeForceGTX 480)
  13. thrust::sort(d_vec.begin(), d_vec.end());
  14. // transfer data back to host
  15. thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
  16. return 0;
  17. }

Report this snippet  

You need to login to post a comment.