]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/include/boost/compute/algorithm/count_if.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / compute / include / boost / compute / algorithm / count_if.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@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 #ifndef BOOST_COMPUTE_ALGORITHM_COUNT_IF_HPP
12 #define BOOST_COMPUTE_ALGORITHM_COUNT_IF_HPP
13
14 #include <boost/compute/device.hpp>
15 #include <boost/compute/system.hpp>
16 #include <boost/compute/command_queue.hpp>
17 #include <boost/compute/algorithm/detail/count_if_with_ballot.hpp>
18 #include <boost/compute/algorithm/detail/count_if_with_reduce.hpp>
19 #include <boost/compute/algorithm/detail/count_if_with_threads.hpp>
20 #include <boost/compute/algorithm/detail/serial_count_if.hpp>
21 #include <boost/compute/detail/iterator_range_size.hpp>
22
23 namespace boost {
24 namespace compute {
25
26 /// Returns the number of elements in the range [\p first, \p last)
27 /// for which \p predicate returns \c true.
28 template<class InputIterator, class Predicate>
29 inline size_t count_if(InputIterator first,
30 InputIterator last,
31 Predicate predicate,
32 command_queue &queue = system::default_queue())
33 {
34 const device &device = queue.get_device();
35
36 size_t input_size = detail::iterator_range_size(first, last);
37 if(input_size == 0){
38 return 0;
39 }
40
41 if(device.type() & device::cpu){
42 if(input_size < 1024){
43 return detail::serial_count_if(first, last, predicate, queue);
44 }
45 else {
46 return detail::count_if_with_threads(first, last, predicate, queue);
47 }
48 }
49 else {
50 if(input_size < 32){
51 return detail::serial_count_if(first, last, predicate, queue);
52 }
53 else {
54 return detail::count_if_with_reduce(first, last, predicate, queue);
55 }
56 }
57 }
58
59 } // end compute namespace
60 } // end boost namespace
61
62 #endif // BOOST_COMPUTE_ALGORITHM_COUNT_IF_HPP