34 #include "ns3/mpi-receiver.h"
36 #include "ns3/node-list.h"
37 #include "ns3/net-device.h"
38 #include "ns3/nstime.h"
39 #include "ns3/simulator.h"
144 static TypeId tid =
TypeId (
"ns3::NullMessageMpiInterface")
146 .SetGroupName (
"Mpi")
202 MPI_Init (pargc, pargv);
246 for (uint32_t rank = 0; rank <
g_size; ++rank)
272 std::list<NullMessageSentBuffer>::reverse_iterator iter =
g_pendingTx.rbegin ();
275 uint32_t bufferSize = serializedSize + ( 2 *
sizeof (uint64_t) ) + ( 2 *
sizeof (uint32_t) );
276 uint8_t* buffer =
new uint8_t[bufferSize];
277 iter->SetBuffer (buffer);
280 uint64_t* pTime =
reinterpret_cast <uint64_t *
> (buffer);
286 uint32_t* pData =
reinterpret_cast<uint32_t *
> (pTime);
290 p->
Serialize (
reinterpret_cast<uint8_t *
> (pData), serializedSize);
292 MPI_Isend (
reinterpret_cast<void *
> (iter->GetBuffer ()), bufferSize, MPI_CHAR, nodeSysId,
307 std::list<NullMessageSentBuffer>::reverse_iterator iter =
g_pendingTx.rbegin ();
309 uint32_t bufferSize = 2 *
sizeof (uint64_t) + 2 *
sizeof (uint32_t);
310 uint8_t* buffer =
new uint8_t[bufferSize];
311 iter->SetBuffer (buffer);
313 uint64_t* pTime =
reinterpret_cast <uint64_t *
> (buffer);
316 uint32_t* pData =
reinterpret_cast<uint32_t *
> (pTime);
321 uint32_t nodeSysId = bundle->GetSystemId ();
323 MPI_Isend (
reinterpret_cast<void *
> (iter->GetBuffer ()), bufferSize, MPI_CHAR, nodeSysId,
363 int messageReceived = 0;
381 MPI_Get_count (&status, MPI_CHAR, &count);
384 uint64_t* pTime =
reinterpret_cast<uint64_t *
> (
g_pRxBuffers[index]);
385 uint64_t time = *pTime++;
386 uint64_t guaranteeUpdate = *pTime++;
388 uint32_t* pData =
reinterpret_cast<uint32_t *
> (pTime);
389 uint32_t node = *pData++;
390 uint32_t dev = *pData++;
395 if (rxTime >
Time (0))
397 count -=
sizeof (time) +
sizeof (guaranteeUpdate) +
sizeof (node) +
sizeof (dev);
399 Ptr<Packet> p = Create<Packet> (
reinterpret_cast<uint8_t *
> (pData), count,
true);
405 for (uint32_t i = 0; i < nDevices; ++i)
426 bundle->SetGuaranteeTime (
Time (guaranteeUpdate));
449 std::list<NullMessageSentBuffer>::iterator iter =
g_pendingTx.begin ();
454 MPI_Test (iter->GetRequest (), &flag, &status);
455 std::list<NullMessageSentBuffer>::iterator current = iter;
471 for (std::list<NullMessageSentBuffer>::iterator iter =
g_pendingTx.begin ();
475 MPI_Cancel (iter->GetRequest ());
476 MPI_Request_free (iter->GetRequest ());
505 MPI_Initialized (&flag);
512 NS_FATAL_ERROR (
"Cannot disable MPI environment without Initializing it first");
521 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.
virtual uint32_t GetIfIndex(void) const =0
uint32_t GetId(void) const
uint32_t GetNDevices(void) const
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
uint32_t GetSystemId(void) const
static Ptr< Node > GetNode(uint32_t n)
virtual void Disable()
Clean up the ns-3 parallel communications interface.
static bool g_mpiInitCalled
Has MPI Init been called by this interface.
virtual void Destroy()
Deletes storage used by the parallel environment.
static void ReceiveMessagesBlocking()
Blocking message receive.
virtual void SendPacket(Ptr< Packet > p, const Time &rxTime, uint32_t node, uint32_t dev)
Send a packet to a remote node.
virtual MPI_Comm GetCommunicator()
Return the communicator used to run ns-3.
static MPI_Comm g_communicator
MPI communicator being used for ns-3 tasks.
static TypeId GetTypeId(void)
Register this type.
static void ReceiveMessagesNonBlocking()
Non-blocking check for received messages complete.
~NullMessageMpiInterface()
virtual bool IsEnabled()
Returns enabled state of parallel environment.
NullMessageMpiInterface()
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.
static bool g_enabled
Has this interface been enabled.
static void InitializeSendReceiveBuffers(void)
Initialize send and receive buffers.
static char ** g_pRxBuffers
Data buffers for non-blocking receives.
static uint32_t g_sid
System ID (rank) for this task.
virtual uint32_t GetSystemId()
Get the id number of this rank.
static uint32_t g_size
Size of the MPI COM_WORLD group.
virtual uint32_t GetSize()
Get the number of ranks used by ns-3.
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.
virtual void Enable(int *pargc, char ***pargv)
Setup the parallel communication interface.
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.
Time CalculateGuaranteeTime(uint32_t systemId)
static NullMessageSimulatorImpl * GetInstance(void)
void RescheduleNullMessageEvent(Ptr< RemoteChannelBundle > bundle)
A base class which provides memory management and object aggregation.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
Serialize a packet, tags, and metadata into a byte buffer.
uint32_t GetSerializedSize(void) const
Returns number of bytes required for packet serialization.
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(void)
Get the number of ns-3 channels in this bundle.
static void ScheduleWithContext(uint32_t context, Time const &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
static Time Now(void)
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
int64_t GetInteger(void) 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.
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.