• 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

94.92
/libs/full/resiliency_distributed/examples/async_replay_distributed.cpp
1
//  Copyright (c) 2019 National Technology & Engineering Solutions of Sandia,
2
//  Copyright (c) 2019 National Technology & Engineering Solutions of Sandia,
3
//                     LLC (NTESS).
4
//  Copyright (c) 2018-2019 Hartmut Kaiser
5
//  Copyright (c) 2018-2019 Adrian Serio
6
//  Copyright (c) 2019-2020 Nikunj Gupta
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_distributed.hpp>
20
#include <hpx/modules/testing.hpp>
21

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

29
int universal_ans(std::vector<hpx::id_type> f_locales, std::size_t size)
2,000✔
30
{
31
    // Pretending to do some useful work
32
    std::size_t start = hpx::chrono::high_resolution_clock::now();
2,000✔
33

34
    while ((hpx::chrono::high_resolution_clock::now() - start) < (size * 100))
1,200,916✔
35
    {
36
    }
37

38
    // Check if the node is faulty
39
    for (const auto& locale : f_locales)
4,000✔
40
    {
41
        // Throw a runtime error in case the node is faulty
42
        if (locale == hpx::find_here())
2,000✔
43
            throw std::runtime_error("runtime error occurred.");
×
44
    }
45

46
    return 42;
2,000✔
47
}
×
48

49
HPX_PLAIN_ACTION(universal_ans, universal_action)
5,004✔
50

51
bool validate(int ans)
1,000✔
52
{
53
    return ans == 42;
1,000✔
54
}
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 = 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

65
    // Make sure that the number of faulty nodes are less than the number of
66
    // localities we work on.
67
    HPX_ASSERT(f_nodes < locales.size());
1✔
68

69
    // List of faulty nodes
70
    std::vector<hpx::id_type> f_locales;
1✔
71
    std::vector<std::size_t> visited;
1✔
72

73
    // Mark nodes as faulty
74
    for (std::size_t i = 0; i < f_nodes; ++i)
2✔
75
    {
76
        std::size_t num = std::rand() % locales.size();
1✔
77
        while (visited.end() != std::find(visited.begin(), visited.end(), num))
1✔
78
        {
79
            num = std::rand() % locales.size();
×
80
        }
81

82
        f_locales.push_back(locales.at(num));
1✔
83
    }
1✔
84

85
    {
86
        hpx::chrono::high_resolution_timer t;
1✔
87

88
        std::vector<hpx::future<int>> tasks;
1✔
89
        for (std::size_t i = 0; i < num_tasks; ++i)
1,001✔
90
        {
91
            tasks.push_back(hpx::resiliency::experimental::async_replay(
1,000✔
92
                locales, ac, f_locales, size));
93

94
            std::rotate(locales.begin(), locales.begin() + 1, locales.end());
1,000✔
95
        }
1,000✔
96

97
        hpx::wait_all(tasks);
1✔
98

99
        double elapsed = t.elapsed();
1✔
100
        std::cout << "Replay: " << elapsed << std::endl;
1✔
101
    }
1✔
102

103
    {
104
        hpx::chrono::high_resolution_timer t;
1✔
105

106
        std::vector<hpx::future<int>> tasks;
1✔
107
        for (std::size_t i = 0; i < num_tasks; ++i)
1,001✔
108
        {
109
            tasks.push_back(
1,000✔
110
                hpx::resiliency::experimental::async_replay_validate(
1,000✔
111
                    locales, &validate, ac, f_locales, size));
1,000✔
112

113
            std::rotate(locales.begin(), locales.begin() + 1, locales.end());
1,000✔
114
        }
1,000✔
115

116
        hpx::wait_all(tasks);
1✔
117

118
        double elapsed = t.elapsed();
1✔
119
        std::cout << "Replay Validate: " << elapsed << std::endl;
1✔
120
    }
1✔
121

122
    return hpx::finalize();
1✔
123
}
1✔
124

125
int main(int argc, char* argv[])
1✔
126
{
127
    // Configure application-specific options
128
    hpx::program_options::options_description desc_commandline;
1✔
129

130
    namespace po = hpx::program_options;
131

132
    // clang-format off
133
    desc_commandline.add_options()
4✔
134
        ("f-nodes", po::value<std::size_t>()->default_value(1),
1✔
135
            "Number of faulty nodes to be injected")
136
        ("size", po::value<std::size_t>()->default_value(200),
1✔
137
            "Grain size of a task")
138
        ("num-tasks", po::value<std::size_t>()->default_value(1000),
1✔
139
            "Number of tasks to invoke")
140
    ;
141
    // clang-format on
142

143
    // Initialize and run HPX
144
    hpx::init_params params;
1✔
145
    params.desc_cmdline = desc_commandline;
1✔
146
    return hpx::init(argc, argv, params);
1✔
147
}
1✔
148

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