Distributed Ranges
Loading...
Searching...
No Matches
exclusive_scan.hpp
1// SPDX-FileCopyrightText: Intel Corporation
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#pragma once
6
7#include <dr/mp/algorithms/inclusive_exclusive_scan_impl.hpp>
8
9namespace dr::mp {
10
12 dr::distributed_contiguous_range O, typename T, typename BinaryOp>
13auto exclusive_scan(R &&r, O &&o, T init, BinaryOp &&binary_op) {
14 return __detail::inclusive_exclusive_scan_impl_<true>(
15 std::forward<R>(r), rng::begin(std::forward<O>(o)),
16 std::forward<BinaryOp>(binary_op),
17 std::optional<rng::range_value_t<R>>(init));
18}
19
22auto exclusive_scan(R &&r, O &&o, T init) {
23 return dr::mp::exclusive_scan(std::forward<R>(r), std::forward<O>(o),
24 static_cast<rng::range_value_t<R>>(init),
25 std::plus<rng::range_value_t<R>>());
26}
27
28// Distributed iterator versions
29
30template <dr::distributed_iterator Iter, dr::distributed_iterator OutputIter,
31 typename T, typename BinaryOp>
32OutputIter exclusive_scan(Iter first, Iter last, OutputIter d_first, T init,
33 BinaryOp &&binary_op) {
34
35 return dr::mp::exclusive_scan(rng::subrange(first, last), d_first,
36 std::forward<BinaryOp>(binary_op), init);
37}
38
39template <dr::distributed_iterator Iter, dr::distributed_iterator OutputIter,
40 typename T>
41OutputIter exclusive_scan(Iter first, Iter last, OutputIter d_first, T init) {
42 auto dist = rng::distance(first, last);
43 auto d_last = d_first;
44 rng::advance(d_last, dist);
45 dr::mp::exclusive_scan(rng::subrange(first, last),
46 rng::subrange(d_first, d_last), init);
47
48 return d_last;
49}
50
51} // namespace dr::mp
Definition: concepts.hpp:42
Definition: concepts.hpp:31