• 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/core/resiliency/examples/async_replicate.cpp
1
//  Copyright (c) 2019 National Technology & Engineering Solutions of Sandia,
2
//                     LLC (NTESS).
3
//  Copyright (c) 2018-2020 Hartmut Kaiser
4
//  Copyright (c) 2019 Adrian Serio
5
//  Copyright (c) 2019 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/chrono.hpp>
12
#include <hpx/init.hpp>
13
#include <hpx/modules/resiliency.hpp>
14

15
#include <atomic>
16
#include <cstddef>
17
#include <iostream>
18
#include <stdexcept>
19

20
std::atomic<int> answer(35);
21

22
struct vogon_exception : std::exception
×
23
{
24
};
25

26
int universal_answer()
×
27
{
28
    return ++answer;
×
29
}
30

31
bool validate(int result)
×
32
{
33
    return result == 42;
×
34
}
35

36
int no_answer()
×
37
{
38
    throw hpx::resiliency::experimental::abort_replicate_exception();
×
39
}
40

41
int deep_thought()
×
42
{
43
    static int ans = 35;
44
    ++ans;
×
45
    if (ans == 42)
×
46
        return ans;
×
47
    else
48
        throw vogon_exception();
×
49
}
50

51
int hpx_main(hpx::program_options::variables_map& vm)
×
52
{
53
    std::size_t sr = vm["sr-value"].as<std::size_t>();
×
54
    std::size_t usr = vm["usr-value"].as<std::size_t>();
×
55
    std::size_t a = vm["a-value"].as<std::size_t>();
×
56

57
    {
58
        // Initialize a high resolution timer
59
        hpx::chrono::high_resolution_timer t;
60

61
        // successful replicate
62
        hpx::future<int> f =
63
            hpx::resiliency::experimental::async_replicate(sr, &deep_thought);
×
64

65
        std::cout << "universal answer: " << f.get() << "\n";
×
66

67
        // successful replicate_validate
68
        f = hpx::resiliency::experimental::async_replicate_validate(
×
69
            sr, &validate, &universal_answer);
×
70

71
        std::cout << "universal answer: " << f.get() << "\n";
×
72

73
        // unsuccessful replicate
74
        f = hpx::resiliency::experimental::async_replicate(usr, &deep_thought);
×
75
        try
76
        {
77
            f.get();
×
78
        }
79
        catch (vogon_exception const&)
×
80
        {
81
            std::cout << "Deep Thought Destroyed!\n";
×
82
        }
×
83

84
        // unsuccessful replicate_validate
85
        f = hpx::resiliency::experimental::async_replicate_validate(
×
86
            usr, &validate, &universal_answer);
×
87
        try
88
        {
89
            f.get();
×
90
        }
91
        catch (hpx::resiliency::experimental::abort_replicate_exception const&)
×
92
        {
93
            std::cout << "no universal answer!\n";
×
94
        }
×
95

96
        // aborted replicate
97
        f = hpx::resiliency::experimental::async_replicate(a, &no_answer);
×
98
        try
99
        {
100
            f.get();
×
101
        }
102
        catch (hpx::resiliency::experimental::abort_replicate_exception const&)
×
103
        {
104
            std::cout << "aborted universal answer calculation!\n";
×
105
        }
×
106

107
        // aborted replicate validate
108
        f = hpx::resiliency::experimental::async_replicate_validate(
×
109
            a, &validate, &no_answer);
×
110
        try
111
        {
112
            f.get();
×
113
        }
114
        catch (hpx::resiliency::experimental::abort_replicate_exception const&)
×
115
        {
116
            std::cout << "aborted universal answer calculation!\n";
×
117
        }
×
118

119
        double elapsed = t.elapsed();
×
120
        hpx::util::format_to(std::cout, "Time elapsed == {1}\n", elapsed);
×
121
    }
122

123
    return hpx::local::finalize();
×
124
}
125

126
int main(int argc, char* argv[])
×
127
{
128
    using hpx::program_options::options_description;
129
    using hpx::program_options::value;
130

131
    // Configure application specific options
132
    options_description desc_commandline(
133
        "Usage: " HPX_APPLICATION_STRING " [options]");
×
134

135
    desc_commandline.add_options()("sr-value",
×
136
        value<std::size_t>()->default_value(10),
×
137
        "Number of asynchronous function launches (curated for successful "
138
        "replicate example)");
139

140
    desc_commandline.add_options()("usr-value",
×
141
        value<std::size_t>()->default_value(6),
×
142
        "Number of asynchronous function launches (curated for unsuccessful "
143
        "replicate example)");
144

145
    desc_commandline.add_options()("a-value",
×
146
        value<std::size_t>()->default_value(1),
×
147
        "Number of asynchronous function launches (curated for aborted "
148
        "replicate example)");
149

150
    // Initialize and run HPX
151
    hpx::local::init_params init_args;
×
152
    init_args.desc_cmdline = desc_commandline;
×
153

154
    return hpx::local::init(hpx_main, argc, argv, init_args);
×
155
}
×
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