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

STEllAR-GROUP / hpx / #853

19 Dec 2022 01:01AM UTC coverage: 86.287% (+0.4%) from 85.912%
#853

push

StellarBot
Merge #6109

6109: Modernize serialization module r=hkaiser a=hkaiser

- flyby separate serialization of Boost types

working towards https://github.com/STEllAR-GROUP/hpx/issues/5497

Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

53 of 53 new or added lines in 6 files covered. (100.0%)

173939 of 201582 relevant lines covered (86.29%)

1931657.12 hits per line

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

1.18
/libs/full/segmented_algorithms/tests/unit/partitioned_vector_inclusive_scan.cpp
1
//  Copyright (c) 2016 Minh-Khanh Do
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
#include <hpx/config.hpp>
8
#if !defined(HPX_COMPUTE_DEVICE_CODE)
9
#include <hpx/hpx_main.hpp>
10
#include <hpx/include/parallel_scan.hpp>
11
#include <hpx/include/partitioned_vector_predef.hpp>
12
#include <hpx/include/runtime.hpp>
13
#include <hpx/modules/testing.hpp>
14
#include <hpx/modules/timing.hpp>
15

16
#include "partitioned_vector_scan.hpp"
17

18
#include <cstddef>
19
#include <iomanip>
20
#include <iostream>
21
#include <type_traits>
22
#include <vector>
23

24
///////////////////////////////////////////////////////////////////////////////
25
#define msg7(a, b, c, d, e, f, g)                                              \
26
    std::cout << std::setw(60) << a << std::setw(40) << b << std::setw(10)     \
27
              << c << std::setw(6) << " " << #d << " " << e << " " << f << " " \
28
              << g << " ";
29
#define msg9(a, b, c, d, e, f, g, h, i)                                        \
30
    std::cout << std::setw(60) << a << std::setw(40) << b << std::setw(10)     \
31
              << c << std::setw(6) << " " << #d << " " << e << " " << f << " " \
32
              << g << " " << h << " " << i << " ";
33

34
///////////////////////////////////////////////////////////////////////////////
35

36
template <typename T>
37
struct opt
38
{
39
    T operator()(T v1, T v2) const
137,287✔
40
    {
41
        return v1 + v2;
137,296✔
42
    }
43
};
44

45
///////////////////////////////////////////////////////////////////////////////
46
template <typename T, typename DistPolicy, typename ExPolicy>
47
void inclusive_scan_algo_tests_with_policy(std::size_t size,
×
48
    DistPolicy const& dist_policy, hpx::partitioned_vector<T>& in,
49
    std::vector<T> ver, ExPolicy const& policy)
50
{
51
    msg7(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
52
        regular, size, dist_policy.get_num_partitions(),
53
        dist_policy.get_localities().size());
54
    hpx::chrono::high_resolution_timer t1;
×
55

56
    std::vector<T> out(in.size());
×
57
    T val(0);
×
58

59
    double e1 = t1.elapsed();
×
60
    t1.restart();
×
61

62
    hpx::inclusive_scan(
×
63
        policy, in.begin(), in.end(), out.begin(), opt<T>(), val);
×
64

65
    double e2 = t1.elapsed();
×
66
    t1.restart();
×
67

68
    HPX_TEST(std::equal(out.begin(), out.end(), ver.begin()));
×
69

70
    double e3 = t1.elapsed();
×
71
    std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3
×
72
              << "\n";
×
73
}
×
74

75
template <typename T, typename DistPolicy, typename ExPolicy>
76
void inclusive_scan_algo_tests_segmented_out_with_policy(std::size_t size,
×
77
    DistPolicy const& in_dist_policy, DistPolicy const& out_dist_policy,
78
    hpx::partitioned_vector<T>& in, hpx::partitioned_vector<T> out,
79
    std::vector<T> ver, ExPolicy const& policy)
80
{
81
    msg9(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
82
        segmented, size, in_dist_policy.get_num_partitions(),
83
        in_dist_policy.get_localities().size(),
84
        out_dist_policy.get_num_partitions(),
85
        out_dist_policy.get_localities().size());
86
    hpx::chrono::high_resolution_timer t1;
×
87

88
    T val(0);
×
89

90
    double e1 = t1.elapsed();
×
91
    t1.restart();
×
92

93
    hpx::inclusive_scan(
×
94
        policy, in.begin(), in.end(), out.begin(), opt<T>(), val);
×
95

96
    double e2 = t1.elapsed();
×
97
    t1.restart();
×
98

99
    verify_values(out, ver);
×
100

101
    double e3 = t1.elapsed();
×
102
    std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3
×
103
              << "\n";
×
104
}
×
105

106
template <typename T, typename DistPolicy, typename ExPolicy>
107
void inclusive_scan_algo_tests_inplace_with_policy(std::size_t size,
×
108
    DistPolicy const& dist_policy, std::vector<T> ver, ExPolicy const& policy)
109
{
110
    msg7(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
111
        inplace, size, dist_policy.get_num_partitions(),
112
        dist_policy.get_localities().size());
113
    hpx::chrono::high_resolution_timer t1;
×
114

115
    hpx::partitioned_vector<T> in(size, dist_policy);
×
116
    iota_vector(in, T(1));
×
117

118
    T val(0);
×
119

120
    double e1 = t1.elapsed();
×
121
    t1.restart();
×
122

123
    hpx::inclusive_scan(
×
124
        policy, in.begin(), in.end(), in.begin(), opt<T>(), val);
×
125

126
    double e2 = t1.elapsed();
×
127
    t1.restart();
×
128

129
    verify_values(in, ver);
×
130

131
    double e3 = t1.elapsed();
×
132
    std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3
×
133
              << "\n";
×
134
}
×
135

136
///////////////////////////////////////////////////////////////////////////////
137

138
template <typename T, typename DistPolicy, typename ExPolicy>
139
void inclusive_scan_algo_tests_with_policy_async(std::size_t size,
×
140
    DistPolicy const& dist_policy, hpx::partitioned_vector<T>& in,
141
    std::vector<T> ver, ExPolicy const& policy)
142
{
143
    msg7(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
144
        async, size, dist_policy.get_num_partitions(),
145
        dist_policy.get_localities().size());
146
    hpx::chrono::high_resolution_timer t1;
×
147

148
    std::vector<T> out(in.size());
×
149
    T val(0);
×
150

151
    double e1 = t1.elapsed();
×
152
    t1.restart();
×
153

154
    auto res = hpx::inclusive_scan(
×
155
        policy, in.begin(), in.end(), out.begin(), opt<T>(), val);
×
156
    res.get();
×
157

158
    double e2 = t1.elapsed();
×
159
    t1.restart();
×
160

161
    HPX_TEST(std::equal(out.begin(), out.end(), ver.begin()));
×
162

163
    double e3 = t1.elapsed();
×
164
    std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3
×
165
              << "\n";
×
166
}
×
167

168
template <typename T, typename DistPolicy, typename ExPolicy>
169
void inclusive_scan_algo_tests_segmented_out_with_policy_async(std::size_t size,
×
170
    DistPolicy const& in_dist_policy, DistPolicy const& out_dist_policy,
171
    hpx::partitioned_vector<T>& in, hpx::partitioned_vector<T> out,
172
    std::vector<T> ver, ExPolicy const& policy)
173
{
174
    msg9(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
175
        async_segmented, size, in_dist_policy.get_num_partitions(),
176
        in_dist_policy.get_localities().size(),
177
        out_dist_policy.get_num_partitions(),
178
        out_dist_policy.get_localities().size());
179
    hpx::chrono::high_resolution_timer t1;
×
180

181
    T val(0);
×
182

183
    double e1 = t1.elapsed();
×
184
    t1.restart();
×
185

186
    auto res = hpx::inclusive_scan(
×
187
        policy, in.begin(), in.end(), out.begin(), opt<T>(), val);
×
188
    res.get();
×
189

190
    double e2 = t1.elapsed();
×
191
    t1.restart();
×
192

193
    verify_values(out, ver);
×
194

195
    double e3 = t1.elapsed();
×
196
    std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3
×
197
              << "\n";
×
198
}
×
199

200
template <typename T, typename DistPolicy, typename ExPolicy>
201
void inclusive_scan_algo_tests_inplace_with_policy_async(std::size_t size,
×
202
    DistPolicy const& dist_policy, std::vector<T> ver, ExPolicy const& policy)
203
{
204
    msg7(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
205
        async_inplace, size, dist_policy.get_num_partitions(),
206
        dist_policy.get_localities().size());
207
    hpx::chrono::high_resolution_timer t1;
×
208

209
    hpx::partitioned_vector<T> in(size, dist_policy);
×
210
    iota_vector(in, T(1));
×
211

212
    T val(0);
×
213

214
    double e1 = t1.elapsed();
×
215
    t1.restart();
×
216

217
    auto res = hpx::inclusive_scan(
×
218
        policy, in.begin(), in.end(), in.begin(), opt<T>(), val);
×
219
    res.get();
×
220

221
    double e2 = t1.elapsed();
×
222
    t1.restart();
×
223

224
    verify_values(in, ver);
×
225

226
    double e3 = t1.elapsed();
×
227
    std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3
×
228
              << "\n";
×
229
}
×
230

231
///////////////////////////////////////////////////////////////////////////////
232

233
template <typename T, typename DistPolicy>
234
void inclusive_scan_tests_with_policy(
×
235
    std::size_t size, DistPolicy const& policy)
236
{
237
    using namespace hpx::execution;
238

239
    // setup partitioned vector to test
240
    hpx::partitioned_vector<T> in(size, policy);
×
241
    iota_vector(in, T(1));
×
242

243
    std::vector<T> ver(in.size());
×
244
    std::iota(ver.begin(), ver.end(), T(1));
×
245
    T val(0);
×
246

247
    hpx::parallel::v1::detail::sequential_inclusive_scan(
×
248
        ver.begin(), ver.end(), ver.begin(), val, opt<T>());
×
249

250
    //sync
251
    inclusive_scan_algo_tests_with_policy<T>(size, policy, in, ver, seq);
×
252
    inclusive_scan_algo_tests_with_policy<T>(size, policy, in, ver, par);
×
253

254
    //async
255
    inclusive_scan_algo_tests_with_policy_async<T>(
×
256
        size, policy, in, ver, seq(task));
×
257
    inclusive_scan_algo_tests_with_policy_async<T>(
×
258
        size, policy, in, ver, par(task));
×
259
}
×
260

261
template <typename T, typename DistPolicy>
262
void inclusive_scan_tests_segmented_out_with_policy(
×
263
    std::size_t size, DistPolicy const& in_policy, DistPolicy const& out_policy)
264
{
265
    using namespace hpx::execution;
266

267
    // setup partitioned vector to test
268
    hpx::partitioned_vector<T> in(size, in_policy);
×
269
    iota_vector(in, T(1));
×
270

271
    hpx::partitioned_vector<T> out(size, out_policy);
×
272

273
    std::vector<T> ver(in.size());
×
274
    std::iota(ver.begin(), ver.end(), T(1));
×
275
    T val(0);
×
276

277
    hpx::parallel::v1::detail::sequential_inclusive_scan(
×
278
        ver.begin(), ver.end(), ver.begin(), val, opt<T>());
×
279

280
    //sync
281
    inclusive_scan_algo_tests_segmented_out_with_policy<T>(
×
282
        size, in_policy, out_policy, in, out, ver, seq);
×
283
    inclusive_scan_algo_tests_segmented_out_with_policy<T>(
×
284
        size, in_policy, out_policy, in, out, ver, par);
×
285

286
    //async
287
    inclusive_scan_algo_tests_segmented_out_with_policy_async<T>(
×
288
        size, in_policy, out_policy, in, out, ver, seq(task));
×
289
    inclusive_scan_algo_tests_segmented_out_with_policy_async<T>(
×
290
        size, in_policy, out_policy, in, out, ver, par(task));
×
291
}
×
292

293
template <typename T, typename DistPolicy>
294
void inclusive_scan_tests_inplace_with_policy(
×
295
    std::size_t size, DistPolicy const& policy)
296
{
297
    using namespace hpx::execution;
298

299
    // setup verification vector
300
    std::vector<T> ver(size);
×
301
    std::iota(ver.begin(), ver.end(), T(1));
×
302
    T val(0);
×
303

304
    hpx::parallel::v1::detail::sequential_inclusive_scan(
×
305
        ver.begin(), ver.end(), ver.begin(), val, opt<T>());
×
306

307
    // sync
308
    inclusive_scan_algo_tests_inplace_with_policy<T>(size, policy, ver, seq);
×
309
    inclusive_scan_algo_tests_inplace_with_policy<T>(size, policy, ver, par);
×
310

311
    // async
312
    inclusive_scan_algo_tests_inplace_with_policy_async<T>(
×
313
        size, policy, ver, seq(task));
×
314
    inclusive_scan_algo_tests_inplace_with_policy_async<T>(
×
315
        size, policy, ver, par(task));
×
316
}
×
317

318
///////////////////////////////////////////////////////////////////////////////
319

320
template <typename T>
321
void inclusive_scan_tests(std::vector<hpx::id_type>& localities)
×
322
{
323
#if defined(HPX_DEBUG)
324
    std::size_t const length = 10000;
×
325
#else
326
    std::size_t const length = 100000;
327
#endif
328

329
    inclusive_scan_tests_with_policy<T>(length, hpx::container_layout);
×
330
    inclusive_scan_tests_with_policy<T>(length, hpx::container_layout(3));
×
331
    inclusive_scan_tests_with_policy<T>(
×
332
        length, hpx::container_layout(3, localities));
×
333
    inclusive_scan_tests_with_policy<T>(
×
334
        length, hpx::container_layout(localities));
×
335

336
    inclusive_scan_tests_with_policy<T>(1000, hpx::container_layout(1000));
×
337

338
    // multiple localities needed for the following tests
339
    inclusive_scan_tests_segmented_out_with_policy<T>(length,
×
340
        hpx::container_layout(localities), hpx::container_layout(localities));
×
341

342
    inclusive_scan_tests_segmented_out_with_policy<T>(
×
343
        length, hpx::container_layout(localities), hpx::container_layout(3));
×
344

345
    inclusive_scan_tests_segmented_out_with_policy<T>(
×
346
        length, hpx::container_layout(localities), hpx::container_layout(10));
×
347

348
    inclusive_scan_tests_inplace_with_policy<T>(
×
349
        length, hpx::container_layout(localities));
×
350
}
×
351

352
///////////////////////////////////////////////////////////////////////////////
353
int main()
×
354
{
355
    std::vector<hpx::id_type> localities = hpx::find_all_localities();
×
356
    inclusive_scan_tests<long long>(localities);
×
357
    return hpx::util::report_errors();
×
358
}
×
359
#endif
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