//---------------------------------------------------------------------------// // Copyright (c) 2013 Kyle Lutz // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_ALGORITHM_EXCLUSIVE_SCAN_HPP #define BOOST_COMPUTE_ALGORITHM_EXCLUSIVE_SCAN_HPP #include #include #include #include #include #include namespace boost { namespace compute { /// Performs an exclusive scan of the elements in the range [\p first, \p last) /// and stores the results in the range beginning at \p result. /// /// Each element in the output is assigned to the sum of all the previous /// values in the input. /// /// \param first first element in the range to scan /// \param last last element in the range to scan /// \param result first element in the result range /// \param init value used to initialize the scan sequence /// \param binary_op associative binary operator /// \param queue command queue to perform the operation /// /// \return \c OutputIterator to the end of the result range /// /// The default operation is to add the elements up. /// /// \snippet test/test_scan.cpp exclusive_scan_int /// /// But different associative operation can be specified as \p binary_op /// instead (e.g., multiplication, maximum, minimum). Also value used to /// initialized the scan sequence can be specified. /// /// \snippet test/test_scan.cpp exclusive_scan_int_multiplies /// /// Space complexity on GPUs: \Omega(n)
/// Space complexity on GPUs when \p first == \p result: \Omega(2n)
/// Space complexity on CPUs: \Omega(1) /// /// \see inclusive_scan() template inline OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, BinaryOperator binary_op, command_queue &queue = system::default_queue()) { BOOST_STATIC_ASSERT(is_device_iterator::value); BOOST_STATIC_ASSERT(is_device_iterator::value); return detail::scan(first, last, result, true, init, binary_op, queue); } /// \overload template inline OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, command_queue &queue = system::default_queue()) { BOOST_STATIC_ASSERT(is_device_iterator::value); BOOST_STATIC_ASSERT(is_device_iterator::value); typedef typename std::iterator_traits::value_type output_type; return detail::scan(first, last, result, true, init, boost::compute::plus(), queue); } /// \overload template inline OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, command_queue &queue = system::default_queue()) { BOOST_STATIC_ASSERT(is_device_iterator::value); BOOST_STATIC_ASSERT(is_device_iterator::value); typedef typename std::iterator_traits::value_type output_type; return detail::scan(first, last, result, true, output_type(0), boost::compute::plus(), queue); } } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_ALGORITHM_EXCLUSIVE_SCAN_HPP