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

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

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

0.0
/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)
×
30
{
31
    // Pretending to do some useful work
32
    std::size_t start = hpx::chrono::high_resolution_clock::now();
33

34
    while ((hpx::chrono::high_resolution_clock::now() - start) < (size * 100))
×
35
    {
36
    }
37

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

46
    return 42;
×
47
}
48

49
HPX_PLAIN_ACTION(universal_ans, universal_action)
×
50

51
bool validate(int ans)
×
52
{
53
    return ans == 42;
×
54
}
55

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

62
    universal_action ac;
63
    std::vector<hpx::id_type> locales = hpx::find_all_localities();
×
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());
68

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

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

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

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

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

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

97
        hpx::wait_all(tasks);
98

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

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

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

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

116
        hpx::wait_all(tasks);
117

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

122
    return hpx::finalize();
×
123
}
×
124

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

130
    namespace po = hpx::program_options;
131

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

143
    // Initialize and run HPX
144
    hpx::init_params params;
×
145
    params.desc_cmdline = desc_commandline;
×
146
    return hpx::init(argc, argv, params);
×
147
}
×
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

© 2026 Coveralls, Inc