A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
distributed-simulator-impl.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Author: George Riley <riley@ece.gatech.edu>
5 *
6 */
7
8/**
9 * @file
10 * @ingroup mpi
11 * Declaration of classes ns3::LbtsMessage and ns3::DistributedSimulatorImpl.
12 */
13
14#ifndef NS3_DISTRIBUTED_SIMULATOR_IMPL_H
15#define NS3_DISTRIBUTED_SIMULATOR_IMPL_H
16
17#include "ns3/event-impl.h"
18#include "ns3/ptr.h"
19#include "ns3/scheduler.h"
20#include "ns3/simulator-impl.h"
21
22#include <list>
23
24namespace ns3
25{
26
27/**
28 * @ingroup mpi
29 *
30 * @brief Structure used for all-reduce LBTS computation
31 */
33{
34 public:
36 : m_txCount(0),
37 m_rxCount(0),
38 m_myId(0),
39 m_isFinished(false)
40 {
41 }
42
43 /**
44 * @param rxc received count
45 * @param txc transmitted count
46 * @param id mpi rank
47 * @param isFinished whether message is finished
48 * @param t smallest time
49 */
50 LbtsMessage(uint32_t rxc, uint32_t txc, uint32_t id, bool isFinished, const Time& t)
51 : m_txCount(txc),
52 m_rxCount(rxc),
53 m_myId(id),
55 m_isFinished(isFinished)
56 {
57 }
58
60
61 /**
62 * @return smallest time
63 */
65 /**
66 * @return transmitted count
67 */
68 uint32_t GetTxCount() const;
69 /**
70 * @return received count
71 */
72 uint32_t GetRxCount() const;
73 /**
74 * @return id which corresponds to mpi rank
75 */
76 uint32_t GetMyId() const;
77 /**
78 * @return true if system is finished
79 */
80 bool IsFinished() const;
81
82 private:
83 uint32_t m_txCount; /**< Count of transmitted messages. */
84 uint32_t m_rxCount; /**< Count of received messages. */
85 uint32_t m_myId; /**< System Id of the rank sending this LBTS. */
86 Time m_smallestTime; /**< Earliest next event timestamp. */
87 bool m_isFinished; /**< \c true when this rank has no more events. */
88};
89
90/**
91 * @ingroup simulator
92 * @ingroup mpi
93 *
94 * @brief Distributed simulator implementation using lookahead
95 */
97{
98 public:
99 /**
100 * Register this type.
101 * @return The object TypeId.
102 */
103 static TypeId GetTypeId();
104
105 /** Default constructor. */
107 /** Destructor. */
108 ~DistributedSimulatorImpl() override;
109
110 // virtual from SimulatorImpl
111 void Destroy() override;
112 bool IsFinished() const override;
113 void Stop() override;
114 EventId Stop(const Time& delay) override;
115 EventId Schedule(const Time& delay, EventImpl* event) override;
116 void ScheduleWithContext(uint32_t context, const Time& delay, EventImpl* event) override;
117 EventId ScheduleNow(EventImpl* event) override;
118 EventId ScheduleDestroy(EventImpl* event) override;
119 void Remove(const EventId& id) override;
120 void Cancel(const EventId& id) override;
121 bool IsExpired(const EventId& id) const override;
122 void Run() override;
123 Time Now() const override;
124 Time GetDelayLeft(const EventId& id) const override;
125 Time GetMaximumSimulationTime() const override;
126 void SetScheduler(ObjectFactory schedulerFactory) override;
127 uint32_t GetSystemId() const override;
128 uint32_t GetContext() const override;
129 uint64_t GetEventCount() const override;
130
131 /**
132 * Add additional bound to lookahead constraints.
133 *
134 * This may be used if there are additional constraints on lookahead
135 * in addition to the minimum inter rank latency time. For example
136 * when running ns-3 in a co-simulation setting the other simulators
137 * may have tighter lookahead constraints.
138 *
139 * The method may be invoked more than once, the minimum time will
140 * be used to constrain lookahead.
141 *
142 * @param [in] lookAhead The maximum lookahead; must be > 0.
143 */
144 virtual void BoundLookAhead(const Time lookAhead);
145
146 private:
147 // Inherited from Object
148 void DoDispose() override;
149
150 /**
151 * Calculate lookahead constraint based on network latency.
152 *
153 * The smallest cross-rank PointToPoint channel delay imposes
154 * a constraint on the conservative PDES time window. The
155 * user may impose additional constraints on lookahead
156 * using the ConstrainLookAhead() method.
157 */
158 void CalculateLookAhead();
159 /**
160 * Check if this rank is finished. It's finished when there are
161 * no more events or stop has been requested.
162 *
163 * @returns \c true when this rank is finished.
164 */
165 bool IsLocalFinished() const;
166
167 /** Process the next event. */
168 void ProcessOneEvent();
169 /**
170 * Get the timestep of the next event.
171 *
172 * If there are no more events the timestep is infinity.
173 *
174 * @return The next event timestep.
175 */
176 uint64_t NextTs() const;
177 /**
178 * Get the time of the next event, as returned by NextTs().
179 *
180 * @return The next event time stamp.
181 */
182 Time Next() const;
183
184 /** Container type for the events to run at Simulator::Destroy(). */
185 typedef std::list<EventId> DestroyEvents;
186
187 /** The container of events to run at Destroy() */
189 /** Flag calling for the end of the simulation. */
190 bool m_stop;
191 /** Are all parallel instances completed. */
193 /** The event priority queue. */
195
196 /** Next event unique id. */
198 /** Unique id of the current event. */
200 /** Timestamp of the current event. */
201 uint64_t m_currentTs;
202 /** Execution context of the current event. */
204 /** The event count. */
205 uint64_t m_eventCount;
206 /**
207 * Number of events that have been inserted but not yet scheduled,
208 * not counting the "destroy" events; this is used for validation.
209 */
211
212 /**
213 * Container for Lbts messages, one per rank.
214 * Allocated once we know how many systems there are.
215 */
217 uint32_t m_myId; /**< MPI rank. */
218 uint32_t m_systemCount; /**< MPI communicator size. */
219 Time m_grantedTime; /**< End of current window. */
220 static Time m_lookAhead; /**< Current window size. */
221};
222
223} // namespace ns3
224
225#endif /* NS3_DISTRIBUTED_SIMULATOR_IMPL_H */
Distributed simulator implementation using lookahead.
EventId Schedule(const Time &delay, EventImpl *event) override
Schedule a future event execution (in the same context).
uint64_t GetEventCount() const override
Get the number of events executed.
void Remove(const EventId &id) override
Remove an event from the event list.
static TypeId GetTypeId()
Register this type.
DestroyEvents m_destroyEvents
The container of events to run at Destroy()
void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event) override
Schedule a future event execution (in a different context).
EventId ScheduleNow(EventImpl *event) override
Schedule an event to run at the current virtual time.
uint64_t NextTs() const
Get the timestep of the next event.
EventId ScheduleDestroy(EventImpl *event) override
Schedule an event to run at the end of the simulation, after the Stop() time or condition has been re...
Time m_grantedTime
End of current window.
uint32_t m_currentContext
Execution context of the current event.
Time GetMaximumSimulationTime() const override
Get the maximum representable simulation time.
LbtsMessage * m_pLBTS
Container for Lbts messages, one per rank.
uint64_t m_currentTs
Timestamp of the current event.
uint32_t GetSystemId() const override
Get the system id of this simulator.
void SetScheduler(ObjectFactory schedulerFactory) override
Set the Scheduler to be used to manage the event list.
bool IsFinished() const override
Check if the simulation should finish.
Ptr< Scheduler > m_events
The event priority queue.
Time Next() const
Get the time of the next event, as returned by NextTs().
void CalculateLookAhead()
Calculate lookahead constraint based on network latency.
uint32_t GetContext() const override
Get the current simulation context.
bool m_globalFinished
Are all parallel instances completed.
uint32_t m_uid
Next event unique id.
void Run() override
Run the simulation.
void ProcessOneEvent()
Process the next event.
std::list< EventId > DestroyEvents
Container type for the events to run at Simulator::Destroy().
void Cancel(const EventId &id) override
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
void Stop() override
Tell the Simulator the calling event should be the last one executed.
int m_unscheduledEvents
Number of events that have been inserted but not yet scheduled, not counting the "destroy" events; th...
void Destroy() override
Execute the events scheduled with ScheduleDestroy().
Time GetDelayLeft(const EventId &id) const override
Get the remaining time until this event will execute.
uint32_t m_systemCount
MPI communicator size.
virtual void BoundLookAhead(const Time lookAhead)
Add additional bound to lookahead constraints.
bool IsExpired(const EventId &id) const override
Check if an event has already run or been cancelled.
Time Now() const override
Return the current simulation virtual time.
bool IsLocalFinished() const
Check if this rank is finished.
bool m_stop
Flag calling for the end of the simulation.
static Time m_lookAhead
Current window size.
uint32_t m_currentUid
Unique id of the current event.
void DoDispose() override
Destructor implementation.
An identifier for simulation events.
Definition event-id.h:45
A simulation event.
Definition event-impl.h:35
Structure used for all-reduce LBTS computation.
uint32_t m_txCount
Count of transmitted messages.
uint32_t m_rxCount
Count of received messages.
uint32_t m_myId
System Id of the rank sending this LBTS.
Time m_smallestTime
Earliest next event timestamp.
bool m_isFinished
true when this rank has no more events.
LbtsMessage(uint32_t rxc, uint32_t txc, uint32_t id, bool isFinished, const Time &t)
Instantiate subclasses of ns3::Object.
Smart pointer class similar to boost::intrusive_ptr.
The SimulatorImpl base class.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.