Created
August 4, 2015 00:47
-
-
Save clarkzjw/681a1383d5bb4adcce68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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