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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Steven Smith <smith84@llnl.gov>
18 */
19
20/**
21 * \file
22 * \ingroup mpi
23 * Declaration of class ns3::NullMessageSimulatorImpl.
24 */
25
26#ifndef NULLMESSAGE_SIMULATOR_IMPL_H
27#define NULLMESSAGE_SIMULATOR_IMPL_H
28
29#include <ns3/event-impl.h>
30#include <ns3/ptr.h>
31#include <ns3/scheduler.h>
32#include <ns3/simulator-impl.h>
33
34#include <fstream>
35#include <iostream>
36#include <list>
37
38namespace ns3
39{
40
41class NullMessageEvent;
42class NullMessageMpiInterface;
43class RemoteChannelBundle;
44
45/**
46 * \ingroup mpi
47 *
48 * \brief Simulator implementation using MPI and a Null Message algorithm.
49 */
51{
52 public:
53 /**
54 * Register this type.
55 * \return The object TypeId.
56 */
57 static TypeId GetTypeId();
58
59 /** Default constructor. */
61
62 /** Destructor. */
64
65 // virtual from SimulatorImpl
66 void Destroy() override;
67 bool IsFinished() const override;
68 void Stop() override;
69 EventId Stop(const Time& delay) override;
70 EventId Schedule(const Time& delay, EventImpl* event) override;
71 void ScheduleWithContext(uint32_t context, const Time& delay, EventImpl* event) override;
72 EventId ScheduleNow(EventImpl* event) override;
73 EventId ScheduleDestroy(EventImpl* event) override;
74 void Remove(const EventId& id) override;
75 void Cancel(const EventId& id) override;
76 bool IsExpired(const EventId& id) const override;
77 void Run() override;
78
79 Time Now() const override;
80 Time GetDelayLeft(const EventId& id) const override;
81 Time GetMaximumSimulationTime() const override;
82 void SetScheduler(ObjectFactory schedulerFactory) override;
83 uint32_t GetSystemId() const override;
84 uint32_t GetContext() const override;
85 uint64_t GetEventCount() const override;
86
87 /**
88 * \return singleton instance
89 *
90 * Singleton accessor.
91 */
93
94 private:
95 friend class NullMessageEvent;
98
99 /**
100 * Non blocking receive of pending messages.
101 */
103
104 /**
105 * Blocking receive of arriving messages.
106 */
108
109 void DoDispose() override;
110
111 /**
112 * Calculate the lookahead allowable for this MPI task. Basically
113 * the minimum latency on links to neighbor MPI tasks.
114 */
115 void CalculateLookAhead();
116
117 /**
118 * Process the next event on the queue.
119 */
120 void ProcessOneEvent();
121
122 /**
123 * \return next local event time.
124 */
125 Time Next() const;
126
127 /**
128 * Calculate the SafeTime. Should be called after message receives.
129 */
130 void CalculateSafeTime();
131
132 /**
133 * Get the current SafeTime; the maximum time that events can
134 * be processed based on information received from neighboring
135 * MPI tasks.
136 * \return the current SafeTime
137 */
139
140 /**
141 * \param bundle Bundle to schedule Null Message event for
142 *
143 * Schedule Null Message event for the specified RemoteChannelBundle.
144 */
146
147 /**
148 * \param bundle Bundle to reschedule Null Message event for
149 *
150 * Reschedule Null Message event for the specified
151 * RemoteChannelBundle. Existing event will be canceled.
152 */
154
155 /**
156 * \param nodeSysId SystemID to reschedule null event for
157 *
158 * Reschedule Null Message event for the RemoteChannelBundle to the
159 * task nodeSysId. Existing event will be canceled.
160 */
161 void RescheduleNullMessageEvent(uint32_t nodeSysId);
162
163 /**
164 * \param systemId SystemID to compute guarantee time for
165 *
166 * \return Guarantee time
167 *
168 * Calculate the guarantee time for incoming RemoteChannelBundle
169 * from task nodeSysId. No message should arrive from task
170 * nodeSysId with a receive time less than the guarantee time.
171 */
173
174 /**
175 * \param bundle remote channel bundle to schedule an event for.
176 *
177 * Null message event handler. Scheduled to send a null message
178 * for the specified bundle at regular intervals. Will canceled
179 * and rescheduled when packets are sent.
180 */
182
183 /** Container type for the events to run at Simulator::Destroy(). */
184 typedef std::list<EventId> DestroyEvents;
185
186 /** The container of events to run at Destroy() */
188 /** Flag calling for the end of the simulation. */
189 bool m_stop;
190 /** The event priority queue. */
192
193 /** Next event unique id. */
195 /** Unique id of the current event. */
197 /** Timestamp of the current event. */
198 uint64_t m_currentTs;
199 /** Execution context of the current event. */
201 /** The event count. */
202 uint64_t m_eventCount;
203 /**
204 * Number of events that have been inserted but not yet scheduled,
205 * not counting the "destroy" events; this is used for validation.
206 */
208
209 uint32_t m_myId; /**< MPI rank. */
210 uint32_t m_systemCount; /**< MPI communicator size. */
211
212 /**
213 * The time for which it is safe for this task to execute events
214 * without danger of out-of-order events.
215 */
217
218 /**
219 * Null Message performance tuning parameter. Controls when Null
220 * messages are sent. When value is 1 the minimum number of Null
221 * messages are sent conserving bandwidth. The delay in arrival of
222 * lookahead information is the greatest resulting in maximum
223 * unnecessary blocking of the receiver. When the value is near 0
224 * Null Messages are sent with high frequency, costing more
225 * bandwidth and Null Message processing time, but there is minimum
226 * unnecessary block of the receiver.
227 */
229
230 /** Singleton instance. */
232};
233
234} // namespace ns3
235
236#endif /* NULLMESSAGE_SIMULATOR_IMPL_H */
An identifier for simulation events.
Definition: event-id.h:55
A simulation event.
Definition: event-impl.h:46
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...
Time CalculateGuaranteeTime(uint32_t systemId)
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.
Definition: ptr.h:77
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: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.