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