35 #include "ns3/net-device.h"
36 #include "ns3/node-list.h"
38 #include "ns3/nstime.h"
39 #include "ns3/simulator.h"
198 MPI_Init(pargc, pargv);
242 for (uint32_t rank = 0; rank <
g_size; ++rank)
276 uint32_t bufferSize = serializedSize + (2 *
sizeof(uint64_t)) + (2 *
sizeof(uint32_t));
277 auto buffer =
new uint8_t[bufferSize];
278 iter->SetBuffer(buffer);
281 auto pTime =
reinterpret_cast<uint64_t*
>(buffer);
284 Time guarantee_update =
288 auto pData =
reinterpret_cast<uint32_t*
>(pTime);
292 p->
Serialize(
reinterpret_cast<uint8_t*
>(pData), serializedSize);
294 MPI_Isend(
reinterpret_cast<void*
>(iter->GetBuffer()),
300 (iter->GetRequest()));
317 uint32_t bufferSize = 2 *
sizeof(uint64_t) + 2 *
sizeof(uint32_t);
318 auto buffer =
new uint8_t[bufferSize];
319 iter->SetBuffer(buffer);
321 auto pTime =
reinterpret_cast<uint64_t*
>(buffer);
324 auto pData =
reinterpret_cast<uint32_t*
>(pTime);
329 uint32_t nodeSysId = bundle->GetSystemId();
331 MPI_Isend(
reinterpret_cast<void*
>(iter->GetBuffer()),
337 (iter->GetRequest()));
375 int messageReceived = 0;
393 MPI_Get_count(&status, MPI_CHAR, &count);
396 auto pTime =
reinterpret_cast<uint64_t*
>(
g_pRxBuffers[index]);
397 uint64_t time = *pTime++;
398 uint64_t guaranteeUpdate = *pTime++;
400 auto pData =
reinterpret_cast<uint32_t*
>(pTime);
401 uint32_t node = *pData++;
402 uint32_t dev = *pData++;
407 if (rxTime >
Time(0))
409 count -=
sizeof(time) +
sizeof(guaranteeUpdate) +
sizeof(node) +
sizeof(dev);
411 Ptr<Packet> p = Create<Packet>(
reinterpret_cast<uint8_t*
>(pData), count,
true);
417 for (uint32_t i = 0; i < nDevices; ++i)
420 if (pThisDev->GetIfIndex() == dev)
440 bundle->SetGuaranteeTime(
Time(guaranteeUpdate));
471 MPI_Test(iter->GetRequest(), &flag, &status);
490 MPI_Cancel(iter->GetRequest());
491 MPI_Request_free(iter->GetRequest());
518 MPI_Initialized(&flag);
525 NS_FATAL_ERROR(
"Cannot disable MPI environment without Initializing it first");
534 NS_FATAL_ERROR(
"Cannot disable MPI environment without Initializing it first");
Class to aggregate to a NetDevice if it supports MPI capability.
void Receive(Ptr< Packet > p)
Direct an incoming packet to the device Receive() method.
uint32_t GetSystemId() const
uint32_t GetNDevices() const
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
static Ptr< Node > GetNode(uint32_t n)
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.
~NullMessageMpiInterface() override
NullMessageMpiInterface()
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.
Non-blocking send buffers for Null Message implementation.
MPI_Request m_request
MPI request posted for the send.
MPI_Request * GetRequest()
void SetBuffer(uint8_t *buffer)
uint8_t * m_buffer
Buffer for send.
static NullMessageSimulatorImpl * GetInstance()
Time CalculateGuaranteeTime(uint32_t systemId)
void RescheduleNullMessageEvent(Ptr< RemoteChannelBundle > bundle)
A base class which provides memory management and object aggregation.
uint32_t GetSerializedSize() const
Returns number of bytes required for packet serialization.
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
Serialize a packet, tags, and metadata into a byte buffer.
Smart pointer class similar to boost::intrusive_ptr.
static Ptr< RemoteChannelBundle > Find(uint32_t systemId)
Get the bundle corresponding to a remote rank.
static std::size_t Size()
Get the number of ns-3 channels in this bundle.
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
int64_t GetInteger() const
Get the raw time value, in the current resolution unit.
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
ns3::MpiReceiver declaration, provides an interface to aggregate to MPI-compatible NetDevices.
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const uint32_t NULL_MESSAGE_MAX_MPI_MSG_SIZE
maximum MPI message size for easy buffer creation
Declaration of classes ns3::NullMessageSentBuffer and ns3::NullMessageMpiInterface.
Declaration of class ns3::NullMessageSimulatorImpl.
Declaration of class ns3::RemoteChannelBundleManager.
Declaration of class ns3::RemoteChannelBundle.