• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #863

11 Jan 2023 05:02PM UTC coverage: 86.533% (-0.05%) from 86.582%
#863

push

StellarBot
Merge #6126

6126: Deprecate hpx::parallel::task_block in favor of hpx::experimental::ta… r=hkaiser a=dimitraka



Co-authored-by: kadimitra <kadimitra@ece.auth.gr>

174614 of 201789 relevant lines covered (86.53%)

1954694.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

36.78
/libs/full/segmented_algorithms/include/hpx/parallel/segmented_algorithms/generate.hpp
1
//  Copyright (c) 2007-2020 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#pragma once
8

9
#include <hpx/config.hpp>
10
#include <hpx/algorithms/traits/segmented_iterator_traits.hpp>
11

12
#include <hpx/executors/execution_policy.hpp>
13
#include <hpx/parallel/algorithms/detail/dispatch.hpp>
14
#include <hpx/parallel/algorithms/generate.hpp>
15
#include <hpx/parallel/segmented_algorithms/detail/dispatch.hpp>
16
#include <hpx/parallel/util/detail/algorithm_result.hpp>
17
#include <hpx/parallel/util/detail/handle_remote_exceptions.hpp>
18

19
#include <algorithm>
20
#include <exception>
21
#include <iterator>
22
#include <list>
23
#include <type_traits>
24
#include <utility>
25
#include <vector>
26

27
namespace hpx { namespace parallel { inline namespace v1 {
28
    ///////////////////////////////////////////////////////////////////////////
29
    // segmented_generate
30
    namespace detail {
31
        ///////////////////////////////////////////////////////////////////////
32
        /// \cond NOINTERNAL
33

34
        // sequential remote implementation
35
        template <typename Algo, typename ExPolicy, typename SegIter,
36
            typename F>
37
        static typename util::detail::algorithm_result<ExPolicy, SegIter>::type
38
        segmented_generate(Algo&& algo, ExPolicy const& policy, SegIter first,
×
39
            SegIter last, F&& f, std::true_type)
40
        {
41
            typedef hpx::traits::segmented_iterator_traits<SegIter> traits;
42
            typedef typename traits::segment_iterator segment_iterator;
43
            typedef typename traits::local_iterator local_iterator_type;
44
            typedef util::detail::algorithm_result<ExPolicy, SegIter> result;
45

46
            segment_iterator sit = traits::segment(first);
×
47
            segment_iterator send = traits::segment(last);
×
48

49
            if (sit == send)
×
50
            {
51
                // all elements are on the same partition
52
                local_iterator_type beg = traits::local(first);
×
53
                local_iterator_type end = traits::local(last);
×
54
                if (beg != end)
×
55
                {
56
                    local_iterator_type out = dispatch(traits::get_id(sit),
×
57
                        algo, policy, std::true_type(), beg, end, f);
×
58
                    last = traits::compose(send, out);
×
59
                }
×
60
            }
×
61
            else
62
            {
63
                // handle the remaining part of the first partition
64
                local_iterator_type beg = traits::local(first);
×
65
                local_iterator_type end = traits::end(sit);
×
66
                local_iterator_type out = traits::local(last);
×
67

68
                if (beg != end)
×
69
                {
70
                    out = dispatch(traits::get_id(sit), algo, policy,
×
71
                        std::true_type(), beg, end, f);
×
72
                }
×
73

74
                // handle all of the full partitions
75
                for (++sit; sit != send; ++sit)
×
76
                {
77
                    beg = traits::begin(sit);
×
78
                    end = traits::end(sit);
×
79
                    if (beg != end)
×
80
                    {
81
                        out = dispatch(traits::get_id(sit), algo, policy,
×
82
                            std::true_type(), beg, end, f);
×
83
                    }
×
84
                }
×
85

86
                // handle the beginning of the last partition
87
                beg = traits::begin(sit);
×
88
                end = traits::local(last);
×
89
                if (beg != end)
×
90
                {
91
                    out = dispatch(traits::get_id(sit), algo, policy,
×
92
                        std::true_type(), beg, end, f);
×
93
                }
×
94

95
                last = traits::compose(send, out);
×
96
            }
×
97

98
            return result::get(HPX_MOVE(last));
×
99
        }
×
100

101
        // parallel remote implementation
102
        template <typename Algo, typename ExPolicy, typename SegIter,
103
            typename F>
104
        static typename util::detail::algorithm_result<ExPolicy, SegIter>::type
105
        segmented_generate(Algo&& algo, ExPolicy const& policy, SegIter first,
2✔
106
            SegIter last, F&& f, std::false_type)
107
        {
108
            typedef hpx::traits::segmented_iterator_traits<SegIter> traits;
109
            typedef typename traits::segment_iterator segment_iterator;
110
            typedef typename traits::local_iterator local_iterator_type;
111

112
            typedef std::integral_constant<bool,
113
                !hpx::traits::is_forward_iterator<SegIter>::value>
114
                forced_seq;
115
            typedef util::detail::algorithm_result<ExPolicy, SegIter> result;
116

117
            segment_iterator sit = traits::segment(first);
2✔
118
            segment_iterator send = traits::segment(last);
2✔
119

120
            std::vector<shared_future<local_iterator_type>> segments;
2✔
121
            segments.reserve(std::distance(sit, send));
2✔
122

123
            if (sit == send)
2✔
124
            {
125
                // all elements are on the same partition
126
                local_iterator_type beg = traits::local(first);
×
127
                local_iterator_type end = traits::local(last);
×
128
                if (beg != end)
×
129
                {
130
                    segments.push_back(dispatch_async(traits::get_id(sit), algo,
×
131
                        policy, forced_seq(), beg, end, f));
×
132
                }
×
133
            }
×
134
            else
135
            {
136
                // handle the remaining part of the first partition
137
                local_iterator_type beg = traits::local(first);
2✔
138
                local_iterator_type end = traits::end(sit);
2✔
139
                if (beg != end)
2✔
140
                {
141
                    segments.push_back(dispatch_async(traits::get_id(sit), algo,
2✔
142
                        policy, forced_seq(), beg, end, f));
2✔
143
                }
2✔
144

145
                // handle all of the full partitions
146
                for (++sit; sit != send; ++sit)
2✔
147
                {
148
                    beg = traits::begin(sit);
×
149
                    end = traits::end(sit);
×
150
                    if (beg != end)
×
151
                    {
152
                        segments.push_back(dispatch_async(traits::get_id(sit),
×
153
                            algo, policy, forced_seq(), beg, end, f));
×
154
                    }
×
155
                }
×
156

157
                // handle the beginning of the last partition
158
                beg = traits::begin(sit);
2✔
159
                end = traits::local(last);
2✔
160
                if (beg != end)
2✔
161
                {
162
                    segments.push_back(dispatch_async(traits::get_id(sit), algo,
×
163
                        policy, forced_seq(), beg, end, f));
×
164
                }
×
165
            }
2✔
166

167
            return result::get(dataflow(
2✔
168
                [=](std::vector<hpx::shared_future<local_iterator_type>>&& r)
4✔
169
                    -> SegIter {
170
                    // handle any remote exceptions, will throw on error
171
                    std::list<std::exception_ptr> errors;
2✔
172
                    parallel::util::detail::handle_remote_exceptions<
2✔
173
                        ExPolicy>::call(r, errors);
2✔
174
                    return traits::compose(send, r.back().get());
2✔
175
                },
2✔
176
                HPX_MOVE(segments)));
177
        }
2✔
178
        /// \endcond
179
    }    // namespace detail
180
}}}      // namespace hpx::parallel::v1
181

182
namespace hpx { namespace segmented {
183

184
    // clang-format off
185
    template <typename SegIter, typename F,
186
        HPX_CONCEPT_REQUIRES_(
187
            hpx::traits::is_iterator<SegIter>::value &&
188
            hpx::traits::is_segmented_iterator<SegIter>::value
189
        )>
190
    // clang-format on
191
    SegIter tag_invoke(hpx::generate_t, SegIter first, SegIter last, F&& f)
192
    {
193
        static_assert(hpx::traits::is_forward_iterator<SegIter>::value,
194
            "Requires at least forward iterator.");
195

196
        if (first == last)
197
        {
198
            return HPX_MOVE(first);
199
        }
200

201
        typedef hpx::traits::segmented_iterator_traits<SegIter> iterator_traits;
202

203
        return hpx::parallel::v1::detail::segmented_generate(
204
            hpx::parallel::v1::detail::generate<
205
                typename iterator_traits::local_iterator>(),
206
            hpx::execution::seq, first, last, HPX_FORWARD(F, f),
207
            std::true_type{});
208
    }
209

210
    // clang-format off
211
    template <typename ExPolicy, typename SegIter, typename F,
212
        HPX_CONCEPT_REQUIRES_(
213
            hpx::is_execution_policy<ExPolicy>::value &&
214
            hpx::traits::is_iterator<SegIter>::value &&
215
            hpx::traits::is_segmented_iterator<SegIter>::value
216
        )>
217
    // clang-format on
218
    typename parallel::util::detail::algorithm_result<ExPolicy, SegIter>::type
219
    tag_invoke(
2✔
220
        hpx::generate_t, ExPolicy&& policy, SegIter first, SegIter last, F&& f)
221
    {
222
        static_assert(hpx::traits::is_forward_iterator<SegIter>::value,
223
            "Requires at least forward iterator.");
224

225
        using is_seq = hpx::is_sequenced_execution_policy<ExPolicy>;
226

227
        if (first == last)
2✔
228
        {
229
            return parallel::util::detail::algorithm_result<ExPolicy,
×
230
                SegIter>::get(HPX_MOVE(first));
231
        }
232

233
        typedef hpx::traits::segmented_iterator_traits<SegIter> iterator_traits;
234

235
        return hpx::parallel::v1::detail::segmented_generate(
2✔
236
            hpx::parallel::v1::detail::generate<
2✔
237
                typename iterator_traits::local_iterator>(),
238
            HPX_FORWARD(ExPolicy, policy), first, last, HPX_FORWARD(F, f),
2✔
239
            is_seq());
2✔
240
    }
2✔
241
}}    // namespace hpx::segmented
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc