A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
null-message-mpi-interface.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 classes ns3::NullMessageSentBuffer and ns3::NullMessageMpiInterface.
24 */
25
26#ifndef NS3_NULLMESSAGE_MPI_INTERFACE_H
27#define NS3_NULLMESSAGE_MPI_INTERFACE_H
28
30
31#include <ns3/buffer.h>
32#include <ns3/nstime.h>
33
34#include <list>
35#include <mpi.h>
36
37namespace ns3
38{
39
40class NullMessageSimulatorImpl;
41class NullMessageSentBuffer;
42class RemoteChannelBundle;
43class Packet;
44
45/**
46 * \ingroup mpi
47 *
48 * \brief Interface between ns-3 and MPI for the Null Message
49 * distributed simulation implementation.
50 */
52{
53 public:
54 /**
55 * Register this type.
56 * \return The object TypeId.
57 */
58 static TypeId GetTypeId();
59
61 ~NullMessageMpiInterface() override;
62
63 // Inherited
64 void Destroy() override;
65 uint32_t GetSystemId() override;
66 uint32_t GetSize() override;
67 bool IsEnabled() override;
68 void Enable(int* pargc, char*** pargv) override;
69 void Enable(MPI_Comm communicator) override;
70 void Disable() override;
71 void SendPacket(Ptr<Packet> p, const Time& rxTime, uint32_t node, uint32_t dev) override;
72 MPI_Comm GetCommunicator() override;
73
74 private:
75 /*
76 * The null message implementation is a collaboration of several
77 * classes. Methods that should be invoked only by the
78 * collaborators are private to restrict use.
79 * It is not intended for state to be shared.
80 */
83
84 /**
85 * \brief Send a Null Message to across the specified bundle.
86 *
87 * Null Messages are sent when a packet has not been sent across
88 * this bundle in order to allow time advancement on the remote
89 * MPI task.
90 *
91 * \param [in] guaranteeUpdate Lower bound time on the next
92 * possible event from this MPI task to the remote MPI task across
93 * the bundle. Remote task may execute events up to this time.
94 *
95 * \param [in] bundle The bundle of links between two ranks.
96 *
97 * \internal The Null Message MPI buffer format uses the same packet
98 * metadata format as sending a normal packet with the time,
99 * destination node, and destination device set to zero. Using the
100 * same packet metadata simplifies receive logic.
101 */
102 static void SendNullMessage(const Time& guaranteeUpdate, Ptr<RemoteChannelBundle> bundle);
103 /**
104 * Non-blocking check for received messages complete. Will
105 * receive all messages that are queued up locally.
106 */
107 static void ReceiveMessagesNonBlocking();
108 /**
109 * Blocking message receive. Will block until at least one message
110 * has been received.
111 */
112 static void ReceiveMessagesBlocking();
113 /**
114 * Check for completed sends
115 */
116 static void TestSendComplete();
117
118 /**
119 * \brief Initialize send and receive buffers.
120 *
121 * This method should be called after all links have been added to the RemoteChannelBundle
122 * manager to setup any required send and receive buffers.
123 */
124 static void InitializeSendReceiveBuffers();
125
126 /**
127 * Check for received messages complete. Will block until message
128 * has been received if blocking flag is true. When blocking will
129 * return after the first message is received. Non-blocking mode will
130 * only check for received messages complete, and return
131 * all messages that are queued up locally.
132 *
133 * \param [in] blocking Whether this call should block.
134 */
135 static void ReceiveMessages(bool blocking = false);
136
137 /** System ID (rank) for this task. */
139
140 /** Size of the MPI COM_WORLD group. */
142
143 /** Number of neighbor tasks, tasks that this task shares a link with. */
145
146 /** Has this interface been enabled. */
147 static bool g_enabled;
148
149 /**
150 * Has MPI Init been called by this interface.
151 * Alternatively user supplies a communicator.
152 */
153 static bool g_mpiInitCalled;
154
155 /** Pending non-blocking receives. */
156 static MPI_Request* g_requests;
157
158 /** Data buffers for non-blocking receives. */
159 static char** g_pRxBuffers;
160
161 /** List of pending non-blocking sends. */
162 static std::list<NullMessageSentBuffer> g_pendingTx;
163
164 /** MPI communicator being used for ns-3 tasks. */
165 static MPI_Comm g_communicator;
166
167 /** Did we create the communicator? Have to free it. */
169};
170
171} // namespace ns3
172
173#endif /* NS3_NULL_MESSAGE_MPI_INTERFACE_H */
Interface between ns-3 and MPI for the Null Message distributed simulation implementation.
static bool g_mpiInitCalled
Has MPI Init been called by this interface.
void Destroy() override
Deletes storage used by the parallel environment.
static void ReceiveMessagesBlocking()
Blocking message receive.
void SendPacket(Ptr< Packet > p, const Time &rxTime, uint32_t node, uint32_t dev) override
Send a packet to a remote node.
bool IsEnabled() override
Returns enabled state of parallel environment.
uint32_t GetSize() override
Get the number of ranks used by ns-3.
static MPI_Comm g_communicator
MPI communicator being used for ns-3 tasks.
static TypeId GetTypeId()
Register this type.
static void ReceiveMessagesNonBlocking()
Non-blocking check for received messages complete.
MPI_Comm GetCommunicator() override
Return the communicator used to run ns-3.
static MPI_Request * g_requests
Pending non-blocking receives.
static void SendNullMessage(const Time &guaranteeUpdate, Ptr< RemoteChannelBundle > bundle)
Send a Null Message to across the specified bundle.
static void TestSendComplete()
Check for completed sends.
static void ReceiveMessages(bool blocking=false)
Check for received messages complete.
void Enable(int *pargc, char ***pargv) override
Setup the parallel communication interface.
static bool g_enabled
Has this interface been enabled.
static char ** g_pRxBuffers
Data buffers for non-blocking receives.
static void InitializeSendReceiveBuffers()
Initialize send and receive buffers.
static uint32_t g_sid
System ID (rank) for this task.
static uint32_t g_size
Size of the MPI COM_WORLD group.
void Disable() override
Clean up the ns-3 parallel communications interface.
static std::list< NullMessageSentBuffer > g_pendingTx
List of pending non-blocking sends.
static bool g_freeCommunicator
Did we create the communicator? Have to free it.
uint32_t GetSystemId() override
Get the id number of this rank.
static uint32_t g_numNeighbors
Number of neighbor tasks, tasks that this task shares a link with.
Simulator implementation using MPI and a Null Message algorithm.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Pure virtual base class for the interface between ns-3 and the parallel communication layer being use...
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Collection of ns-3 channels between local and remote nodes.
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.
Declaration of class ns3::ParallelCommunicationInterface.