• 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_vote.cpp
1
//  Copyright (c) 2019 National Technology & Engineering Solutions of Sandia,
2
//                     LLC (NTESS).
3
//  Copyright (c) 2019 Nikunj Gupta
4
//
5
//  SPDX-License-Identifier: BSL-1.0
6
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
7
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8

9
#include <hpx/chrono.hpp>
10
#include <hpx/future.hpp>
11
#include <hpx/init.hpp>
12
#include <hpx/modules/resiliency.hpp>
13

14
#include <cstddef>
15
#include <iostream>
16
#include <random>
17
#include <unordered_map>
18
#include <vector>
19

20
std::random_device rd;
21
std::mt19937 mt(rd());
22
std::uniform_real_distribution<double> dist(1.0, 10.0);
23

24
int vote(std::vector<int> vect)
×
25
{
26
    return vect.at(0);
×
27
}
28

29
int universal_ans()
×
30
{
31
    if (dist(mt) > 5)
×
32
        return 42;
×
33
    return 84;
34
}
35

36
bool validate(int ans)
×
37
{
38
    return ans == 42;
×
39
}
40

41
int hpx_main(hpx::program_options::variables_map& vm)
×
42
{
43
    std::size_t n = vm["n-value"].as<std::size_t>();
×
44

45
    {
46
        // Initialize a high resolution timer
47
        hpx::chrono::high_resolution_timer t;
48

49
        hpx::future<int> f =
50
            hpx::resiliency::experimental::async_replicate_vote(
51
                n, &vote, &universal_ans);
×
52

53
        std::cout << "Universal ans (maybe true): " << f.get() << std::endl;
×
54

55
        double elapsed = t.elapsed();
×
56
        hpx::util::format_to(std::cout, "Time elapsed == {1}\n", elapsed);
×
57
    }
58

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

63
        hpx::future<int> f =
64
            hpx::resiliency::experimental::async_replicate_vote_validate(
65
                n, &vote, &validate, &universal_ans);
×
66

67
        std::cout << "Universal ans (true ans): " << f.get() << std::endl;
×
68

69
        double elapsed = t.elapsed();
×
70
        hpx::util::format_to(std::cout, "Time elapsed == {1}\n", elapsed);
×
71
    }
72

73
    return hpx::local::finalize();
×
74
}
75

76
int main(int argc, char* argv[])
×
77
{
78
    using hpx::program_options::options_description;
79
    using hpx::program_options::value;
80

81
    // Configure application specific options
82
    options_description desc_commandline(
83
        "Usage: " HPX_APPLICATION_STRING " [options]");
×
84

85
    desc_commandline.add_options()("n-value",
×
86
        value<std::size_t>()->default_value(10),
×
87
        "Number of asynchronous function launches (curated for successful "
88
        "replicate example)");
89

90
    // Initialize and run HPX
91
    hpx::local::init_params init_args;
×
92
    init_args.desc_cmdline = desc_commandline;
×
93

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