• 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/dataflow_replicate.cpp
1
//  Copyright (c) 2019 National Technology & Engineering Solutions of Sandia,
2
//                     LLC (NTESS).
3
//  Copyright (c) 2018 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/init.hpp>
12
#include <hpx/modules/resiliency.hpp>
13

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

20
std::mt19937 gen(1);
21

22
struct bad_calc_exception : std::exception
×
23
{
24
};
25
struct inv_arg_exception : std::exception
×
26
{
27
};
28

29
int moody_calc(int a, int b)
×
30
{
31
    if (gen() % 2 == 0)
×
32
        return a + b;
×
33
    else
34
        return a;
35
}
36

37
int moody_add(int a, int b)
×
38
{
39
    if (a == 0 || b == 0)
×
40
        throw inv_arg_exception();
×
41
    int c = moody_calc(a, b);
42
    if (c == a)
×
43
        throw bad_calc_exception();
×
44
    else
45
        return c;
×
46
}
47

48
int bad_add(int, int)
×
49
{
50
    throw bad_calc_exception();
×
51
}
52

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

59
    {
60
        // Successful replicate
61
        hpx::future<int> f = hpx::resiliency::experimental::dataflow_replicate(
62
            sr, moody_add, 5, 5);
63
        try
64
        {
65
            std::cout << f.get() << std::endl;
×
66
        }
67
        catch (inv_arg_exception const&)
×
68
        {
69
            std::cout << "Invalid Argument!" << std::endl;
70
        }
×
71
        catch (bad_calc_exception const&)
×
72
        {
73
            std::cout << "Bad Calculation!" << std::endl;
74
        }
×
75

76
        // Unsuccessful replicate
77
        f = hpx::resiliency::experimental::dataflow_replay(
×
78
            usr, moody_add, 0, 5);
79
        try
80
        {
81
            std::cout << f.get() << std::endl;
×
82
        }
83
        catch (inv_arg_exception const&)
×
84
        {
85
            std::cout << "Invalid Argument!" << std::endl;
86
        }
×
87
        catch (bad_calc_exception const&)
×
88
        {
89
            std::cout << "Bad Calculation!" << std::endl;
90
        }
×
91

92
        // Aborted replicate
93
        f = hpx::resiliency::experimental::dataflow_replay(a, bad_add, 10, 5);
×
94
        try
95
        {
96
            std::cout << f.get() << std::endl;
×
97
        }
98
        catch (inv_arg_exception const&)
×
99
        {
100
            std::cout << "Invalid Argument!" << std::endl;
101
        }
×
102
        catch (bad_calc_exception const&)
×
103
        {
104
            std::cout << "Bad Calculation!" << std::endl;
105
        }
×
106
    }
107

108
    return hpx::local::finalize();
×
109
}
110

111
int main(int argc, char* argv[])
×
112
{
113
    using hpx::program_options::options_description;
114
    using hpx::program_options::value;
115

116
    // Configure application specific options
117
    options_description desc_commandline(
118
        "Usage: " HPX_APPLICATION_STRING " [options]");
×
119

120
    desc_commandline.add_options()("sr-value",
×
121
        value<std::size_t>()->default_value(10),
×
122
        "Number of repeat launches for successful dataflow replicate");
123

124
    desc_commandline.add_options()("usr-value",
×
125
        value<std::size_t>()->default_value(6),
×
126
        "Number of repeat launches for unsuccessful dataflow replicate");
127

128
    desc_commandline.add_options()("a-value",
×
129
        value<std::size_t>()->default_value(3),
×
130
        "Number of repeat launches for aborted dataflow replicate");
131

132
    // Initialize and run HPX
133
    hpx::local::init_params init_args;
×
134
    init_args.desc_cmdline = desc_commandline;
×
135

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