Skip to content

Instantly share code, notes, and snippets.

@clarkzjw
Created August 4, 2015 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkzjw/681a1383d5bb4adcce68 to your computer and use it in GitHub Desktop.
Save clarkzjw/681a1383d5bb4adcce68 to your computer and use it in GitHub Desktop.
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/sort.h>
#include <thrust/copy.h>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <cstdlib>
int main(void)
{
using namespace std;
vector<int> vec(32 << 18);
//// generate random numbers serially
std::generate(vec.begin(), vec.end(), rand);
//// transfer data to the device
thrust::device_vector<int> d_vec = vec;
clock_t begin, end;
begin = clock();
//// sort data on the device (846M keys per second on GeForce GTX 480)
thrust::sort(d_vec.begin(), d_vec.end());
end = clock();
cout << end - begin << endl;
begin = clock();
std::sort(vec.begin(), vec.end());
end = clock();
cout << end - begin << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment