1#ifndef BITSIM_DISTRIBUTED_SYNCHRONISER_H
2#define BITSIM_DISTRIBUTED_SYNCHRONISER_H
8#include <boost/noncopyable.hpp>
118 const std::vector<PeerState> &
exchange(
uint_t step,
const std::vector<BodyState> &bodies,
119 const std::vector<real_t> &values = {});
128 const std::string &
participant() const noexcept {
return participant_; }
147 using steady = std::chrono::steady_clock;
150 void handle_(
const std::string &bytes);
152 const std::vector<PeerState> &lockstep_(
uint_t step);
153 const std::vector<PeerState> &wall_clock_(
uint_t step);
156 std::string participant_;
159 std::optional<StateMessage> current_;
160 std::optional<StateMessage> previous_;
161 bool has_left_{
false};
164 std::map<std::string, std::map<uint_t, StateMessage>> pending_;
166 std::map<std::string, StateMessage> latest_;
168 std::map<std::string, uint_t> left_at_;
170 std::optional<steady::time_point> start_;
171 std::vector<PeerState> peers_;
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
uint_t n_sent() const noexcept
Definition synchroniser.h:132
Synchroniser(Transport &transport, const std::string &participant, const SynchroniserConfig &config)
Definition synchroniser.cpp:20
real_t max_wait() const noexcept
lockstep: the longest exchange() waited [s]; wall-clock: the latest a step started
Definition synchroniser.h:144
uint_t n_received() const noexcept
Definition synchroniser.h:133
const std::vector< PeerState > & exchange(uint_t step, const std::vector< BodyState > &bodies, const std::vector< real_t > &values={})
Send the state of this participant's bodies at step, and get the others'.
Definition synchroniser.cpp:102
~Synchroniser()
Leaves, if leave() was not called.
Definition synchroniser.cpp:35
const std::string & participant() const noexcept
Definition synchroniser.h:128
uint_t n_resent() const noexcept
Definition synchroniser.h:134
const SynchroniserConfig & config() const noexcept
Definition synchroniser.h:130
uint_t n_overruns() const noexcept
wall-clock: the steps that started more than a sync period late
Definition synchroniser.h:139
void leave()
Tell the others that this participant stops after the last step it exchanged.
Definition synchroniser.cpp:299
real_t time_of(uint_t step) const noexcept
Definition synchroniser.h:126
How the participants of a distributed simulation reach each other: everything one publishes,...
Definition transport.h:34
Definition chrono_ghosts.cpp:12
SyncMode
How the participants of a distributed simulation keep time.
Definition synchroniser.h:25
@ WALL_CLOCK
Definition synchroniser.h:38
@ LOCKSTEP
Definition synchroniser.h:31
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20
What a participant knows of another at a step.
Definition synchroniser.h:68
std::string participant
Definition synchroniser.h:69
real_t age
wall-clock: how long ago it was sent [s]; 0 in lockstep
Definition synchroniser.h:72
real_t time
the simulated time of the state
Definition synchroniser.h:71
std::vector< real_t > values
the values it sent with the state, as they were
Definition synchroniser.h:76
uint_t step
Definition synchroniser.h:70
bool left
the participant has left; bodies is its last state
Definition synchroniser.h:74
bool stale
wall-clock: older than stale_after, or never received
Definition synchroniser.h:73
std::vector< BodyState > bodies
Definition synchroniser.h:75
What a participant of a distributed simulation sends: the state of its bodies at one step,...
Definition state_message.h:64
The settings of Synchroniser.
Definition synchroniser.h:45
SyncMode mode
Definition synchroniser.h:46
real_t sync_period
the simulated time between two exchanges [s]
Definition synchroniser.h:47
real_t real_time_factor
wall-clock: simulated seconds per wall-clock second
Definition synchroniser.h:59
real_t timeout
lockstep: the longest wait for a step [s]
Definition synchroniser.h:56
std::vector< std::string > peers
Definition synchroniser.h:54
real_t resend_period
lockstep: send the last steps again this often while waiting [s]
Definition synchroniser.h:57
real_t stale_after
wall-clock: a state older than this is stale [s]
Definition synchroniser.h:60
bool extrapolate
wall-clock: move the states forward by their age
Definition synchroniser.h:61