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

7
// hpxinspect:noinclude:hpx::util::from_string
8

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

15
#include "template_accumulator.hpp"
16

17
#include <iostream>
18
#include <string>
19
#include <vector>
20

21
///////////////////////////////////////////////////////////////////////////////
22
REGISTER_TEMPLATE_ACCUMULATOR(double)
×
23
REGISTER_TEMPLATE_ACCUMULATOR(int)
×
24

25
///////////////////////////////////////////////////////////////////////////////
26
char const* const help = "commands: reset, add [amount], query, help, quit";
27

28
template <typename T>
29
void run_template_accumulator(char const* type)
×
30
{
31
    typedef typename examples::server::template_accumulator<T> accumulator_type;
32
    typedef typename accumulator_type::argument_type argument_type;
33

34
    // Find the localities connected to this application.
35
    std::vector<hpx::id_type> localities = hpx::find_all_localities();
×
36

37
    // Create an accumulator component either on this locality (if the
38
    // example is executed on one locality only) or on any of the remote
39
    // localities (otherwise).
40
    examples::template_accumulator<T> accu =
×
41
        hpx::new_<accumulator_type>(localities.back());
42

43
    // Print out the available commands.
44
    std::cout << std::endl
45
              << "Running accumulator accepting argument type: " << type
×
46
              << std::endl;
47
    std::cout << help << std::endl;
48

49
    // Enter the interpreter loop.
50
    std::string line;
51
    while (std::getline(std::cin, line))
×
52
    {
53
        hpx::string_util::trim(line);
×
54

55
        std::vector<std::string> cmd;
×
56
        hpx::string_util::split(cmd, line, hpx::string_util::is_any_of(" \t\n"),
×
57
            hpx::string_util::token_compress_mode::on);
58

59
        if (!cmd.empty() && !cmd[0].empty())
×
60
        {
61
            // try to interpret the entered command
62
            if (cmd[0] == "reset")
×
63
            {
64
                accu.reset();
×
65
            }
66
            else if (cmd[0] == "add")
×
67
            {
68
                if (cmd.size() == 2)
×
69
                {
70
                    try
71
                    {
72
                        double val = hpx::util::from_string<double>(cmd[1]);
×
73
                        accu.add(argument_type(val));
×
74
                    }
75
                    catch (hpx::util::bad_lexical_cast const&)
×
76
                    {
77
                        std::cout << "error: invalid argument for add: '"
78
                                  << cmd[1] << "'" << std::endl;
79
                    }
80
                }
81
                else
82
                {
83
                    std::cout << "error: invalid command '" << line << "'"
84
                              << std::endl
85
                              << help << std::endl;
86
                }
87
            }
88
            else if (cmd[0] == "query")
×
89
            {
90
                std::cout << accu.query() << std::endl;
×
91
            }
92
            else if (cmd[0] == "help")
×
93
            {
94
                std::cout << help << std::endl;
95
            }
96
            else if (cmd[0] == "quit")
×
97
            {
98
                break;
99
            }
100
            else
101
            {
102
                std::cout << "error: invalid command '" << line << "'"
103
                          << std::endl
104
                          << help << std::endl;
105
            }
106
        }
107

108
        std::cout << "> ";
×
109
    }
110
}
×
111

112
///////////////////////////////////////////////////////////////////////////////
113
int hpx_main()
×
114
{
115
    // Dispatch to proper accumulator type
116
    while (std::cin)
×
117
    {
118
        std::cout << std::endl
119
                  << "Available accumulator types are: "
120
                     "double (press 1) and int (press 2): ";
×
121

122
        char c = '0';
×
123
        std::cin >> c;
×
124

125
        if (c == '1')
×
126
            run_template_accumulator<double>("double");
×
127
        else if (c == '2')
×
128
            run_template_accumulator<int>("int");
×
129
        else
130
            break;
131
    }
132

133
    // Initiate shutdown of the runtime systems on all localities.
134
    return hpx::finalize();
×
135
}
136

137
///////////////////////////////////////////////////////////////////////////////
138
int main(int argc, char* argv[])
×
139
{
140
    // We force this example to use 2 threads by default as one of the threads
141
    // will be sitting most of the time in the kernel waiting for user input.
142
    std::vector<std::string> const cfg = {"hpx.os_threads=2"};
×
143

144
    // Initialize and run HPX.
145
    hpx::init_params init_args;
×
146
    init_args.cfg = cfg;
×
147

148
    return hpx::init(argc, argv, init_args);
×
149
}
×
150

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

© 2026 Coveralls, Inc