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

STEllAR-GROUP / hpx / #857

28 Dec 2022 11:12PM UTC coverage: 86.543% (-0.06%) from 86.602%
#857

push

StellarBot
Merge #6118

6118: Modernize modules from level 17, 18, 19, and 20 r=hkaiser a=hkaiser

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

Modules:
- core/threading_base
- full/command_line_handling
- core/io_service
- core/schedulers
- core/synchronization
- core/futures
- core/thread_pools
- core/lcos_local
- core/pack_traversal
- core/resource_partitioner
- core/threading
- full/naming_base


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

849 of 849 new or added lines in 98 files covered. (100.0%)

174389 of 201505 relevant lines covered (86.54%)

1916353.25 hits per line

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

27.55
/tests/performance/local/future_overhead_report.cpp
1
//  Copyright (c) 2018-2020 Mikael Simberg
2
//  Copyright (c) 2018-2019 John Biddiscombe
3
//  Copyright (c) 2011 Bryce Adelstein-Lelbach
4
//
5
//  SPDX-License-Identifier: BSL-1.0
6
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
7
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8

9
#include <hpx/config.hpp>
10
#include <hpx/local/chrono.hpp>
11
#include <hpx/local/future.hpp>
12
#include <hpx/local/init.hpp>
13
#include <hpx/local/thread.hpp>
14
#include <hpx/modules/testing.hpp>
15

16
#include <array>
17
#include <cstddef>
18
#include <cstdint>
19
#include <string>
20
#include <type_traits>
21

22
using hpx::program_options::options_description;
23
using hpx::program_options::value;
24
using hpx::program_options::variables_map;
25

26
using hpx::async;
27
using hpx::future;
28
using hpx::post;
29

30
using hpx::chrono::high_resolution_timer;
31

32
// global vars we stick here to make printouts easy for plotting
33
static std::string queuing = "default";
1✔
34
static std::size_t numa_sensitive = 0;
35
static std::uint64_t num_threads = 1;
36
static std::string info_string = "";
1✔
37

38
///////////////////////////////////////////////////////////////////////////////
39
// we use globals here to prevent the delay from being optimized away
40
double global_scratch = 0;
41
std::uint64_t num_iterations = 0;
42

43
///////////////////////////////////////////////////////////////////////////////
44
double null_function() noexcept
×
45
{
46
    if (num_iterations > 0)
×
47
    {
48
        const int array_size = 4096;
×
49
        std::array<double, array_size> dummy;
50
        for (std::uint64_t i = 0; i < num_iterations; ++i)
×
51
        {
52
            for (std::uint64_t j = 0; j < array_size; ++j)
×
53
            {
54
                dummy[j] = 1.0 / (2.0 * i * j + 1.0);
×
55
            }
×
56
        }
×
57
        return dummy[0];
×
58
    }
59
    return 0.0;
×
60
}
×
61

62
struct scratcher
63
{
64
    void operator()(future<double> r) const
65
    {
66
        global_scratch += r.get();
67
    }
68
};
69

70
void measure_function_futures_create_thread_hierarchical_placement(
×
71
    std::uint64_t count, const int repetitions)
72
{
73
    auto sched = hpx::threads::get_self_id_data()->get_scheduler_base();
×
74

75
    if (std::string("core-shared_priority_queue_scheduler") ==
×
76
        sched->get_description())
×
77
    {
78
        sched->add_remove_scheduler_mode(
×
79
            hpx::threads::policies::scheduler_mode::assign_work_thread_parent,
80
            hpx::threads::policies::scheduler_mode::enable_stealing |
×
81
                hpx::threads::policies::scheduler_mode::enable_stealing_numa |
×
82
                hpx::threads::policies::scheduler_mode::
83
                    assign_work_round_robin |
×
84
                hpx::threads::policies::scheduler_mode::steal_after_local |
×
85
                hpx::threads::policies::scheduler_mode::
86
                    steal_high_priority_first);
87
    }
×
88
    auto const desc = hpx::threads::thread_description();
×
89
    auto prio = hpx::threads::thread_priority::normal;
×
90
    auto const stack_size = hpx::threads::thread_stacksize::small_;
×
91
    auto const num_threads = hpx::get_num_worker_threads();
×
92
    hpx::error_code ec;
×
93

94
    hpx::util::perftests_report(
×
95
        "future overhead - create_thread_hierarchical - latch", "no-executor",
×
96
        repetitions, [&]() -> void {
×
97
            hpx::latch l(count);
×
98

99
            auto const func = [&l]() {
×
100
                null_function();
×
101
                l.count_down(1);
×
102
            };
×
103
            auto const thread_func =
104
                hpx::threads::detail::thread_function_nullary<decltype(func)>{
×
105
                    func};
×
106
            for (std::size_t t = 0; t < num_threads; ++t)
×
107
            {
108
                auto const hint = hpx::threads::thread_schedule_hint(
×
109
                    static_cast<std::int16_t>(t));
×
110
                auto spawn_func = [&thread_func, sched, hint, t, count,
×
111
                                      num_threads, desc, prio]() {
×
112
                    std::uint64_t const count_start = t * count / num_threads;
×
113
                    std::uint64_t const count_end =
×
114
                        (t + 1) * count / num_threads;
×
115
                    hpx::error_code ec;
×
116
                    for (std::uint64_t i = count_start; i < count_end; ++i)
×
117
                    {
118
                        hpx::threads::thread_init_data init(
×
119
                            hpx::threads::thread_function_type(thread_func),
×
120
                            desc, prio, hint, stack_size,
×
121
                            hpx::threads::thread_schedule_state::pending, false,
122
                            sched);
×
123
                        sched->create_thread(init, nullptr, ec);
×
124
                    }
×
125
                };
×
126

127
                // different versions of clang-format disagree
128
                // clang-format off
129
                auto const thread_spawn_func =
130
                    hpx::threads::detail::thread_function_nullary<
131
                        decltype(spawn_func)>{spawn_func};
×
132
                // clang-format on
133

134
                hpx::threads::thread_init_data init(
×
135
                    hpx::threads::thread_function_type(thread_spawn_func), desc,
×
136
                    prio, hint, stack_size,
×
137
                    hpx::threads::thread_schedule_state::pending, false, sched);
×
138
                sched->create_thread(init, nullptr, ec);
×
139
            }
×
140
            l.wait();
×
141
        });
×
142
    hpx::util::perftests_print_times();
×
143
}
×
144

145
///////////////////////////////////////////////////////////////////////////////
146
int hpx_main(variables_map& vm)
1✔
147
{
148
    {
149
        if (vm.count("hpx:queuing"))
1✔
150
            queuing = vm["hpx:queuing"].as<std::string>();
×
151

152
        if (vm.count("hpx:numa-sensitive"))
1✔
153
            numa_sensitive = 1;
×
154
        else
155
            numa_sensitive = 0;
1✔
156

157
        bool test_all = (vm.count("test-all") > 0);
1✔
158
        const int repetitions = vm["repetitions"].as<int>();
1✔
159

160
        if (vm.count("info"))
1✔
161
            info_string = vm["info"].as<std::string>();
1✔
162

163
        num_threads = hpx::get_num_worker_threads();
1✔
164

165
        num_iterations = vm["delay-iterations"].as<std::uint64_t>();
1✔
166

167
        const std::uint64_t count = vm["futures"].as<std::uint64_t>();
1✔
168
        if (HPX_UNLIKELY(0 == count))
1✔
169
            throw std::logic_error("error: count of 0 futures specified\n");
×
170

171
        if (test_all)
1✔
172
        {
173
            measure_function_futures_create_thread_hierarchical_placement(
×
174
                count, repetitions);
×
175
        }
×
176
    }
177

178
    return hpx::local::finalize();
1✔
179
}
×
180

181
///////////////////////////////////////////////////////////////////////////////
182
int main(int argc, char* argv[])
1✔
183
{
184
    // Configure application-specific options.
185
    options_description cmdline("usage: " HPX_APPLICATION_STRING " [options]");
1✔
186

187
    // clang-format off
188
    cmdline.add_options()("futures",
5✔
189
        value<std::uint64_t>()->default_value(500000),
1✔
190
        "number of futures to invoke")
191

192
        ("delay-iterations", value<std::uint64_t>()->default_value(0),
1✔
193
         "number of iterations in the delay loop")
194

195
        ("test-all", "run all benchmarks")
196
        ("repetitions", value<int>()->default_value(1),
1✔
197
         "number of repetitions of the full benchmark")
198

199
        ("info", value<std::string>()->default_value("no-info"),
1✔
200
         "extra info for plot output (e.g. branch name)");
201
    // clang-format on
202

203
    // Initialize and run HPX.
204
    hpx::local::init_params init_args;
1✔
205
    init_args.desc_cmdline = cmdline;
1✔
206

207
    return hpx::local::init(hpx_main, argc, argv, init_args);
1✔
208
}
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

© 2026 Coveralls, Inc