• 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
/examples/throttle/throttle_client.cpp
1
//  Copyright (c) 2007-2012 Hartmut Kaiser
2
//  Copyright (c) 2011      Bryce Lelbach
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/config.hpp>
9
#if !defined(HPX_COMPUTE_DEVICE_CODE)
10
#include <hpx/components_base/agas_interface.hpp>
11
#include <hpx/hpx_init.hpp>
12
#include <hpx/include/components.hpp>
13
#include <hpx/include/runtime.hpp>
14
#include <hpx/include/util.hpp>
15

16
#include "throttle/throttle.hpp"
17

18
#include <iostream>
19
#include <sstream>
20
#include <string>
21
#include <vector>
22

23
using hpx::program_options::variables_map;
24

25
using hpx::string_util::is_space;
26
using hpx::string_util::split;
27

28
using hpx::naming::get_agas_client;
29

30
///////////////////////////////////////////////////////////////////////////////
31
int hpx_main(variables_map& vm)
×
32
{
33
    try
34
    {
35
        hpx::util::format_to(std::cout, "prefix: {}",
×
36
            hpx::naming::get_locality_id_from_id(hpx::find_here()))
×
37
            << std::endl;
38

39
        // Try to connect to existing throttle instance, create a new one if
40
        // this fails.
41
        char const* throttle_component_name = "/throttle/0";
42
        hpx::id_type gid =
43
            hpx::agas::resolve_name(hpx::launch::sync, throttle_component_name);
×
44
        throttle::throttle t;
×
45
        if (!t.get_id())
46
        {
47
            std::vector<hpx::id_type> localities =
48
                hpx::find_remote_localities();
×
49

50
            // create throttle on the console, register the instance with AGAS
51
            // and add an additional reference count to keep it alive
52
            if (!localities.empty())
×
53
            {
54
                // use AGAS client to get the component type as we do not
55
                // register any factories
56
                t = hpx::new_<throttle::throttle>(localities[0]);
×
57
                hpx::agas::register_name(
×
58
                    hpx::launch::sync, throttle_component_name, t.get_id());
59
            }
60
            else
61
            {
62
                std::cerr << "Can't find throttle component." << std::endl;
63
            }
64
        }
×
65

66
        // handle commands
67
        if (t.get_id())
68
        {
69
            if (vm.count("suspend"))
×
70
            {
71
                t.suspend(vm["suspend"].as<int>());
×
72
            }
73
            else if (vm.count("resume"))
×
74
            {
75
                t.resume(vm["resume"].as<int>());
×
76
            }
77
            else if (vm.count("release"))
×
78
            {
79
                // unregister from AGAS, remove additional reference count which
80
                // will allow for the throttle instance to be released
81
                hpx::agas::unregister_name(
×
82
                    hpx::launch::sync, throttle_component_name);
83
            }
84
        }
85
    }
86
    catch (hpx::exception const& e)
×
87
    {
88
        std::cerr << "throttle_client: caught exception: " << e.what()
×
89
                  << std::endl;
90
    }
×
91

92
    hpx::disconnect();
93
    return 0;
×
94
}
95

96
///////////////////////////////////////////////////////////////////////////////
97
int main(int argc, char* argv[])
×
98
{
99
    namespace po = hpx::program_options;
100

101
    // Configure application-specific options
102
    po::options_description cmdline(
103
        "Usage: " HPX_APPLICATION_STRING " [options]");
×
104
    cmdline.add_options()(
×
105
        "suspend", po::value<int>(), "suspend thread with given number")(
×
106
        "resume", po::value<int>(), "resume thread with given number")(
×
107
        "release", "release throttle component instance");
108

109
    // Disable loading of all external components
110
    std::vector<std::string> const cfg = {
111
        "hpx.components.load_external=0", "hpx.run_hpx_main!=1"};
×
112

113
    hpx::init_params init_args;
×
114
    init_args.mode = hpx::runtime_mode::connect;
×
115
    init_args.cfg = cfg;
×
116
    init_args.desc_cmdline = cmdline;
×
117

118
    return hpx::init(argc, argv, init_args);
×
119
}
×
120

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