• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #869

20 Jan 2023 12:14AM UTC coverage: 86.397% (-0.09%) from 86.487%
#869

push

web-flow
Merge pull request #6142 from msimberg/update-daint-jenkins-perftest-references

Update performance test references for Piz Daint

174481 of 201952 relevant lines covered (86.4%)

2150263.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.1
/examples/quickstart/custom_serialization.cpp
1
//  Copyright (c) 2022 John Sorial
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
// This example is meant for inclusion in the documentation.
8

9
#include <hpx/format.hpp>
10
#include <hpx/future.hpp>
11
#include <hpx/hpx_main.hpp>
12
#include <hpx/include/actions.hpp>
13
#include <hpx/include/runtime.hpp>
14
#include <hpx/include/util.hpp>
15
#include <hpx/serialization.hpp>
16

17
#include <iostream>
18
#include <memory>
19

20
//[point_member_serialization
21
struct point_member_serialization
×
22
{
23
    int x{0};
×
24
    int y{0};
×
25

26
    // Required when defining the serialization function as private
27
    // In this case it isn't
28
    // Provides serialization access to HPX
29
    friend class hpx::serialization::access;
30

31
    // Second argument exists solely for compatibility with boost serialize
32
    // it is NOT processed by HPX in any way.
33
    template <typename Archive>
34
    void serialize(Archive& ar, const unsigned int)
×
35
    {
36
        // clang-format off
37
        ar & x & y;
×
38
        // clang-format on
39
    }
×
40
};
41

42
// Allow bitwise serialization
43
HPX_IS_BITWISE_SERIALIZABLE(point_member_serialization)
44
//]
45

46
//[rectangle_member_serialization
47
struct rectangle_member_serialization
48
{
49
    point_member_serialization top_left;
50
    point_member_serialization lower_right;
51

52
    template <typename Archive>
53
    void serialize(Archive& ar, const unsigned int)
54
    {
55
        // clang-format off
56
        ar & top_left & lower_right;
57
        // clang-format on
58
    }
59
};
60
//]
61

62
//[rectangle_free
63
struct rectangle_free
×
64
{
65
    point_member_serialization top_left;
66
    point_member_serialization lower_right;
67
};
68

69
template <typename Archive>
70
void serialize(Archive& ar, rectangle_free& pt, const unsigned int)
×
71
{
72
    // clang-format off
73
    ar & pt.lower_right & pt.top_left;
×
74
    // clang-format on
75
}
×
76
//]
77

78
//[point_class
79
class point_class
80
{
81
public:
82
    point_class(int x, int y)
83
      : x(x)
84
      , y(y)
85
    {
86
    }
87

88
    point_class() = default;
89

90
    [[nodiscard]] int get_x() const noexcept
91
    {
92
        return x;
93
    }
94

95
    [[nodiscard]] int get_y() const noexcept
96
    {
97
        return y;
98
    }
99

100
private:
101
    int x;
102
    int y;
103
};
104

105
template <typename Archive>
106
void load(Archive& ar, point_class& pt, const unsigned int)
107
{
108
    int x, y;
109
    ar >> x >> y;
110
    pt = point_class(x, y);
111
}
112

113
template <typename Archive>
114
void save(Archive& ar, point_class const& pt, const unsigned int)
115
{
116
    ar << pt.get_x() << pt.get_y();
117
}
118

119
// This tells HPX that you have spilt your serialize function into
120
// load and save
121
HPX_SERIALIZATION_SPLIT_FREE(point_class)
122
//]
123

124
//[SendRectangle
125
void send_rectangle_struct(rectangle_free rectangle)
×
126
{
127
    hpx::util::format_to(std::cout,
×
128
        "Rectangle(Point(x={1},y={2}),Point(x={3},y={4}))\n",
×
129
        rectangle.top_left.x, rectangle.top_left.y, rectangle.lower_right.x,
×
130
        rectangle.lower_right.y);
×
131
}
×
132
//]
133

134
HPX_PLAIN_ACTION(send_rectangle_struct)
3✔
135

136
//[planet_weight_calculator
137
class planet_weight_calculator
138
{
139
public:
140
    explicit planet_weight_calculator(double g)
1✔
141
      : g(g)
1✔
142
    {
143
    }
1✔
144

145
    template <class Archive>
146
    friend void save_construct_data(
147
        Archive&, planet_weight_calculator const*, unsigned int);
148

149
    [[nodiscard]] double get_g() const
1✔
150
    {
151
        return g;
1✔
152
    }
153

154
private:
155
    // Provides serialization access to HPX
156
    friend class hpx::serialization::access;
157
    template <class Archive>
158
    void serialize(Archive&, const unsigned int)
2✔
159
    {
160
        // Serialization will be done in the save_construct_data
161
        // Still needs to be defined
162
    }
2✔
163

164
    double g;
165
};
166
//]
167

168
//[save_construct_data
169
template <class Archive>
170
inline void save_construct_data(Archive& ar,
×
171
    planet_weight_calculator const* weight_calc, const unsigned int)
172
{
173
    ar << weight_calc->g;    // Do all of your serialization here
×
174
}
×
175

176
template <class Archive>
177
inline void load_construct_data(
1✔
178
    Archive& ar, planet_weight_calculator* weight_calc, const unsigned int)
179
{
180
    double g;
181
    ar >> g;
1✔
182

183
    // ::new(ptr) construct new object at given address
184
    hpx::construct_at(weight_calc, g);
1✔
185
}
1✔
186
//]
187

188
void send_gravity(planet_weight_calculator gravity)
1✔
189
{
190
    std::cout << "gravity.g = " << gravity.get_g() << std::endl;
1✔
191
}
1✔
192

193
HPX_PLAIN_ACTION(send_gravity)
4✔
194

195
//[Main
196
int main()
×
197
{
198
    // Needs at least two localities to run
199
    // When sending to your current locality, no serialization is done
200
    send_rectangle_struct_action rectangle_action;
201
    auto rectangle = rectangle_free{{0, 0}, {0, 5}};
×
202
    hpx::async(rectangle_action, hpx::find_here(), rectangle).get();
×
203

204
    send_gravity_action gravityAction;
205
    auto gravity = planet_weight_calculator(9.81);
×
206
    hpx::async(gravityAction, hpx::find_remote_localities()[0], gravity).get();
×
207

208
    return 0;
×
209
}
×
210
//]
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