• 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_replay.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 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/format.hpp>
13
#include <hpx/future.hpp>
14
#include <hpx/init.hpp>
15
#include <hpx/modules/resiliency.hpp>
16

17
#include <atomic>
18
#include <cstddef>
19
#include <iostream>
20
#include <stdexcept>
21

22
std::atomic<int> answer(35);
23
struct vogon_exception : std::exception
×
24
{
25
};
26

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

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

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

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

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

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

62
        // successful replay
63
        hpx::future<int> f =
64
            hpx::resiliency::experimental::async_replay(sr, &deep_thought);
×
65

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

68
        // successful replay validate
69
        f = hpx::resiliency::experimental::async_replay_validate(
×
70
            sr, &validate, &universal_answer);
×
71

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

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

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

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

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

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

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

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

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

136
    desc_commandline.add_options()("sr-value",
×
137
        value<std::size_t>()->default_value(10),
×
138
        "Maximum number of repeat launches (curated for successful replay "
139
        "example)");
140

141
    desc_commandline.add_options()("usr-value",
×
142
        value<std::size_t>()->default_value(6),
×
143
        "Maximum number of repeat launches (curated for unsuccessful replay "
144
        "example)");
145

146
    desc_commandline.add_options()("a-value",
×
147
        value<std::size_t>()->default_value(1),
×
148
        "Maximum number of repeat launches (curated for aborted replay "
149
        "example)");
150

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

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