A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
null-message-simulator-impl.h
Go to the documentation of this file.
1/*
2 * Copyright 2013. Lawrence Livermore National Security, LLC.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Steven Smith <smith84@llnl.gov>
7 */
8
9/**
10 * @file
11 * @ingroup mpi
12 * Declaration of class ns3::NullMessageSimulatorImpl.
13 */
14
15#ifndef NULLMESSAGE_SIMULATOR_IMPL_H
16#define NULLMESSAGE_SIMULATOR_IMPL_H
17
18#include <ns3/event-impl.h>
19#include <ns3/ptr.h>
20#include <ns3/scheduler.h>
21#include <ns3/simulator-impl.h>
22
23#include <fstream>
24#include <iostream>
25#include <list>
26
27namespace ns3
28{
29
30class NullMessageEvent;
31class NullMessageMpiInterface;
32class RemoteChannelBundle;
33
34/**
35 * @ingroup mpi
36 *
37 * @brief Simulator implementation using MPI and a Null Message algorithm.
38 */
40{
41 public:
42 /**
43 * Register this type.
44 * @return The object TypeId.
45 */
46 static TypeId GetTypeId();
47
48 /** Default constructor. */
50
51 /** Destructor. */
53
54 // virtual from SimulatorImpl
55 void Destroy() override;
56 bool IsFinished() const override;
57 void Stop() override;
58 EventId Stop(const Time& delay) override;
59 EventId Schedule(const Time& delay, EventImpl* event) override;
60 void ScheduleWithContext(uint32_t context, const Time& delay, EventImpl* event) override;
61 EventId ScheduleNow(EventImpl* event) override;
62 EventId ScheduleDestroy(EventImpl* event) override;
63 void Remove(const EventId& id) override;
64 void Cancel(const EventId& id) override;
65 bool IsExpired(const EventId& id) const override;
66 void Run() override;
67
68 Time Now() const override;
69 Time GetDelayLeft(const EventId& id) const override;
70 Time GetMaximumSimulationTime() const override;
71 void SetScheduler(ObjectFactory schedulerFactory) override;
72 uint32_t GetSystemId() const override;
73 uint32_t GetContext() const override;
74 uint64_t GetEventCount() const override;
75
76 /**
77 * @return singleton instance
78 *
79 * Singleton accessor.
80 */
82
83 private:
84 friend class NullMessageEvent;
87
88 /**
89 * Non blocking receive of pending messages.
90 */
92
93 /**
94 * Blocking receive of arriving messages.
95 */
97
98 void DoDispose() override;
99
100 /**
101 * Calculate the lookahead allowable for this MPI task. Basically
102 * the minimum latency on links to neighbor MPI tasks.
103 */
104 void CalculateLookAhead();
105
106 /**
107 * Process the next event on the queue.
108 */
109 void ProcessOneEvent();
110
111 /**
112 * @return next local event time.
113 */
114 Time Next() const;
115
116 /**
117 * Calculate the SafeTime. Should be called after message receives.
118 */
119 void CalculateSafeTime();
120
121 /**
122 * Get the current SafeTime; the maximum time that events can
123 * be processed based on information received from neighboring
124 * MPI tasks.
125 * @return the current SafeTime
126 */
128
129 /**
130 * @param bundle Bundle to schedule Null Message event for
131 *
132 * Schedule Null Message event for the specified RemoteChannelBundle.
133 */
135
136 /**
137 * @param bundle Bundle to reschedule Null Message event for
138 *
139 * Reschedule Null Message event for the specified
140 * RemoteChannelBundle. Existing event will be canceled.
141 */
143
144 /**
145 * @param nodeSysId SystemID to reschedule null event for
146 *
147 * Reschedule Null Message event for the RemoteChannelBundle to the
148 * task nodeSysId. Existing event will be canceled.
149 */
150 void RescheduleNullMessageEvent(uint32_t nodeSysId);
151
152 /**
153 * @param systemId SystemID to compute guarantee time for
154 *
155 * @return Guarantee time
156 *
157 * Calculate the guarantee time for incoming RemoteChannelBundle
158 * from task nodeSysId. No message should arrive from task
159 * nodeSysId with a receive time less than the guarantee time.
160 */
162
163 /**
164 * @param bundle remote channel bundle to schedule an event for.
165 *
166 * Null message event handler. Scheduled to send a null message
167 * for the specified bundle at regular intervals. Will canceled
168 * and rescheduled when packets are sent.
169 */
171
172 /** Container type for the events to run at Simulator::Destroy(). */
173 typedef std::list<EventId> DestroyEvents;
174
175 /** The container of events to run at Destroy() */
177 /** Flag calling for the end of the simulation. */
178 bool m_stop;
179 /** The event priority queue. */
181
182 /** Next event unique id. */
184 /** Unique id of the current event. */
186 /** Timestamp of the current event. */
187 uint64_t m_currentTs;
188 /** Execution context of the current event. */
190 /** The event count. */
191 uint64_t m_eventCount;
192 /**
193 * Number of events that have been inserted but not yet scheduled,
194 * not counting the "destroy" events; this is used for validation.
195 */
197
198 uint32_t m_myId; /**< MPI rank. */
199 uint32_t m_systemCount; /**< MPI communicator size. */
200
201 /**
202 * The time for which it is safe for this task to execute events
203 * without danger of out-of-order events.
204 */
206
207 /**
208 * Null Message performance tuning parameter. Controls when Null
209 * messages are sent. When value is 1 the minimum number of Null
210 * messages are sent conserving bandwidth. The delay in arrival of
211 * lookahead information is the greatest resulting in maximum
212 * unnecessary blocking of the receiver. When the value is near 0
213 * Null Messages are sent with high frequency, costing more
214 * bandwidth and Null Message processing time, but there is minimum
215 * unnecessary block of the receiver.
216 */
218
219 /** Singleton instance. */
221};
222
223} // namespace ns3
224
225#endif /* NULLMESSAGE_SIMULATOR_IMPL_H */
An identifier for simulation events.
Definition event-id.h:45
A simulation event.
Definition event-impl.h:35
Interface between ns-3 and MPI for the Null Message distributed simulation implementation.
Simulator implementation using MPI and a Null Message algorithm.
void CalculateLookAhead()
Calculate the lookahead allowable for this MPI task.
double m_schedulerTune
Null Message performance tuning parameter.
Ptr< Scheduler > m_events
The event priority queue.
void Remove(const EventId &id) override
Remove an event from the event list.
uint32_t m_currentUid
Unique id of the current event.
Time GetDelayLeft(const EventId &id) const override
Get the remaining time until this event will execute.
void HandleArrivingMessagesBlocking()
Blocking receive of arriving messages.
uint32_t m_systemCount
MPI communicator size.
void Run() override
Run the simulation.
void HandleArrivingMessagesNonBlocking()
Non blocking receive of pending messages.
uint32_t m_currentContext
Execution context of the current event.
void DoDispose() override
Destructor implementation.
uint32_t GetSystemId() const override
Get the system id of this simulator.
static NullMessageSimulatorImpl * GetInstance()
Time m_safeTime
The time for which it is safe for this task to execute events without danger of out-of-order events.
bool IsExpired(const EventId &id) const override
Check if an event has already run or been cancelled.
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...
static NullMessageSimulatorImpl * g_instance
Singleton instance.
void ProcessOneEvent()
Process the next event on the queue.
uint32_t m_uid
Next event unique id.
static TypeId GetTypeId()
Register this type.
uint64_t GetEventCount() const override
Get the number of events executed.
void SetScheduler(ObjectFactory schedulerFactory) override
Set the Scheduler to be used to manage the event list.
uint64_t m_currentTs
Timestamp of the current event.
Time GetMaximumSimulationTime() const override
Get the maximum representable simulation time.
void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event) override
Schedule a future event execution (in a different context).
void NullMessageEventHandler(RemoteChannelBundle *bundle)
DestroyEvents m_destroyEvents
The container of events to run at 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...
EventId Schedule(const Time &delay, EventImpl *event) override
Schedule a future event execution (in the same context).
uint32_t GetContext() const override
Get the current simulation context.
Time GetSafeTime()
Get the current SafeTime; the maximum time that events can be processed based on information received...
std::list< EventId > DestroyEvents
Container type for the events to run at Simulator::Destroy().
int m_unscheduledEvents
Number of events that have been inserted but not yet scheduled, not counting the "destroy" events; th...
bool IsFinished() const override
Check if the simulation should finish.
void Stop() override
Tell the Simulator the calling event should be the last one executed.
void RescheduleNullMessageEvent(Ptr< RemoteChannelBundle > bundle)
bool m_stop
Flag calling for the end of the simulation.
Time Now() const override
Return the current simulation virtual time.
void Destroy() override
Execute the events scheduled with ScheduleDestroy().
void CalculateSafeTime()
Calculate the SafeTime.
void ScheduleNullMessageEvent(Ptr< RemoteChannelBundle > bundle)
EventId ScheduleNow(EventImpl *event) override
Schedule an event to run at the current virtual time.
Instantiate subclasses of ns3::Object.
Smart pointer class similar to boost::intrusive_ptr.
Collection of ns-3 channels between local and remote nodes.
Singleton for managing the RemoteChannelBundles for each process.
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.