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

STEllAR-GROUP / hpx / #861

09 Jan 2023 03:50PM UTC coverage: 86.634% (+0.7%) from 85.965%
#861

push

StellarBot
Merge #6127

6127: Working around gccV9 problem that prevent us from storing enum classes in bit fields r=hkaiser a=hkaiser



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

40 of 40 new or added lines in 8 files covered. (100.0%)

174879 of 201859 relevant lines covered (86.63%)

1846822.82 hits per line

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

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

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

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

23
#include <algorithm>
24
#include <cassert>
25
#include <cstddef>
26
#include <ctime>
27
#include <iostream>
28
#include <random>
29
#include <vector>
30

31
int universal_ans(std::vector<hpx::id_type> const& f_locales, std::size_t err,
79✔
32
    std::size_t size)
33
{
34
    std::vector<hpx::future<int>> local_tasks;
79✔
35

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

42
            while ((hpx::chrono::high_resolution_clock::now() - start) <
466,098✔
43
                (size * 100))
466,098✔
44
            {
45
            }
46

47
            return 42;
790✔
48
        }));
49
    }
790✔
50

51
    hpx::wait_all(local_tasks);
79✔
52

53
    std::random_device rd;
79✔
54
    std::mt19937 gen(rd());
79✔
55
    std::uniform_int_distribution<std::size_t> dist(1, 100);
79✔
56

57
    bool is_faulty = false;
79✔
58

59
    // Check if the node is faulty
60
    for (const auto& locale : f_locales)
158✔
61
    {
62
        // Throw a runtime error in case the node is faulty
63
        if (locale == hpx::find_here())
79✔
64
        {
65
            is_faulty = true;
×
66
            if (dist(gen) < err * 10)
×
67
                throw std::runtime_error("runtime error occurred.");
×
68
        }
×
69
    }
70

71
    if (!is_faulty && dist(gen) < err)
79✔
72
        throw std::runtime_error("runtime error occurred.");
3✔
73

74
    return 42;
75
}
79✔
76

77
HPX_PLAIN_ACTION(universal_ans, universal_action)
218✔
78

79
bool validate(int ans)
99✔
80
{
81
    return ans == 42;
99✔
82
}
83

84
int hpx_main(hpx::program_options::variables_map& vm)
1✔
85
{
86
    std::size_t f_nodes = vm["f-nodes"].as<std::size_t>();
1✔
87
    std::size_t err = vm["error"].as<std::size_t>();
1✔
88
    std::size_t size = vm["size"].as<std::size_t>();
1✔
89
    std::size_t num_tasks = vm["num-tasks"].as<std::size_t>();
1✔
90

91
    universal_action ac;
92
    std::vector<hpx::id_type> locales = hpx::find_all_localities();
1✔
93

94
    // Make sure that the number of faulty nodes are less than the number of
95
    // localities we work on.
96
    HPX_ASSERT(f_nodes < locales.size());
1✔
97

98
    // List of faulty nodes
99
    std::vector<hpx::id_type> f_locales;
1✔
100
    std::vector<std::size_t> visited;
1✔
101

102
    // Mark nodes as faulty
103
    for (std::size_t i = 0; i < f_nodes; ++i)
2✔
104
    {
105
        std::size_t num = std::rand() % locales.size();
1✔
106
        while (visited.end() != std::find(visited.begin(), visited.end(), num))
1✔
107
        {
108
            num = std::rand() % locales.size();
×
109
        }
110

111
        f_locales.push_back(locales.at(num));
1✔
112
    }
1✔
113

114
    {
115
        hpx::chrono::high_resolution_timer t;
1✔
116

117
        std::vector<hpx::future<int>> tasks;
1✔
118
        for (std::size_t i = 0; i < num_tasks; ++i)
101✔
119
        {
120
            tasks.push_back(
100✔
121
                hpx::resiliency::experimental::async_replay_validate(
100✔
122
                    locales, &validate, ac, f_locales, err, size));
100✔
123

124
            std::rotate(locales.begin(), locales.begin() + 1, locales.end());
100✔
125
        }
100✔
126

127
        HPX_TEST(!hpx::wait_all_nothrow(tasks));
1✔
128

129
        double elapsed = t.elapsed();
1✔
130
        std::cout << "Replay Validate: " << elapsed << std::endl;
1✔
131
    }
1✔
132

133
    return hpx::finalize();
1✔
134
}
1✔
135

136
int main(int argc, char* argv[])
1✔
137
{
138
    namespace po = hpx::program_options;
139

140
    // Configure application-specific options
141
    po::options_description desc_commandline;
1✔
142

143
    // clang-format off
144
    desc_commandline.add_options()
5✔
145
        ("f-nodes", po::value<std::size_t>()->default_value(1),
1✔
146
            "Number of faulty nodes to be injected")
147
        ("error", po::value<std::size_t>()->default_value(5),
1✔
148
            "Error rates for all nodes. Faulty nodes will have 10x error rates.")
149
        ("size", po::value<std::size_t>()->default_value(200),
1✔
150
            "Grain size of a task")
151
        ("num-tasks", po::value<std::size_t>()->default_value(100),
1✔
152
            "Number of tasks to invoke")
153
        ;
154
    // clang-format on
155

156
    // Initialize and run HPX
157
    hpx::init_params params;
1✔
158
    params.desc_cmdline = desc_commandline;
1✔
159
    return hpx::init(argc, argv, params);
1✔
160
}
1✔
161

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