]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/perf/perf_reduce_by_key.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2015 Jakub Szuppe <j.szuppe@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
16 #include <boost/compute/system.hpp>
17 #include <boost/compute/algorithm/fill.hpp>
18 #include <boost/compute/algorithm/reduce_by_key.hpp>
19 #include <boost/compute/container/vector.hpp>
25 return static_cast<int>((rand() / double(RAND_MAX
)) * 25.0);
30 int avgValuesNoPerKey
;
35 avgValuesNoPerKey
= 512;
40 double p
= double(1.0) / static_cast<double>(avgValuesNoPerKey
);
41 if((rand() / double(RAND_MAX
)) <= p
)
47 int main(int argc
, char *argv
[])
49 perf_parse_args(argc
, argv
);
51 std::cout
<< "size: " << PERF_N
<< std::endl
;
53 // setup context and queue for the default device
54 boost::compute::device device
= boost::compute::system::default_device();
55 boost::compute::context
context(device
);
56 boost::compute::command_queue
queue(context
, device
);
57 std::cout
<< "device: " << device
.name() << std::endl
;
59 // create vector of keys and random values
60 std::vector
<int> host_keys(PERF_N
);
61 std::vector
<int> host_values(PERF_N
);
62 std::generate(host_keys
.begin(), host_keys
.end(), UniqueKey
);
63 std::generate(host_values
.begin(), host_values
.end(), rand_int
);
65 // create vectors for keys and values on the device and copy the data
66 boost::compute::vector
<int> device_keys(PERF_N
, context
);
67 boost::compute::vector
<int> device_values(PERF_N
,context
);
77 device_values
.begin(),
81 // vectors for the results
82 boost::compute::vector
<int> device_keys_results(PERF_N
, context
);
83 boost::compute::vector
<int> device_values_results(PERF_N
,context
);
85 typedef boost::compute::vector
<int>::iterator iterType
;
86 std::pair
<iterType
, iterType
> result(
87 device_keys_results
.begin(),
88 device_values_results
.begin()
93 for(size_t trial
= 0; trial
< PERF_TRIALS
; trial
++){
95 result
= boost::compute::reduce_by_key(device_keys
.begin(),
97 device_values
.begin(),
98 device_keys_results
.begin(),
99 device_values_results
.begin(),
103 std::cout
<< "time: " << t
.min_time() / 1e6
<< " ms" << std::endl
;
105 size_t result_size
= std::distance(device_keys_results
.begin(), result
.first
);
106 if(result_size
!= static_cast<size_t>(host_keys
[PERF_N
-1] + 1)){
107 std::cout
<< "ERROR: "
108 << "wrong number of keys" << result_size
<< "\n" << (host_keys
[PERF_N
-1] + 1)