upgpkg: wordpress 6.2.1-1
[ArchLinux/community.git] / rocthrust / trunk / test.cpp
blobd61a1d5e55850fa1717c7db056aa7b7b186f5323
1 #include <thrust/copy.h>
2 #include <thrust/host_vector.h>
3 #include <thrust/device_vector.h>
4 #include <thrust/sort.h>
5 #include <iostream>
6 #include <vector>
7 #include <algorithm>
8 #include <random>
10 int main(int argc, char *argv[])
12 size_t size = 1024;
14 std::random_device rd;
15 std::mt19937 gen(rd());
16 std::uniform_real_distribution<float> dist(-1.0, 1.0);
18 auto myrand = [&]() -> float {return dist(gen);};
20 thrust::host_vector<float> xin(size);
21 std::generate(xin.begin(), xin.end(), myrand);
23 thrust::device_vector<float> x(size);
24 x = xin;
26 thrust::sort(x.begin(), x.end());
27 thrust::copy(x.begin(), x.end(), xin.begin());
29 for(size_t i = 1; i < size; i++){
30 if(xin[i - 1] > xin[i]){
31 std::cout << "Elements " << i - 1 << " and " << i
32 << "are not sorted:\n";
33 std::cout << xin[i - 1] << " " << xin[i] << std::endl;
34 return 1;
38 std::cout << "TESTS PASSED!" << std::endl;