A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
distributed-simulator-impl.h
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 *
15 * Author: George Riley <riley@ece.gatech.edu>
16 *
17 */
18
19/**
20 * \file
21 * \ingroup mpi
22 * Declaration of classes ns3::LbtsMessage and ns3::DistributedSimulatorImpl.
23 */
24
25#ifndef NS3_DISTRIBUTED_SIMULATOR_IMPL_H
26#define NS3_DISTRIBUTED_SIMULATOR_IMPL_H
27
28#include "ns3/event-impl.h"
29#include "ns3/ptr.h"
30#include "ns3/scheduler.h"
31#include "ns3/simulator-impl.h"
32
33#include <list>
34
35namespace ns3
36{
37
38/**
39 * \ingroup mpi
40 *
41 * \brief Structure used for all-reduce LBTS computation
42 */
44{
45 public:
47 : m_txCount(0),
48 m_rxCount(0),
49 m_myId(0),
50 m_isFinished(false)
51 {
52 }
53
54 /**
55 * \param rxc received count
56 * \param txc transmitted count
57 * \param id mpi rank
58 * \param isFinished whether message is finished
59 * \param t smallest time
60 */
61 LbtsMessage(uint32_t rxc, uint32_t txc, uint32_t id, bool isFinished, const Time& t)
62 : m_txCount(txc),
63 m_rxCount(rxc),
64 m_myId(id),
66 m_isFinished(isFinished)
67 {
68 }
69
71
72 /**
73 * \return smallest time
74 */
76 /**
77 * \return transmitted count
78 */
79 uint32_t GetTxCount() const;
80 /**
81 * \return received count
82 */
83 uint32_t GetRxCount() const;
84 /**
85 * \return id which corresponds to mpi rank
86 */
87 uint32_t GetMyId() const;
88 /**
89 * \return true if system is finished
90 */
91 bool IsFinished() const;
92
93 private:
94 uint32_t m_txCount; /**< Count of transmitted messages. */
95 uint32_t m_rxCount; /**< Count of received messages. */
96 uint32_t m_myId; /**< System Id of the rank sending this LBTS. */
97 Time m_smallestTime; /**< Earliest next event timestamp. */
98 bool m_isFinished; /**< \c true when this rank has no more events. */
99};
100
101/**
102 * \ingroup simulator
103 * \ingroup mpi
104 *
105 * \brief Distributed simulator implementation using lookahead
106 */
108{
109 public:
110 /**
111 * Register this type.
112 * \return The object TypeId.
113 */
114 static TypeId GetTypeId();
115
116 /** Default constructor. */
118 /** Destructor. */
119 ~DistributedSimulatorImpl() override;
120
121 // virtual from SimulatorImpl
122 void Destroy() override;
123 bool IsFinished() const override;
124 void Stop() override;
125 EventId Stop(const Time& delay) override;
126 EventId Schedule(const Time& delay, EventImpl* event) override;
127 void ScheduleWithContext(uint32_t context, const Time& delay, EventImpl* event) override;
128 EventId ScheduleNow(EventImpl* event) override;
129 EventId ScheduleDestroy(EventImpl* event) override;
130 void Remove(const EventId& id) override;
131 void Cancel(const EventId& id) override;
132 bool IsExpired(const EventId& id) const override;
133 void Run() override;
134 Time Now() const override;
135 Time GetDelayLeft(const EventId& id) const override;
136 Time GetMaximumSimulationTime() const override;
137 void SetScheduler(ObjectFactory schedulerFactory) override;
138 uint32_t GetSystemId() const override;
139 uint32_t GetContext() const override;
140 uint64_t GetEventCount() const override;
141
142 /**
143 * Add additional bound to lookahead constraints.
144 *
145 * This may be used if there are additional constraints on lookahead
146 * in addition to the minimum inter rank latency time. For example
147 * when running ns-3 in a co-simulation setting the other simulators
148 * may have tighter lookahead constraints.
149 *
150 * The method may be invoked more than once, the minimum time will
151 * be used to constrain lookahead.
152 *
153 * \param [in] lookAhead The maximum lookahead; must be > 0.
154 */
155 virtual void BoundLookAhead(const Time lookAhead);
156
157 private:
158 // Inherited from Object
159 void DoDispose() override;
160
161 /**
162 * Calculate lookahead constraint based on network latency.
163 *
164 * The smallest cross-rank PointToPoint channel delay imposes
165 * a constraint on the conservative PDES time window. The
166 * user may impose additional constraints on lookahead
167 * using the ConstrainLookAhead() method.
168 */
169 void CalculateLookAhead();
170 /**
171 * Check if this rank is finished. It's finished when there are
172 * no more events or stop has been requested.
173 *
174 * \returns \c true when this rank is finished.
175 */
176 bool IsLocalFinished() const;
177
178 /** Process the next event. */
179 void ProcessOneEvent();
180 /**
181 * Get the timestep of the next event.
182 *
183 * If there are no more events the timestep is infinity.
184 *
185 * \return The next event timestep.
186 */
187 uint64_t NextTs() const;
188 /**
189 * Get the time of the next event, as returned by NextTs().
190 *
191 * \return The next event time stamp.
192 */
193 Time Next() const;
194
195 /** Container type for the events to run at Simulator::Destroy(). */
196 typedef std::list<EventId> DestroyEvents;
197
198 /** The container of events to run at Destroy() */
200 /** Flag calling for the end of the simulation. */
201 bool m_stop;
202 /** Are all parallel instances completed. */
204 /** The event priority queue. */
206
207 /** Next event unique id. */
209 /** Unique id of the current event. */
211 /** Timestamp of the current event. */
212 uint64_t m_currentTs;
213 /** Execution context of the current event. */
215 /** The event count. */
216 uint64_t m_eventCount;
217 /**
218 * Number of events that have been inserted but not yet scheduled,
219 * not counting the "destroy" events; this is used for validation.
220 */
222
223 /**
224 * Container for Lbts messages, one per rank.
225 * Allocated once we know how many systems there are.
226 */
228 uint32_t m_myId; /**< MPI rank. */
229 uint32_t m_systemCount; /**< MPI communicator size. */
230 Time m_grantedTime; /**< End of current window. */
231 static Time m_lookAhead; /**< Current window size. */
232};
233
234} // namespace ns3
235
236#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:55
A simulation event.
Definition: event-impl.h:46
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.
Definition: ptr.h:77
The SimulatorImpl base class.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.