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

STEllAR-GROUP / hpx / #851

16 Dec 2022 12:27PM CUT coverage: 86.568% (+0.2%) from 86.404%
#851

push

StellarBot
Merge #6104

6104: Adding parameters API: measure_iteration r=hkaiser a=hkaiser

- split `get_chunk_size` CP into `measure_iteration` and modified `get_chunk_size`
- introducing a breaking change to `get_chunk_size` and `processing_units_count` customization point, those now expect the time for one iteration

The new APIs are:
```
    template <typename Target, typename F>
    hpx::chrono::steady_duration measure_iteration(
        Target&&, F&&, std::size_t num_tasks);

    template <typename Target>
    std::size_t processing_units_count(
        Target&&, hpx::chrono::steady_duration const&, std::size_t num_tasks);

    template <typename Target>
    std::size_t get_chunk_size(Target&&,
        hpx::chrono::steady_duration const&, std::size_t num_cores,
        std::size_t num_tasks);
```
This also moves all executor parameter objects to `namespace hpx::execution::experimental`. 

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

209 of 209 new or added lines in 34 files covered. (100.0%)

174475 of 201546 relevant lines covered (86.57%)

1888115.1 hits per line

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

98.43
/libs/core/algorithms/tests/unit/container_algorithms/lexicographical_compare_range.cpp
1
//  Copyright (c) 2018 Christopher Ogle
2
//  Copyright (c) 2020 Hartmut Kaiser
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/iterator_support/tests/iter_sent.hpp>
9
#include <hpx/local/init.hpp>
10
#include <hpx/modules/testing.hpp>
11
#include <hpx/parallel/container_algorithms/lexicographical_compare.hpp>
12

13
#include <algorithm>
14
#include <iostream>
15
#include <iterator>
16
#include <random>
17
#include <string>
18
#include <unordered_set>
19
#include <vector>
20

21
#include "test_utils.hpp"
22

23
////////////////////////////////////////////////////////////////////////////
24
unsigned int seed;
25
std::mt19937 gen;
1✔
26
std::uniform_int_distribution<> dis(0, 25);
1✔
27

28
void test_lexicographical_compare_sent()
2✔
29
{
30
    // ensure all characters are unique
31
    std::unordered_set<unsigned char> uset;
2✔
32

33
    std::vector<char> c1(7);
2✔
34
    std::generate(std::begin(c1), std::end(c1), [&uset]() {
16✔
35
        unsigned char c = 'a' + dis(gen);
14✔
36
        while (uset.find(c) != uset.end())
17✔
37
        {
38
            c = 'a' + dis(gen);
3✔
39
        }
40
        uset.insert(c);
14✔
41
        return c;
14✔
42
    });
43

44
    uset.clear();
2✔
45
    std::vector<char> c2(7);
2✔
46
    std::generate(std::begin(c2), std::end(c2), [&uset]() {
16✔
47
        unsigned char c = 'a' + dis(gen);
14✔
48
        while (uset.find(c) != uset.end())
14✔
49
        {
50
            c = 'a' + dis(gen);
×
51
        }
52
        uset.insert(c);
14✔
53
        return c;
14✔
54
    });
55

56
    bool actual_result1 = std::lexicographical_compare(
2✔
57
        std::begin(c1), std::begin(c1) + 5, std::begin(c2), std::begin(c2) + 5);
2✔
58
    bool result1 = hpx::ranges::lexicographical_compare(std::begin(c1),
4✔
59
        sentinel<char>{*(std::begin(c1) + 5)}, std::begin(c2),
2✔
60
        sentinel<char>{*(std::begin(c2) + 5)});
2✔
61

62
    bool actual_result2 = std::lexicographical_compare(
2✔
63
        std::begin(c2), std::begin(c2) + 5, std::begin(c1), std::begin(c1) + 5);
2✔
64
    bool result2 = hpx::ranges::lexicographical_compare(std::begin(c2),
4✔
65
        sentinel<char>{*(std::begin(c2) + 5)}, std::begin(c1),
2✔
66
        sentinel<char>{*(std::begin(c1) + 5)});
2✔
67

68
    bool actual_result3 = std::lexicographical_compare(
2✔
69
        std::begin(c1), std::begin(c1) + 5, std::begin(c1), std::begin(c1) + 5);
2✔
70
    bool result3 = hpx::ranges::lexicographical_compare(std::begin(c1),
4✔
71
        sentinel<char>{*(std::begin(c1) + 5)}, std::begin(c1),
2✔
72
        sentinel<char>{*(std::begin(c1) + 5)});
2✔
73

74
    HPX_TEST_EQ(actual_result1, result1);
2✔
75
    HPX_TEST_EQ(actual_result2, result2);
2✔
76
    HPX_TEST_EQ(actual_result3, result3);
2✔
77

78
    // check corner cases
79
    std::vector<char> c3 = {1, 1, 1, 1, 3, 2, 2, 8};
2✔
80
    std::vector<char> c4 = {1, 1, 1, 1, 3, 5, 5, 8};
2✔
81
    auto result4 = hpx::ranges::lexicographical_compare(
2✔
82
        std::begin(c3), sentinel<char>{3}, std::begin(c4), sentinel<char>{3});
2✔
83
    auto result5 = hpx::ranges::lexicographical_compare(
2✔
84
        std::begin(c3), sentinel<char>{8}, std::begin(c4), sentinel<char>{8});
2✔
85

86
    HPX_TEST_EQ(false, result4);
2✔
87
    HPX_TEST_EQ(true, result5);
2✔
88
}
2✔
89

90
template <typename ExPolicy>
91
void test_lexicographical_compare_sent(ExPolicy policy)
6✔
92
{
93
    static_assert(hpx::is_execution_policy<ExPolicy>::value,
94
        "hpx::is_execution_policy<ExPolicy>::value");
95

96
    // ensure all characters are unique
97
    std::unordered_set<unsigned char> uset;
6✔
98

99
    std::vector<char> c1(7);
6✔
100
    std::generate(std::begin(c1), std::end(c1), [&uset]() {
48✔
101
        unsigned char c = 'a' + dis(gen);
42✔
102
        while (uset.find(c) != uset.end())
47✔
103
        {
104
            c = 'a' + dis(gen);
5✔
105
        }
106
        uset.insert(c);
42✔
107
        return c;
42✔
108
    });
109

110
    uset.clear();
6✔
111
    std::vector<char> c2(7);
6✔
112
    std::generate(std::begin(c2), std::end(c2), [&uset]() {
48✔
113
        unsigned char c = 'a' + dis(gen);
42✔
114
        while (uset.find(c) != uset.end())
48✔
115
        {
116
            c = 'a' + dis(gen);
6✔
117
        }
118
        uset.insert(c);
42✔
119
        return c;
42✔
120
    });
121

122
    bool actual_result1 = std::lexicographical_compare(
6✔
123
        std::begin(c1), std::begin(c1) + 5, std::begin(c2), std::begin(c2) + 5);
6✔
124
    bool result1 = hpx::ranges::lexicographical_compare(policy, std::begin(c1),
12✔
125
        sentinel<char>{*(std::begin(c1) + 5)}, std::begin(c2),
6✔
126
        sentinel<char>{*(std::begin(c2) + 5)});
6✔
127

128
    bool actual_result2 = std::lexicographical_compare(
6✔
129
        std::begin(c2), std::begin(c2) + 5, std::begin(c1), std::begin(c1) + 5);
6✔
130
    bool result2 = hpx::ranges::lexicographical_compare(policy, std::begin(c2),
12✔
131
        sentinel<char>{*(std::begin(c2) + 5)}, std::begin(c1),
6✔
132
        sentinel<char>{*(std::begin(c1) + 5)});
6✔
133

134
    bool actual_result3 = std::lexicographical_compare(
6✔
135
        std::begin(c1), std::begin(c1) + 5, std::begin(c1), std::begin(c1) + 5);
6✔
136
    bool result3 = hpx::ranges::lexicographical_compare(policy, std::begin(c1),
12✔
137
        sentinel<char>{*(std::begin(c1) + 5)}, std::begin(c1),
6✔
138
        sentinel<char>{*(std::begin(c1) + 5)});
6✔
139

140
    HPX_TEST_EQ(actual_result1, result1);
6✔
141
    HPX_TEST_EQ(actual_result2, result2);
6✔
142
    HPX_TEST_EQ(actual_result3, result3);
6✔
143

144
    // check corner cases
145
    std::vector<char> c3 = {1, 1, 1, 1, 3, 2, 2, 8};
6✔
146
    std::vector<char> c4 = {1, 1, 1, 1, 3, 5, 5, 8};
6✔
147
    auto result4 = hpx::ranges::lexicographical_compare(policy, std::begin(c3),
12✔
148
        sentinel<char>{3}, std::begin(c4), sentinel<char>{3});
6✔
149
    auto result5 = hpx::ranges::lexicographical_compare(policy, std::begin(c3),
12✔
150
        sentinel<char>{8}, std::begin(c4), sentinel<char>{8});
6✔
151

152
    HPX_TEST_EQ(false, result4);
6✔
153
    HPX_TEST_EQ(true, result5);
6✔
154
}
6✔
155

156
template <typename IteratorTag>
157
void test_lexicographical_compare(IteratorTag)
2✔
158
{
159
    std::vector<char> c1(10);
2✔
160
    std::generate(
2✔
161
        std::begin(c1), std::end(c1), []() { return 'a' + dis(gen); });
22✔
162

163
    std::vector<char> c2(10);
2✔
164
    std::generate(
2✔
165
        std::begin(c2), std::end(c2), []() { return 'a' + dis(gen); });
22✔
166

167
    bool actual_result1 = std::lexicographical_compare(
2✔
168
        std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
2✔
169
    bool result1 = hpx::ranges::lexicographical_compare(c1, c2);
2✔
170

171
    bool actual_result2 = std::lexicographical_compare(
2✔
172
        std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
2✔
173
    bool result2 = hpx::ranges::lexicographical_compare(c1, c2);
2✔
174

175
    bool actual_result3 = std::lexicographical_compare(
2✔
176
        std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
2✔
177
    bool result3 = hpx::ranges::lexicographical_compare(c1, c2);
2✔
178

179
    HPX_TEST_EQ(actual_result1, result1);
2✔
180
    HPX_TEST_EQ(actual_result2, result2);
2✔
181
    HPX_TEST_EQ(actual_result3, result3);
2✔
182
}
2✔
183

184
template <typename ExPolicy, typename IteratorTag>
185
void test_lexicographical_compare(ExPolicy policy, IteratorTag)
6✔
186
{
187
    static_assert(hpx::is_execution_policy<ExPolicy>::value,
188
        "hpx::is_execution_policy<ExPolicy>::value");
189

190
    std::vector<char> c1(10);
6✔
191
    std::generate(
6✔
192
        std::begin(c1), std::end(c1), []() { return 'a' + dis(gen); });
66✔
193

194
    std::vector<char> c2(10);
6✔
195
    std::generate(
6✔
196
        std::begin(c2), std::end(c2), []() { return 'a' + dis(gen); });
66✔
197

198
    bool actual_result1 = std::lexicographical_compare(
6✔
199
        std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
6✔
200
    bool result1 = hpx::ranges::lexicographical_compare(policy, c1, c2);
6✔
201

202
    bool actual_result2 = std::lexicographical_compare(
6✔
203
        std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
6✔
204
    bool result2 = hpx::ranges::lexicographical_compare(policy, c1, c2);
6✔
205

206
    bool actual_result3 = std::lexicographical_compare(
6✔
207
        std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
6✔
208
    bool result3 = hpx::ranges::lexicographical_compare(policy, c1, c2);
6✔
209

210
    HPX_TEST_EQ(actual_result1, result1);
6✔
211
    HPX_TEST_EQ(actual_result2, result2);
6✔
212
    HPX_TEST_EQ(actual_result3, result3);
6✔
213
}
6✔
214

215
template <typename ExPolicy, typename IteratorTag>
216
void test_lexicographical_compare_async(ExPolicy policy, IteratorTag)
4✔
217
{
218
    static_assert(hpx::is_execution_policy<ExPolicy>::value,
219
        "hpx::is_execution_policy<ExPolicy>::value");
220

221
    std::vector<char> c1(10);
4✔
222
    std::generate(
4✔
223
        std::begin(c1), std::end(c1), []() { return 'a' + dis(gen); });
44✔
224

225
    std::vector<char> c2(10);
4✔
226
    std::generate(
4✔
227
        std::begin(c2), std::end(c2), []() { return 'a' + dis(gen); });
44✔
228

229
    bool actual_result1 = std::lexicographical_compare(
4✔
230
        std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
4✔
231
    hpx::future<bool> result1 =
232
        hpx::ranges::lexicographical_compare(policy, c1, c2);
4✔
233

234
    bool actual_result2 = std::lexicographical_compare(
4✔
235
        std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
4✔
236
    hpx::future<bool> result2 =
237
        hpx::ranges::lexicographical_compare(policy, c1, c2);
4✔
238

239
    bool actual_result3 = std::lexicographical_compare(
4✔
240
        std::begin(c1), std::end(c1), std::begin(c2), std::end(c2));
4✔
241
    hpx::future<bool> result3 =
242
        hpx::ranges::lexicographical_compare(policy, c1, c2);
4✔
243

244
    result1.wait();
4✔
245
    result2.wait();
4✔
246
    result3.wait();
4✔
247

248
    HPX_TEST_EQ(actual_result1, result1.get());
4✔
249
    HPX_TEST_EQ(actual_result2, result2.get());
4✔
250
    HPX_TEST_EQ(actual_result3, result3.get());
4✔
251
}
4✔
252

253
template <typename IteratorTag>
254
void test_lexicographical_compare()
2✔
255
{
256
    using namespace hpx::execution;
257

258
    test_lexicographical_compare(IteratorTag());
2✔
259
    test_lexicographical_compare(seq, IteratorTag());
2✔
260
    test_lexicographical_compare(par, IteratorTag());
2✔
261
    test_lexicographical_compare(par_unseq, IteratorTag());
2✔
262

263
    test_lexicographical_compare_async(seq(task), IteratorTag());
2✔
264
    test_lexicographical_compare_async(par(task), IteratorTag());
2✔
265

266
    test_lexicographical_compare_sent();
2✔
267
    test_lexicographical_compare_sent(seq);
2✔
268
    test_lexicographical_compare_sent(par);
2✔
269
    test_lexicographical_compare_sent(par_unseq);
2✔
270
}
2✔
271

272
void lexicographical_compare_test()
1✔
273
{
274
    test_lexicographical_compare<std::random_access_iterator_tag>();
1✔
275
    test_lexicographical_compare<std::forward_iterator_tag>();
1✔
276
}
1✔
277

278
////////////////////////////////////////////////////////////////////////////
279
int hpx_main(hpx::program_options::variables_map& vm)
1✔
280
{
281
    unsigned int seed1 = (unsigned int) std::time(nullptr);
1✔
282
    if (vm.count("seed"))
1✔
283
        seed1 = vm["seed"].as<unsigned int>();
×
284

285
    std::cout << "using seed: " << seed1 << std::endl;
1✔
286
    std::srand(seed1);
1✔
287

288
    seed = seed1;
1✔
289
    gen = std::mt19937(seed);
1✔
290

291
    lexicographical_compare_test();
1✔
292
    return hpx::local::finalize();
1✔
293
}
×
294

295
int main(int argc, char* argv[])
1✔
296
{
297
    // add command line option which controls the random number generator seed
298
    using namespace hpx::program_options;
299
    options_description desc_commandline(
1✔
300
        "Usage: " HPX_APPLICATION_STRING " [options]");
1✔
301

302
    desc_commandline.add_options()("seed,s", value<unsigned int>(),
1✔
303
        "the random number generator seed to use for this run");
304

305
    // By default this test should run on all available cores
306
    std::vector<std::string> const cfg = {"hpx.os_threads=all"};
1✔
307

308
    // Initialize and run HPX
309
    hpx::local::init_params init_args;
1✔
310
    init_args.desc_cmdline = desc_commandline;
1✔
311
    init_args.cfg = cfg;
1✔
312

313
    HPX_TEST_EQ_MSG(hpx::local::init(hpx_main, argc, argv, init_args), 0,
1✔
314
        "HPX main exited with non-zero status");
315

316
    return hpx::util::report_errors();
1✔
317
}
1✔
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