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

STEllAR-GROUP / hpx / #875

25 Jan 2023 03:11PM UTC coverage: 86.39% (+0.5%) from 85.911%
#875

push

StellarBot
Merge #6151

6151: Refactoring the Manual page in documentation r=hkaiser a=dimitraka

- Move the instructions to build the tests and examples in a new separate page 
- Add references of the most important CMake options or the comprehensive list of CMake options
- Rename the CMake options page (title was too long)
- Refer to the new page of how to build the examples in the examples section itself


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

174481 of 201968 relevant lines covered (86.39%)

1898746.94 hits per line

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

0.0
/libs/full/segmented_algorithms/tests/unit/partitioned_vector_exclusive_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
// The vector types to be used are defined in partitioned_vector module.
26
// HPX_REGISTER_PARTITIONED_VECTOR(double)
27
// HPX_REGISTER_PARTITIONED_VECTOR(int)
28

29
#define msg7(a, b, c, d, e, f, g)                                              \
30
    std::cout << std::setw(60) << a << std::setw(40) << b << std::setw(10)     \
31
              << c << std::setw(6) << " " << #d << " " << e << " " << f << " " \
32
              << g << " ";
33
#define msg9(a, b, c, d, e, f, g, h, i)                                        \
34
    std::cout << std::setw(60) << a << std::setw(40) << b << std::setw(10)     \
35
              << c << std::setw(6) << " " << #d << " " << e << " " << f << " " \
36
              << g << " " << h << " " << i << " ";
37

38
///////////////////////////////////////////////////////////////////////////////
39

40
template <typename T>
41
struct opt
42
{
43
    T operator()(T v1, T v2) const
×
44
    {
45
        return v1 + v2;
×
46
    }
47
};
48

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

60
    std::vector<T> out(in.size());
×
61
    T val(0);
×
62

63
    double e1 = t1.elapsed();
×
64
    t1.restart();
×
65

66
    hpx::exclusive_scan(
×
67
        policy, in.begin(), in.end(), out.begin(), val, opt<T>());
×
68

69
    double e2 = t1.elapsed();
×
70
    t1.restart();
×
71

72
    HPX_TEST(std::equal(out.begin(), out.end(), ver.begin()));
×
73

74
    double e3 = t1.elapsed();
×
75
    std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3
×
76
              << "\n";
×
77
}
×
78

79
template <typename T, typename DistPolicy>
80
void exclusive_scan_algo_tests_segmented_out_with_policy_seq(std::size_t size,
×
81
    DistPolicy const& in_dist_policy, DistPolicy const& out_dist_policy,
82
    hpx::partitioned_vector<T>& in, hpx::partitioned_vector<T> out,
83
    std::vector<T> const& ver)
84
{
85
    msg9(typeid(hpx::execution::seq).name(), typeid(DistPolicy).name(),
×
86
        typeid(T).name(), segmented, size, in_dist_policy.get_num_partitions(),
87
        in_dist_policy.get_localities().size(),
88
        out_dist_policy.get_num_partitions(),
89
        out_dist_policy.get_localities().size());
90
    hpx::chrono::high_resolution_timer t1;
×
91

92
    T val(0);
×
93

94
    double e1 = t1.elapsed();
×
95
    t1.restart();
×
96

97
    hpx::exclusive_scan(in.begin(), in.end(), out.begin(), val, opt<T>());
×
98

99
    double e2 = t1.elapsed();
×
100
    t1.restart();
×
101

102
    verify_values(out, ver);
×
103

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

109
template <typename T, typename DistPolicy, typename ExPolicy>
110
void exclusive_scan_algo_tests_segmented_out_with_policy(std::size_t size,
×
111
    DistPolicy const& in_dist_policy, DistPolicy const& out_dist_policy,
112
    hpx::partitioned_vector<T>& in, hpx::partitioned_vector<T> out,
113
    std::vector<T> const& ver, ExPolicy const& policy)
114
{
115
    msg9(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
116
        segmented, size, in_dist_policy.get_num_partitions(),
117
        in_dist_policy.get_localities().size(),
118
        out_dist_policy.get_num_partitions(),
119
        out_dist_policy.get_localities().size());
120
    hpx::chrono::high_resolution_timer t1;
×
121

122
    T val(0);
×
123

124
    double e1 = t1.elapsed();
×
125
    t1.restart();
×
126

127
    hpx::exclusive_scan(
×
128
        policy, in.begin(), in.end(), out.begin(), val, opt<T>());
×
129

130
    double e2 = t1.elapsed();
×
131
    t1.restart();
×
132

133
    verify_values(out, ver);
×
134

135
    double e3 = t1.elapsed();
×
136
    std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3
×
137
              << "\n";
×
138
}
×
139

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

150
    hpx::partitioned_vector<T> in(size, dist_policy);
×
151
    iota_vector(in, T(1));
×
152

153
    T val(0);
×
154

155
    double e1 = t1.elapsed();
×
156
    t1.restart();
×
157

158
    hpx::exclusive_scan(
×
159
        policy, in.begin(), in.end(), in.begin(), val, opt<T>());
×
160

161
    double e2 = t1.elapsed();
×
162
    t1.restart();
×
163

164
    verify_values(in, ver);
×
165

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

171
///////////////////////////////////////////////////////////////////////////////
172

173
template <typename T, typename DistPolicy, typename ExPolicy>
174
void exclusive_scan_algo_tests_with_policy_async(std::size_t size,
×
175
    DistPolicy const& dist_policy, hpx::partitioned_vector<T>& in,
176
    std::vector<T> const& ver, ExPolicy const& policy)
177
{
178
    msg7(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
179
        async, size, dist_policy.get_num_partitions(),
180
        dist_policy.get_localities().size());
181
    hpx::chrono::high_resolution_timer t1;
×
182

183
    std::vector<T> out(in.size());
×
184
    T val(0);
×
185

186
    double e1 = t1.elapsed();
×
187
    t1.restart();
×
188

189
    auto res = hpx::exclusive_scan(
×
190
        policy, in.begin(), in.end(), out.begin(), val, opt<T>());
×
191
    res.get();
×
192

193
    double e2 = t1.elapsed();
×
194
    t1.restart();
×
195

196
    HPX_TEST(std::equal(out.begin(), out.end(), ver.begin()));
×
197

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

203
template <typename T, typename DistPolicy, typename ExPolicy>
204
void exclusive_scan_algo_tests_segmented_out_with_policy_async(std::size_t size,
×
205
    DistPolicy const& in_dist_policy, DistPolicy const& out_dist_policy,
206
    hpx::partitioned_vector<T>& in, hpx::partitioned_vector<T> out,
207
    std::vector<T> const& ver, ExPolicy const& policy)
208
{
209
    msg9(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
210
        async_segmented, size, in_dist_policy.get_num_partitions(),
211
        in_dist_policy.get_localities().size(),
212
        out_dist_policy.get_num_partitions(),
213
        out_dist_policy.get_localities().size());
214
    hpx::chrono::high_resolution_timer t1;
×
215

216
    t1.restart();
×
217
    T val(0);
×
218

219
    double e1 = t1.elapsed();
×
220
    t1.restart();
×
221

222
    auto res = hpx::exclusive_scan(
×
223
        policy, in.begin(), in.end(), out.begin(), val, opt<T>());
×
224
    res.get();
×
225

226
    double e2 = t1.elapsed();
×
227
    t1.restart();
×
228

229
    verify_values(out, ver);
×
230

231
    double e3 = t1.elapsed();
×
232
    std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3
×
233
              << "\n";
×
234
}
×
235

236
template <typename T, typename DistPolicy, typename ExPolicy>
237
void exclusive_scan_algo_tests_inplace_with_policy_async(std::size_t size,
×
238
    DistPolicy const& dist_policy, std::vector<T> const& ver,
239
    ExPolicy const& policy)
240
{
241
    msg7(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
242
        async_inplace, size, dist_policy.get_num_partitions(),
243
        dist_policy.get_localities().size());
244
    hpx::chrono::high_resolution_timer t1;
×
245

246
    hpx::partitioned_vector<T> in(size, dist_policy);
×
247
    iota_vector(in, T(1));
×
248

249
    T val(0);
×
250

251
    double e1 = t1.elapsed();
×
252
    t1.restart();
×
253

254
    auto res = hpx::exclusive_scan(
×
255
        policy, in.begin(), in.end(), in.begin(), val, opt<T>());
×
256
    res.get();
×
257

258
    double e2 = t1.elapsed();
×
259
    t1.restart();
×
260

261
    verify_values(in, ver);
×
262

263
    double e3 = t1.elapsed();
×
264
    std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3
×
265
              << "\n";
×
266
}
×
267

268
///////////////////////////////////////////////////////////////////////////////
269

270
template <typename T, typename DistPolicy>
271
void exclusive_scan_tests_with_policy(
×
272
    std::size_t size, DistPolicy const& policy)
273
{
274
    using namespace hpx::execution;
275

276
    // setup partitioned vector to test
277
    hpx::partitioned_vector<T> in(size, policy);
×
278
    iota_vector(in, T(1));
×
279

280
    std::vector<T> ver(in.size());
×
281
    std::iota(ver.begin(), ver.end(), T(1));
×
282
    T val(0);
×
283

284
    hpx::parallel::v1::detail::sequential_exclusive_scan(
×
285
        ver.begin(), ver.end(), ver.begin(), val, opt<T>());
×
286

287
    //sync
288
    exclusive_scan_algo_tests_with_policy<T>(size, policy, in, ver, seq);
×
289
    exclusive_scan_algo_tests_with_policy<T>(size, policy, in, ver, par);
×
290

291
    //async
292
    exclusive_scan_algo_tests_with_policy_async<T>(
×
293
        size, policy, in, ver, seq(task));
×
294
    exclusive_scan_algo_tests_with_policy_async<T>(
×
295
        size, policy, in, ver, par(task));
×
296
}
×
297

298
template <typename T, typename DistPolicy>
299
void exclusive_scan_tests_segmented_out_with_policy(
×
300
    std::size_t size, DistPolicy const& in_policy, DistPolicy const& out_policy)
301
{
302
    using namespace hpx::execution;
303

304
    // setup partitioned vector to test
305
    hpx::partitioned_vector<T> in(size, in_policy);
×
306
    iota_vector(in, T(1));
×
307

308
    hpx::partitioned_vector<T> out(size, out_policy);
×
309

310
    std::vector<T> ver(in.size());
×
311
    std::iota(ver.begin(), ver.end(), T(1));
×
312
    T val(0);
×
313

314
    hpx::parallel::v1::detail::sequential_exclusive_scan(
×
315
        ver.begin(), ver.end(), ver.begin(), val, opt<T>());
×
316

317
    exclusive_scan_algo_tests_segmented_out_with_policy_seq<T>(
×
318
        size, in_policy, out_policy, in, out, ver);
×
319

320
    //sync
321
    exclusive_scan_algo_tests_segmented_out_with_policy<T>(
×
322
        size, in_policy, out_policy, in, out, ver, seq);
×
323
    exclusive_scan_algo_tests_segmented_out_with_policy<T>(
×
324
        size, in_policy, out_policy, in, out, ver, par);
×
325

326
    //async
327
    exclusive_scan_algo_tests_segmented_out_with_policy_async<T>(
×
328
        size, in_policy, out_policy, in, out, ver, seq(task));
×
329
    exclusive_scan_algo_tests_segmented_out_with_policy_async<T>(
×
330
        size, in_policy, out_policy, in, out, ver, par(task));
×
331
}
×
332

333
template <typename T, typename DistPolicy>
334
void exclusive_scan_tests_inplace_with_policy(
×
335
    std::size_t size, DistPolicy const& policy)
336
{
337
    using namespace hpx::execution;
338

339
    // setup verification vector
340
    std::vector<T> ver(size);
×
341
    std::iota(ver.begin(), ver.end(), T(1));
×
342
    T val(0);
×
343

344
    hpx::parallel::v1::detail::sequential_exclusive_scan(
×
345
        ver.begin(), ver.end(), ver.begin(), val, opt<T>());
×
346

347
    // sync
348
    exclusive_scan_algo_tests_inplace_with_policy<T>(size, policy, ver, seq);
×
349
    exclusive_scan_algo_tests_inplace_with_policy<T>(size, policy, ver, par);
×
350

351
    // async
352
    exclusive_scan_algo_tests_inplace_with_policy_async<T>(
×
353
        size, policy, ver, seq(task));
×
354
    exclusive_scan_algo_tests_inplace_with_policy_async<T>(
×
355
        size, policy, ver, par(task));
×
356
}
×
357

358
///////////////////////////////////////////////////////////////////////////////
359

360
template <typename T>
361
void exclusive_scan_tests(std::vector<hpx::id_type>& localities)
×
362
{
363
#if defined(HPX_DEBUG)
364
    std::size_t const length = 10000;
×
365
#else
366
    std::size_t const length = 100000;
367
#endif
368

369
    exclusive_scan_tests_with_policy<T>(length, hpx::container_layout);
×
370
    exclusive_scan_tests_with_policy<T>(length, hpx::container_layout(3));
×
371
    exclusive_scan_tests_with_policy<T>(
×
372
        length, hpx::container_layout(3, localities));
×
373
    exclusive_scan_tests_with_policy<T>(
×
374
        length, hpx::container_layout(localities));
×
375

376
    exclusive_scan_tests_with_policy<T>(1000, hpx::container_layout(1000));
×
377

378
    // multiple localities needed for the following tests
379
    exclusive_scan_tests_segmented_out_with_policy<T>(length,
×
380
        hpx::container_layout(localities), hpx::container_layout(localities));
×
381

382
    exclusive_scan_tests_segmented_out_with_policy<T>(
×
383
        length, hpx::container_layout(localities), hpx::container_layout(3));
×
384

385
    exclusive_scan_tests_segmented_out_with_policy<T>(
×
386
        length, hpx::container_layout(localities), hpx::container_layout(10));
×
387

388
    exclusive_scan_tests_inplace_with_policy<T>(
×
389
        length, hpx::container_layout(localities));
×
390
}
×
391

392
///////////////////////////////////////////////////////////////////////////////
393
int main()
×
394
{
395
    std::vector<hpx::id_type> localities = hpx::find_all_localities();
×
396
    exclusive_scan_tests<long long>(localities);
×
397

398
    return hpx::util::report_errors();
×
399
}
×
400
#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