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

STEllAR-GROUP / hpx / #875

25 Jan 2023 03:11PM UTC coverage: 86.39% (+0.5%) from 85.911%
#875

push

StellarBot
Merge #6151

6151: Refactoring the Manual page in documentation r=hkaiser a=dimitraka

- Move the instructions to build the tests and examples in a new separate page 
- Add references of the most important CMake options or the comprehensive list of CMake options
- Rename the CMake options page (title was too long)
- Refer to the new page of how to build the examples in the examples section itself


Co-authored-by: kadimitra <kadimitra@ece.auth.gr>

174481 of 201968 relevant lines covered (86.39%)

1898746.94 hits per line

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

43.75
/libs/full/resiliency_distributed/tests/performance/replicate/async_replicate_distributed_vote.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/resiliency_distributed.hpp>
20
#include <hpx/modules/testing.hpp>
21

22
#include <cstddef>
23
#include <iostream>
24
#include <random>
25
#include <vector>
26

27
int universal_ans(
150✔
28
    std::vector<hpx::id_type> f_locales, std::size_t err, std::size_t size)
29
{
30
    std::vector<hpx::future<int>> local_tasks;
150✔
31

32
    for (std::size_t i = 0; i < 100; ++i)
15,150✔
33
    {
34
        local_tasks.push_back(hpx::async([size]() {
30,000✔
35
            // Pretending to do some useful work
36
            std::size_t start = hpx::chrono::high_resolution_clock::now();
15,000✔
37

38
            while ((hpx::chrono::high_resolution_clock::now() - start) <
8,796,679✔
39
                (size * 100))
8,796,679✔
40
            {
41
            }
42

43
            return 42;
15,000✔
44
        }));
45
    }
15,000✔
46

47
    hpx::wait_all(local_tasks);
150✔
48

49
    std::random_device rd;
150✔
50
    std::mt19937 gen(rd());
150✔
51
    std::uniform_int_distribution<std::size_t> dist(1, 100);
150✔
52

53
    bool is_faulty = false;
150✔
54

55
    // Check if the node is faulty
56
    for (const auto& locale : f_locales)
282✔
57
    {
58
        // Throw a runtime error in case the node is faulty
59
        if (locale == hpx::find_here())
150✔
60
        {
61
            is_faulty = true;
150✔
62
            if (dist(gen) < err * 10)
150✔
63
                throw std::runtime_error("runtime error occurred.");
18✔
64
        }
132✔
65
    }
66

67
    if (!is_faulty && dist(gen) < err)
132✔
68
        throw std::runtime_error("runtime error occurred.");
×
69

70
    return 42;
71
}
150✔
72

73
HPX_PLAIN_ACTION(universal_ans, universal_action)
153✔
74

75
bool validate(int ans)
×
76
{
77
    return ans == 42;
×
78
}
79

80
int vote(std::vector<int>&& results)
×
81
{
82
    return results.at(0);
×
83
}
84

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

93
    universal_action ac;
94
    std::vector<hpx::id_type> locales = hpx::find_all_localities();
×
95

96
    // Make sure that the number of faulty nodes are less than the number of
97
    // localities we work on.
98
    HPX_ASSERT(f_nodes < locales.size());
×
99

100
    // List of faulty nodes
101
    std::vector<hpx::id_type> f_locales;
×
102
    std::vector<std::size_t> visited;
×
103

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

113
        f_locales.push_back(locales.at(num));
×
114
    }
×
115

116
    {
117
        hpx::chrono::high_resolution_timer t;
×
118

119
        std::vector<hpx::future<int>> tasks;
×
120
        for (std::size_t i = 0; i < num_tasks; ++i)
×
121
        {
122
            std::vector<hpx::id_type> ids;
×
123
            ids.reserve(num_replications);
×
124
            if (num_replications < locales.size())
×
125
            {
126
                for (auto& locale : locales)
×
127
                    ids.push_back(locale);
×
128
            }
×
129
            else
130
            {
131
                for (auto& locale : locales)
×
132
                    ids.push_back(locale);
×
133

134
                for (std::size_t i = 0; i < num_replications - ids.size(); ++i)
×
135
                {
136
                    ids.emplace_back(locales.at(i));
×
137
                }
×
138
            }
139

140
            tasks.push_back(hpx::resiliency::experimental::async_replicate_vote(
×
141
                ids, &vote, ac, f_locales, err, size));
×
142

143
            std::rotate(locales.begin(), locales.begin() + 1, locales.end());
×
144
        }
×
145

146
        hpx::wait_all(tasks);
×
147

148
        double elapsed = t.elapsed();
×
149
        std::cout << "Replicate Vote: " << elapsed << std::endl;
×
150
    }
×
151

152
    return hpx::finalize();
×
153
}
×
154

155
int main(int argc, char* argv[])
1✔
156
{
157
    namespace po = hpx::program_options;
158

159
    // Configure application-specific options
160
    po::options_description desc_commandline;
1✔
161

162
    // clang-format off
163
    desc_commandline.add_options()
6✔
164
        ("f-nodes", po::value<std::size_t>()->default_value(1),
1✔
165
            "Number of faulty nodes to be injected")
166
        ("error", po::value<std::size_t>()->default_value(1),
1✔
167
            "Error rates for all nodes. Faulty nodes will have 10x error rates.")
168
        ("size", po::value<std::size_t>()->default_value(200),
1✔
169
            "Grain size of a task")
170
        ("num-tasks", po::value<std::size_t>()->default_value(100),
1✔
171
            "Number of tasks to invoke")
172
        ("num-replications", po::value<std::size_t>()->default_value(3),
1✔
173
            "Total number of replicates for a task (including the task itself)")
174
    ;
175
    // clang-format on
176

177
    // Initialize and run HPX
178
    hpx::init_params params;
1✔
179
    params.desc_cmdline = desc_commandline;
1✔
180
    return hpx::init(argc, argv, params);
1✔
181
}
1✔
182

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