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

STEllAR-GROUP / hpx / #869

20 Jan 2023 12:14AM UTC coverage: 86.397% (-0.09%) from 86.487%
#869

push

web-flow
Merge pull request #6142 from msimberg/update-daint-jenkins-perftest-references

Update performance test references for Piz Daint

174481 of 201952 relevant lines covered (86.4%)

2150263.37 hits per line

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

1.17
/libs/full/segmented_algorithms/tests/unit/partitioned_vector_exclusive_scan2.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
136,221✔
44
    {
45
        return v1 + v2;
136,234✔
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, typename ExPolicy>
80
void exclusive_scan_algo_tests_segmented_out_with_policy(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, ExPolicy const& policy)
84
{
85
    msg9(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
86
        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(
×
98
        policy, in.begin(), in.end(), out.begin(), val, opt<T>());
×
99

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

103
    verify_values(out, ver);
×
104

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

110
template <typename T, typename DistPolicy, typename ExPolicy>
111
void exclusive_scan_algo_tests_inplace_with_policy(std::size_t size,
×
112
    DistPolicy const& dist_policy, std::vector<T> const& ver,
113
    ExPolicy const& policy)
114
{
115
    msg7(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
116
        inplace, size, dist_policy.get_num_partitions(),
117
        dist_policy.get_localities().size());
118
    hpx::chrono::high_resolution_timer t1;
×
119

120
    hpx::partitioned_vector<T> in(size, dist_policy);
×
121
    iota_vector(in, T(1));
×
122

123
    T val(0);
×
124

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

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

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

134
    verify_values(in, ver);
×
135

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

141
///////////////////////////////////////////////////////////////////////////////
142

143
template <typename T, typename DistPolicy, typename ExPolicy>
144
void exclusive_scan_algo_tests_with_policy_async(std::size_t size,
×
145
    DistPolicy const& dist_policy, hpx::partitioned_vector<T>& in,
146
    std::vector<T> const& ver, ExPolicy const& policy)
147
{
148
    msg7(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
149
        async, size, dist_policy.get_num_partitions(),
150
        dist_policy.get_localities().size());
151
    hpx::chrono::high_resolution_timer t1;
×
152

153
    std::vector<T> out(in.size());
×
154
    T val(0);
×
155

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

159
    auto res = hpx::exclusive_scan(
×
160
        policy, in.begin(), in.end(), out.begin(), val, opt<T>());
×
161
    res.get();
×
162

163
    double e2 = t1.elapsed();
×
164
    t1.restart();
×
165

166
    HPX_TEST(std::equal(out.begin(), out.end(), ver.begin()));
×
167

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

173
template <typename T, typename DistPolicy, typename ExPolicy>
174
void exclusive_scan_algo_tests_segmented_out_with_policy_async(std::size_t size,
×
175
    DistPolicy const& in_dist_policy, DistPolicy const& out_dist_policy,
176
    hpx::partitioned_vector<T>& in, hpx::partitioned_vector<T> out,
177
    std::vector<T> const& ver, ExPolicy const& policy)
178
{
179
    msg9(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
180
        async_segmented, size, in_dist_policy.get_num_partitions(),
181
        in_dist_policy.get_localities().size(),
182
        out_dist_policy.get_num_partitions(),
183
        out_dist_policy.get_localities().size());
184
    hpx::chrono::high_resolution_timer t1;
×
185

186
    t1.restart();
×
187
    T val(0);
×
188

189
    double e1 = t1.elapsed();
×
190
    t1.restart();
×
191

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

196
    double e2 = t1.elapsed();
×
197
    t1.restart();
×
198

199
    verify_values(out, ver);
×
200

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

206
template <typename T, typename DistPolicy, typename ExPolicy>
207
void exclusive_scan_algo_tests_inplace_with_policy_async(std::size_t size,
×
208
    DistPolicy const& dist_policy, std::vector<T> const& ver,
209
    ExPolicy const& policy)
210
{
211
    msg7(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(),
×
212
        async_inplace, size, dist_policy.get_num_partitions(),
213
        dist_policy.get_localities().size());
214
    hpx::chrono::high_resolution_timer t1;
×
215

216
    hpx::partitioned_vector<T> in(size, dist_policy);
×
217
    iota_vector(in, T(1));
×
218

219
    T val(0);
×
220

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

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

228
    double e2 = t1.elapsed();
×
229
    t1.restart();
×
230

231
    verify_values(in, ver);
×
232

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

238
///////////////////////////////////////////////////////////////////////////////
239

240
template <typename T, typename DistPolicy>
241
void exclusive_scan_tests_with_policy(
×
242
    std::size_t size, DistPolicy const& policy)
243
{
244
    using namespace hpx::execution;
245

246
    // setup partitioned vector to test
247
    hpx::partitioned_vector<T> in(size, policy);
×
248
    iota_vector(in, T(1));
×
249

250
    std::vector<T> ver(in.size());
×
251
    std::iota(ver.begin(), ver.end(), T(1));
×
252
    T val(0);
×
253

254
    hpx::parallel::v1::detail::sequential_exclusive_scan(
×
255
        ver.begin(), ver.end(), ver.begin(), val, opt<T>());
×
256

257
    //sync
258
    exclusive_scan_algo_tests_with_policy<T>(size, policy, in, ver, seq);
×
259
    exclusive_scan_algo_tests_with_policy<T>(size, policy, in, ver, par);
×
260

261
    //async
262
    exclusive_scan_algo_tests_with_policy_async<T>(
×
263
        size, policy, in, ver, seq(task));
×
264
    exclusive_scan_algo_tests_with_policy_async<T>(
×
265
        size, policy, in, ver, par(task));
×
266
}
×
267

268
template <typename T, typename DistPolicy>
269
void exclusive_scan_tests_segmented_out_with_policy(
×
270
    std::size_t size, DistPolicy const& in_policy, DistPolicy const& out_policy)
271
{
272
    using namespace hpx::execution;
273

274
    // setup partitioned vector to test
275
    hpx::partitioned_vector<T> in(size, in_policy);
×
276
    iota_vector(in, T(1));
×
277

278
    hpx::partitioned_vector<T> out(size, out_policy);
×
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_segmented_out_with_policy<T>(
×
289
        size, in_policy, out_policy, in, out, ver, seq);
×
290
    exclusive_scan_algo_tests_segmented_out_with_policy<T>(
×
291
        size, in_policy, out_policy, in, out, ver, par);
×
292

293
    //async
294
    exclusive_scan_algo_tests_segmented_out_with_policy_async<T>(
×
295
        size, in_policy, out_policy, in, out, ver, seq(task));
×
296
    exclusive_scan_algo_tests_segmented_out_with_policy_async<T>(
×
297
        size, in_policy, out_policy, in, out, ver, par(task));
×
298
}
×
299

300
template <typename T, typename DistPolicy>
301
void exclusive_scan_tests_inplace_with_policy(
×
302
    std::size_t size, DistPolicy const& policy)
303
{
304
    using namespace hpx::execution;
305

306
    // setup verification vector
307
    std::vector<T> ver(size);
×
308
    std::iota(ver.begin(), ver.end(), T(1));
×
309
    T val(0);
×
310

311
    hpx::parallel::v1::detail::sequential_exclusive_scan(
×
312
        ver.begin(), ver.end(), ver.begin(), val, opt<T>());
×
313

314
    // sync
315
    exclusive_scan_algo_tests_inplace_with_policy<T>(size, policy, ver, seq);
×
316
    exclusive_scan_algo_tests_inplace_with_policy<T>(size, policy, ver, par);
×
317

318
    // async
319
    exclusive_scan_algo_tests_inplace_with_policy_async<T>(
×
320
        size, policy, ver, seq(task));
×
321
    exclusive_scan_algo_tests_inplace_with_policy_async<T>(
×
322
        size, policy, ver, par(task));
×
323
}
×
324

325
///////////////////////////////////////////////////////////////////////////////
326

327
template <typename T>
328
void exclusive_scan_tests(std::vector<hpx::id_type>& localities)
×
329
{
330
#if defined(HPX_DEBUG)
331
    std::size_t const length = 10000;
×
332
#else
333
    std::size_t const length = 100000;
334
#endif
335

336
    exclusive_scan_tests_with_policy<T>(length, hpx::container_layout);
×
337
    exclusive_scan_tests_with_policy<T>(length, hpx::container_layout(3));
×
338
    exclusive_scan_tests_with_policy<T>(
×
339
        length, hpx::container_layout(3, localities));
×
340
    exclusive_scan_tests_with_policy<T>(
×
341
        length, hpx::container_layout(localities));
×
342

343
    exclusive_scan_tests_with_policy<T>(1000, hpx::container_layout(1000));
×
344

345
    // multiple localities needed for the following tests
346
    exclusive_scan_tests_segmented_out_with_policy<T>(length,
×
347
        hpx::container_layout(localities), hpx::container_layout(localities));
×
348

349
    exclusive_scan_tests_segmented_out_with_policy<T>(
×
350
        length, hpx::container_layout(localities), hpx::container_layout(3));
×
351

352
    exclusive_scan_tests_segmented_out_with_policy<T>(
×
353
        length, hpx::container_layout(localities), hpx::container_layout(10));
×
354

355
    exclusive_scan_tests_inplace_with_policy<T>(
×
356
        length, hpx::container_layout(localities));
×
357
}
×
358

359
///////////////////////////////////////////////////////////////////////////////
360

361
int main()
×
362
{
363
    std::vector<hpx::id_type> localities = hpx::find_all_localities();
×
364
    exclusive_scan_tests<double>(localities);
×
365

366
    return hpx::util::report_errors();
×
367
}
×
368
#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

© 2025 Coveralls, Inc