• 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

85.71
/examples/quickstart/pingpong.cpp
1
//  Copyright (c) 2012 Mehmet Balman
2
//  Copyright (c) 2012 Hartmut Kaiser
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/hpx_init.hpp>
11
#include <hpx/include/actions.hpp>
12
#include <hpx/include/components.hpp>
13
#include <hpx/include/lcos.hpp>
14
#include <hpx/include/runtime.hpp>
15
#include <hpx/iostream.hpp>
16
#include <hpx/modules/timing.hpp>
17
#include <hpx/serialization.hpp>
18

19
#include <cstddef>
20
#include <iostream>
21
#include <memory>
22
#include <utility>
23
#include <vector>
24

25
///////////////////////////////////////////////////////////////////////////////
26
std::size_t const vsize_default = 1'048'576;
27
std::size_t const numiter_default = 5;
28

29
///////////////////////////////////////////////////////////////////////////////
30
void on_recv(
31
    hpx::id_type to, std::vector<double> const& in, std::size_t counter);
32
HPX_PLAIN_ACTION(on_recv, on_recv_action)
20✔
33

34
void on_recv(
10✔
35
    hpx::id_type to, std::vector<double> const& in, std::size_t counter)
36
{
37
    // received vector in
38
    if (--counter == 0)
10✔
39
        return;
1✔
40

41
    // send it to remote locality (to), and wait until it is received
42
    std::vector<double> data(in);
9✔
43

44
    on_recv_action act;
45
    act(to, hpx::find_here(), std::move(data), counter);
18✔
46
}
47

48
///////////////////////////////////////////////////////////////////////////////
49
void on_recv_ind(hpx::id_type to,
50
    std::shared_ptr<std::vector<double>> const& in, std::size_t counter);
51
HPX_PLAIN_ACTION(on_recv_ind, on_recv_ind_action)
×
52

53
void on_recv_ind(hpx::id_type to,
×
54
    std::shared_ptr<std::vector<double>> const& in, std::size_t counter)
55
{
56
    // received vector in
57
    if (--counter == 0)
×
58
        return;
×
59

60
    // send it to remote locality (to), and wait until it is received
61
    std::shared_ptr<std::vector<double>> data(
62
        std::make_shared<std::vector<double>>(*in));
63

64
    on_recv_ind_action act;
65
    act(to, hpx::find_here(), data, counter);
×
66
}
67

68
///////////////////////////////////////////////////////////////////////////////
69
int hpx_main(hpx::program_options::variables_map& b_arg)
1✔
70
{
71
    std::size_t const vsize = b_arg["vsize"].as<std::size_t>();
2✔
72
    std::size_t const numiter = b_arg["numiter"].as<std::size_t>() * 2;
2✔
73
    bool verbose = b_arg["verbose"].as<bool>();
2✔
74

75
    std::vector<hpx::id_type> localities = hpx::find_remote_localities();
1✔
76

77
    hpx::id_type to;
1✔
78
    if (localities.size() == 0)
1✔
79
    {
80
        to = hpx::find_here();
2✔
81
    }
82
    else
83
    {
84
        to = localities[0];    // send to first remote locality
85
    }
86

87
    // test sending messages back and forth using a larger vector as one of
88
    // the arguments
89
    {
90
        std::vector<double> data(vsize, double(3.11));
1✔
91

92
        hpx::chrono::high_resolution_timer timer1;
93

94
        if (numiter != 0)
1✔
95
        {
96
            on_recv_action act;
97
            act(to, hpx::find_here(), data, numiter);
2✔
98
        }
99

100
        double time = timer1.elapsed();
101
        double bandwidth =
1✔
102
            ((static_cast<double>(vsize * sizeof(double) * numiter) / time) /
1✔
103
                1024) /
104
            1024;
105
        if (verbose)
1✔
106
        {
107
            std::cout << "[hpx_pingpong]" << std::endl
108
                      << "total_time(secs)=" << time << std::endl
109
                      << "vsize=" << vsize << " = " << vsize * sizeof(double)
1✔
110
                      << " Bytes" << std::endl
111
                      << "bandwidth(MiB/s)=" << bandwidth << std::endl
112
                      << "localities=" << localities.size() << std::endl
113
                      << "numiter=" << numiter << std::endl;
1✔
114
        }
115
        else
116
        {
117
            std::cout << "[hpx_pingpong]"
118
                      << ":total_time(secs)=" << time << ":vsize=" << vsize
119
                      << ":bandwidth(MiB/s)=" << bandwidth
120
                      << ":localities=" << localities.size()
121
                      << ":numiter=" << numiter << std::endl;
×
122
        }
123
    }
124

125
    // do the same but with a wrapped vector
126
    /*
127
    {
128
        std::shared_ptr<std::vector<double> > data(
129
            std::make_shared<std::vector<double> >(vsize, double(3.11)));
130

131
        hpx::chrono::high_resolution_timer timer1;
132

133
        if (numiter != 0) {
134
            on_recv_ind_action act;
135
            act(to, hpx::find_here(), data, numiter);
136
        }
137

138
        double time = timer1.elapsed();
139

140
        std::cout << "[hpx_pingpong]"
141
                  << ":total_time(secs)=" << time
142
                  << ":vsize=" << vsize
143
                  << ":bandwidth(GB/s)=" << (vsize * sizeof(double) * numiter)
144
                    / (time * 1024 * 1024)
145
                  << ":localities=" << localities.size()
146
                  << ":numiter=" << numiter << std::endl;
147
    }
148
    */
149

150
    hpx::finalize();
151
    return 0;
1✔
152
}
1✔
153

154
int main(int argc, char* argv[])
1✔
155
{
156
    namespace po = hpx::program_options;
157
    po::options_description description("HPX pingpong example");
1✔
158

159
    description.add_options()("vsize",
2✔
160
        po::value<std::size_t>()->default_value(vsize_default),
1✔
161
        "number of elements (doubles) to send/receive  (integer)")("numiter",
1✔
162
        po::value<std::size_t>()->default_value(numiter_default),
1✔
163
        "number of ping-pong iterations")("verbose",
1✔
164
        po::value<bool>()->default_value(true),
1✔
165
        "verbosity of output,if false output is for awk");
166

167
    hpx::init_params init_args;
1✔
168
    init_args.desc_cmdline = description;
1✔
169

170
    return hpx::init(argc, argv, init_args);
1✔
171
}
1✔
172

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