Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9688312542   E-mail:ns3simulation@gmail.com

NS3 Parallel Simulation

The purpose of the parallel simulation is to speed up our simulations is to run them in parallel taking advantage of the power of all the processors and the memory availability of our machine.

Ns3 parallel simulation:

  • Ns3 offers the message passing interface (MPI) along with the distributed simulator class for this purpose of parallel simulation
  • Parallel simulation involves the execution of a single simulation program on a collection of tightly coupled processors

Goal of parallel simulation in ns3:

  • Speeding up simulation times while being as little intrusive for the end user as possible.
  • Chose to do multithreaded parallelism instead of distributed parallelism, i.e. doing parallelism using the resources of a single computer rather than using a bunch of compute.

DES of parallel simulation:

  • Centralized scheduling
  • Local synchronization
  • Typically shared memory context
  • Several execution resources
  • Memory-based communication mechanism etc.

LP (Logical Processor) in ns3:

  • An individual sequential simulation is referred to as a logical process (LP), and the unique number for each LP is referred to as the rank.
  • each LP can be placed on a different processor for execution

Example Ns3 parallel simulation scenario:

  • In this scenario a network topology consisting of two nodes in parallel. Each node is assigned to a dedicated logical processor.
  • default parallel synchronization strategy implemented in the DistributedSimulatorImpl class is based on a globally synchronized algorithm using an MPI collective operation to synchronize simulation time across all LPs.
  • A second synchronization strategy based on local communication and null messages is implemented in the NullMessageSimulatorImpl class, For the null message strategy the global all to all gather is not required; LPs only need to communication with LPs that have shared point-to-point links.

Sample code for Ns3 Parallel Simulation


#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/ndnSIM-module.h"
#include "ns3/mpi-interface.h"
#ifdef NS3_MPI
#include <mpi.h>
#else
#error "ndn-simple-mpi scenario can be compiled only if NS3_MPI is enabled"
#endif
namespace ns3 {
int
main(int argc, char* argv[])
{
Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Gbps"));
Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("1ms"));
Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("10"));
bool nullmsg = false;
CommandLine cmd;
cmd.AddValue("nullmsg", "Enable the use of null-message synchronization", nullmsg);
cmd.Parse(argc, argv);
if (nullmsg) {
GlobalValue::Bind("SimulatorImplementationType",
StringValue("ns3::NullMessageSimulatorImpl"));
}
else {
GlobalValue::Bind("SimulatorImplementationType",
StringValue("ns3::DistributedSimulatorImpl"));
}
MpiInterface::Enable(&argc, &argv);
uint32_t systemId = MpiInterface::GetSystemId();
uint32_t systemCount = MpiInterface::GetSize();
if (systemCount != 2) {
std::cout << "Simulation will run on a single processor only" << std::endl
<< "To run using MPI, run" << std::endl
<< " mpirun -np 2 ./waf --run=ndn-simple-mpi" << std::endl;
}
Ptr<Node> node1 = CreateObject<Node>(0);
Ptr<Node> node2 = CreateObject<Node>(systemCount == 2 ? 1 : 0);
PointToPointHelper p2p;
p2p.Install(node1, node2);
ndn::StackHelper ndnHelper;
ndnHelper.InstallAll();
ndn::FibHelper::AddRoute(node1, "/prefix/1", node2, 1);
ndn::FibHelper::AddRoute(node2, "/prefix/2", node1, 1);
ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
consumerHelper.SetAttribute("Frequency", StringValue("100")); // 10 interests a second
ndn::AppHelper producerHelper("ns3::ndn::Producer");
producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
if (systemCount != 2 || systemId == 0) {
consumerHelper.SetPrefix("/prefix/1"); // request /prefix/1/*
consumerHelper.Install(node1);
producerHelper.SetPrefix("/prefix/2"); // serve /prefix/2/*
producerHelper.Install(node1);
ndn::L3RateTracer::Install(node1, "node1.txt", Seconds(0.5));
}
if (systemCount != 2 || systemId == 1) {
consumerHelper.SetPrefix("/prefix/2"); // request /prefix/2/*
consumerHelper.Install(node2);
producerHelper.SetPrefix("/prefix/1"); // serve /prefix/1/*
producerHelper.Install(node2);
ndn::L3RateTracer::Install(node2, "node2.txt", Seconds(0.5));
}
Simulator::Stop(Seconds(400.0));
Simulator::Run();
Simulator::Destroy();
MpiInterface::Disable();
return 0;
}
}
int
main(int argc, char* argv[])
{
return ns3::main(argc, argv);
}