A Discrete-Event Network Simulator
API
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 
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 
38 namespace ns3
39 {
40 
41 class NullMessageEvent;
42 class NullMessageMpiInterface;
43 class RemoteChannelBundle;
44 
51 {
52  public:
57  static TypeId GetTypeId();
58 
61 
63  ~NullMessageSimulatorImpl() override;
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 
93 
94  private:
95  friend class NullMessageEvent;
98 
103 
108 
109  void DoDispose() override;
110 
115  void CalculateLookAhead();
116 
120  void ProcessOneEvent();
121 
125  Time Next() const;
126 
130  void CalculateSafeTime();
131 
138  Time GetSafeTime();
139 
146 
154 
161  void RescheduleNullMessageEvent(uint32_t nodeSysId);
162 
172  Time CalculateGuaranteeTime(uint32_t systemId);
173 
182 
184  typedef std::list<EventId> DestroyEvents;
185 
189  bool m_stop;
192 
194  uint32_t m_uid;
196  uint32_t m_currentUid;
198  uint64_t m_currentTs;
202  uint64_t m_eventCount;
208 
209  uint32_t m_myId;
210  uint32_t m_systemCount;
217 
229 
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.