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

STEllAR-GROUP / hpx / #846

05 Dec 2022 11:16PM UTC coverage: 86.482% (+0.8%) from 85.664%
#846

push

StellarBot
Merge #6093

6093: Replace boost::string_ref with std::string_view r=hkaiser a=hkaiser

Working towards #5497 and #3440

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

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

172759 of 199764 relevant lines covered (86.48%)

1842530.83 hits per line

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

94.74
/libs/full/resiliency_distributed/tests/performance/replay/plain_async_distributed.cpp
1
//  Copyright (c) 2019 National Technology & Engineering Solutions of Sandia,
2
//                     LLC (NTESS).
3
//  Copyright (c) 2018-2019 Hartmut Kaiser
4
//  Copyright (c) 2018-2019 Adrian Serio
5
//  Copyright (c) 2019-2020 Nikunj Gupta
6
//  SPDX-License-Identifier: BSL-1.0
7
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
8
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9

10
#include <hpx/config.hpp>
11
#if !defined(HPX_COMPUTE_DEVICE_CODE)
12

13
#include <hpx/actions_base/plain_action.hpp>
14
#include <hpx/assert.hpp>
15
#include <hpx/hpx_init.hpp>
16
#include <hpx/include/runtime.hpp>
17
#include <hpx/modules/futures.hpp>
18
#include <hpx/modules/resiliency.hpp>
19
#include <hpx/modules/testing.hpp>
20

21
#include <algorithm>
22
#include <cassert>
23
#include <cstddef>
24
#include <iostream>
25
#include <random>
26
#include <string>
27
#include <utility>
28
#include <vector>
29

30
int universal_ans(std::vector<hpx::id_type> const&, std::size_t size)
50✔
31
{
32
    std::vector<hpx::future<int>> local_tasks;
50✔
33

34
    for (std::size_t i = 0; i < 10; ++i)
550✔
35
    {
36
        local_tasks.push_back(hpx::async([size]() {
1,000✔
37
            // Pretending to do some useful work
38
            std::size_t start = hpx::chrono::high_resolution_clock::now();
500✔
39

40
            while ((hpx::chrono::high_resolution_clock::now() - start) <
291,599✔
41
                (size * 100))
291,599✔
42
            {
43
            }
44

45
            return 42;
500✔
46
        }));
47
    }
500✔
48

49
    hpx::wait_all(local_tasks);
50✔
50

51
    return 42;
52
}
50✔
53

54
HPX_PLAIN_ACTION(universal_ans, universal_action)
104✔
55

56
int hpx_main(hpx::program_options::variables_map& vm)
1✔
57
{
58
    std::size_t f_nodes = vm["f-nodes"].as<std::size_t>();
1✔
59
    std::size_t size = vm["size"].as<std::size_t>();
1✔
60
    std::size_t num_tasks_total = vm["num-tasks"].as<std::size_t>();
1✔
61

62
    universal_action ac;
63
    std::vector<hpx::id_type> locales = hpx::find_all_localities();
1✔
64
    std::size_t num_localities = hpx::get_num_localities(hpx::launch::sync);
1✔
65
    std::size_t num_tasks = num_tasks_total / num_localities;
1✔
66

67
    std::size_t rank = hpx::get_locality_id();
1✔
68
    if (rank == 0)
1✔
69
        num_tasks += (num_tasks_total % num_localities);
×
70

71
    // Make sure that the number of faulty nodes are less than the number of
72
    // localities we work on.
73
    HPX_ASSERT(f_nodes < locales.size());
1✔
74

75
    // List of faulty nodes
76
    std::vector<hpx::id_type> f_locales;
1✔
77
    std::vector<std::size_t> visited;
1✔
78

79
    // Mark nodes as faulty
80
    for (std::size_t i = 0; i < f_nodes; ++i)
2✔
81
    {
82
        std::size_t num = std::rand() % locales.size();
1✔
83
        while (visited.end() != std::find(visited.begin(), visited.end(), num))
1✔
84
        {
85
            num = std::rand() % locales.size();
×
86
        }
87

88
        f_locales.push_back(locales.at(num));
1✔
89
    }
1✔
90

91
    {
92
        hpx::chrono::high_resolution_timer t;
1✔
93

94
        std::vector<hpx::future<int>> tasks;
1✔
95
        for (std::size_t i = 0; i < num_tasks; ++i)
51✔
96
        {
97
            tasks.push_back(hpx::async(ac, locales.at(0), f_locales, size));
50✔
98

99
            std::rotate(locales.begin(), locales.begin() + 1, locales.end());
50✔
100
        }
50✔
101

102
        hpx::wait_all(tasks);
1✔
103

104
        double elapsed = t.elapsed();
1✔
105

106
        if (rank == 0)
1✔
107
            std::cout << "Plain async: " << elapsed << std::endl;
×
108
    }
1✔
109

110
    return hpx::finalize();
1✔
111
}
1✔
112

113
int main(int argc, char* argv[])
1✔
114
{
115
    namespace po = hpx::program_options;
116

117
    // Configure application-specific options
118
    po::options_description desc_commandline;
1✔
119

120
    // clang-format off
121
    desc_commandline.add_options()
4✔
122
        ("f-nodes", po::value<std::size_t>()->default_value(1),
1✔
123
            "Number of faulty nodes to be injected")
124
        ("size", po::value<std::size_t>()->default_value(200),
1✔
125
            "Grain size of a task")
126
        ("num-tasks", po::value<std::size_t>()->default_value(100),
1✔
127
            "Number of tasks to invoke")
128
    ;
129
    // clang-format on
130

131
    // Initialize and run HPX, this example requires to run hpx_main on all
132
    // localities
133
    std::vector<std::string> cfg = {
1✔
134
        "hpx.run_hpx_main!=1",
1✔
135
    };
136

137
    // Initialize and run HPX
138
    hpx::init_params params;
1✔
139
    params.desc_cmdline = desc_commandline;
1✔
140
    params.cfg = std::move(cfg);
1✔
141
    return hpx::init(argc, argv, params);
1✔
142
}
1✔
143

144
#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