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

STEllAR-GROUP / hpx / #847

07 Dec 2022 07:15PM UTC coverage: 85.835% (-0.6%) from 86.482%
#847

push

StellarBot
Merge #6095

6095: Replacing facilities from Boost.Range r=hkaiser a=hkaiser

Working towards #3440 


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

43 of 43 new or added lines in 21 files covered. (100.0%)

171460 of 199755 relevant lines covered (85.84%)

1820288.13 hits per line

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

44.3
/libs/full/resiliency_distributed/tests/performance/replicate/async_replicate_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
//
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 <cstddef>
24
#include <iostream>
25
#include <random>
26
#include <vector>
27

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

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

39
            while ((hpx::chrono::high_resolution_clock::now() - start) <
9,069,777✔
40
                (size * 100))
9,069,777✔
41
            {
42
            }
43

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

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

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

54
    bool is_faulty = false;
150✔
55

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

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

71
    return 42;
72
}
150✔
73

74
HPX_PLAIN_ACTION(universal_ans, universal_action)
153✔
75

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

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

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

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

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

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

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

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

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

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

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

141
            tasks.push_back(hpx::resiliency::experimental::async_replicate(
×
142
                ids, ac, f_locales, err, size));
143

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

147
        hpx::wait_all(tasks);
×
148

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

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

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

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

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

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

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