]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/perf/perf_prev_permutation.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / compute / perf / perf_prev_permutation.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2014 Roshan <thisisroshansmail@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #include <algorithm>
12 #include <iostream>
13 #include <numeric>
14 #include <vector>
15
16 #include <boost/compute/system.hpp>
17 #include <boost/compute/algorithm/next_permutation.hpp>
18 #include <boost/compute/algorithm/prev_permutation.hpp>
19 #include <boost/compute/container/vector.hpp>
20
21 #include "perf.hpp"
22
23 int rand_int()
24 {
25 return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
26 }
27
28 int main(int argc, char *argv[])
29 {
30 perf_parse_args(argc, argv);
31 std::cout << "size: " << PERF_N << std::endl;
32
33 // setup context and queue for the default device
34 boost::compute::device device = boost::compute::system::default_device();
35 boost::compute::context context(device);
36 boost::compute::command_queue queue(context, device);
37 std::cout << "device: " << device.name() << std::endl;
38
39 // create vector of random numbers on the host
40 std::vector<int> host_vector(PERF_N);
41 std::generate(host_vector.begin(), host_vector.end(), rand_int);
42 std::sort(host_vector.begin(), host_vector.end());
43
44 // create vector on the device and copy the data
45 boost::compute::vector<int> device_vector(PERF_N, context);
46 boost::compute::copy(
47 host_vector.begin(), host_vector.end(), device_vector.begin(), queue
48 );
49
50 perf_timer t;
51 for(size_t trial = 0; trial < PERF_TRIALS; trial++){
52 t.start();
53 boost::compute::prev_permutation(
54 device_vector.begin(), device_vector.end(), queue
55 );
56 queue.finish();
57 t.stop();
58 boost::compute::next_permutation(
59 device_vector.begin(), device_vector.end(), queue
60 );
61 }
62 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
63
64 return 0;
65 }