A Discrete-Event Network Simulator
API
mpi-interface.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright 2013. Lawrence Livermore National Security, LLC.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Steven Smith <smith84@llnl.gov>
19  *
20  */
21 
22 #include "mpi-interface.h"
23 
24 #include <ns3/global-value.h>
25 #include <ns3/string.h>
26 #include <ns3/log.h>
27 
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("MpiInterface");
34 
35 ParallelCommunicationInterface* MpiInterface::g_parallelCommunicationInterface = 0;
36 
37 void
39 {
42 }
43 
44 uint32_t
46 {
49  else
50  return 0;
51 }
52 
53 uint32_t
55 {
58  else
59  return 1;
60 }
61 
62 bool
64 {
66  {
68  }
69  else
70  {
71  return false;
72  }
73 }
74 
75 void
76 MpiInterface::Enable (int* pargc, char*** pargv)
77 {
78  StringValue simulationTypeValue;
79  bool useDefault = true;
80 
81  if (GlobalValue::GetValueByNameFailSafe ("SimulatorImplementationType", simulationTypeValue))
82  {
83  std::string simulationType = simulationTypeValue.Get ();
84 
85  // Set communication interface based on the simulation type being used.
86  // Defaults to synchronous.
87  if (simulationType.compare ("ns3::NullMessageSimulatorImpl") == 0)
88  {
90  useDefault = false;
91  }
92  else if (simulationType.compare ("ns3::DistributedSimulatorImpl") == 0)
93  {
95  useDefault = false;
96  }
97  }
98 
99  // User did not specify a valid parallel simulator; use the default.
100  if (useDefault)
101  {
103  GlobalValue::Bind ("SimulatorImplementationType",
104  StringValue ("ns3::DistributedSimulatorImpl"));
105  NS_LOG_WARN ("SimulatorImplementationType was set to non-parallel simulator; setting type to ns3::DistributedSimulatorImp");
106  }
107 
109 }
110 
111 void
112 MpiInterface::SendPacket (Ptr<Packet> p, const Time& rxTime, uint32_t node, uint32_t dev)
113 {
115  g_parallelCommunicationInterface->SendPacket (p, rxTime, node, dev);
116 }
117 
118 
119 void
121 {
126 }
127 
128 
129 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Hold variables of type string.
Definition: string.h:41
virtual void Destroy()=0
Deletes storage used by the parallel environment.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
static void Disable()
Terminates the parallel environment.
std::string Get(void) const
Definition: string.cc:31
static void Destroy()
Deletes storage used by the parallel environment.
static void Enable(int *pargc, char ***pargv)
Sets up parallel communication interface.
static bool IsEnabled()
virtual void Disable()=0
Terminates the parallel environment.
virtual void Enable(int *pargc, char ***pargv)=0
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
static bool GetValueByNameFailSafe(std::string name, AttributeValue &value)
Finds the GlobalValue with the given name and returns its value.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual uint32_t GetSystemId()=0
static void SendPacket(Ptr< Packet > p, const Time &rxTime, uint32_t node, uint32_t dev)
static uint32_t GetSystemId()
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:262
static ParallelCommunicationInterface * g_parallelCommunicationInterface
Static instance of the instantiated parallel controller.
static uint32_t GetSize()
virtual void SendPacket(Ptr< Packet > p, const Time &rxTime, uint32_t node, uint32_t dev)=0
Interface between ns-3 and MPI for the Null Message distributed simulation implementation.