A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mpi-interface.cc
Go to the documentation of this file.
1/*
2 * Copyright 2013. Lawrence Livermore National Security, LLC.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Steven Smith <smith84@llnl.gov>
18 */
19
20/**
21 * \file
22 * \ingroup mpi
23 * Implementation of class ns3::MpiInterface.
24 */
25
26#include "mpi-interface.h"
27
30
31#include <ns3/global-value.h>
32#include <ns3/log.h>
33#include <ns3/string.h>
34
35namespace ns3
36{
37
38NS_LOG_COMPONENT_DEFINE("MpiInterface");
39
40ParallelCommunicationInterface* MpiInterface::g_parallelCommunicationInterface = nullptr;
41
42void
44{
47}
48
51{
53 {
55 }
56 else
57 {
58 return 0;
59 }
60}
61
64{
66 {
68 }
69 else
70 {
71 return 1;
72 }
73}
74
75bool
77{
79 {
81 }
82 else
83 {
84 return false;
85 }
86}
87
88void
90{
91 StringValue simulationTypeValue;
92 bool useDefault = true;
93
94 if (GlobalValue::GetValueByNameFailSafe("SimulatorImplementationType", simulationTypeValue))
95 {
96 std::string simulationType = simulationTypeValue.Get();
97
98 // Set communication interface based on the simulation type being used.
99 // Defaults to synchronous.
100 if (simulationType == "ns3::NullMessageSimulatorImpl")
101 {
103 useDefault = false;
104 }
105 else if (simulationType == "ns3::DistributedSimulatorImpl")
106 {
108 useDefault = false;
109 }
110 }
111
112 // User did not specify a valid parallel simulator; use the default.
113 if (useDefault)
114 {
116 GlobalValue::Bind("SimulatorImplementationType",
117 StringValue("ns3::DistributedSimulatorImpl"));
118 NS_LOG_WARN("SimulatorImplementationType was set to non-parallel simulator; setting type "
119 "to ns3::DistributedSimulatorImp");
120 }
121}
122
123void
124MpiInterface::Enable(int* pargc, char*** pargv)
125{
127
129}
130
131void
132MpiInterface::Enable(MPI_Comm communicator)
133{
136}
137
138void
140{
142 g_parallelCommunicationInterface->SendPacket(p, rxTime, node, dev);
143}
144
145MPI_Comm
147{
150}
151
152void
154{
159}
160
161} // namespace ns3
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.
static ParallelCommunicationInterface * g_parallelCommunicationInterface
Static instance of the instantiated parallel controller.
static MPI_Comm GetCommunicator()
Return the communicator used to run ns-3.
static void SendPacket(Ptr< Packet > p, const Time &rxTime, uint32_t node, uint32_t dev)
Send a packet to a remote node.
static bool IsEnabled()
Returns enabled state of parallel environment.
static void Destroy()
Deletes storage used by the parallel environment.
static uint32_t GetSystemId()
Get the id number of this rank.
static uint32_t GetSize()
Get the number of ranks used by ns-3.
static void Disable()
Clean up the ns-3 parallel communications interface.
static void Enable(int *pargc, char ***pargv)
Setup the parallel communication interface.
static void SetParallelSimulatorImpl()
Common enable logic.
Interface between ns-3 and MPI for the Null Message distributed simulation implementation.
virtual void SendPacket(Ptr< Packet > p, const Time &rxTime, uint32_t node, uint32_t dev)=0
Send a packet to a remote node.
virtual void Enable(int *pargc, char ***pargv)=0
Setup the parallel communication interface.
virtual bool IsEnabled()=0
Returns enabled state of parallel environment.
virtual MPI_Comm GetCommunicator()=0
Return the communicator used to run ns-3.
virtual uint32_t GetSystemId()=0
Get the id number of this rank.
virtual void Destroy()=0
Deletes storage used by the parallel environment.
virtual uint32_t GetSize()=0
Get the number of ranks used by ns-3.
virtual void Disable()=0
Clean up the ns-3 parallel communications interface.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Hold variables of type string.
Definition: string.h:56
std::string Get() const
Definition: string.cc:31
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Declaration of classes ns3::SentBuffer and ns3::GrantedTimeWindowMpiInterface.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
Declaration of class ns3::MpiInterface.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Declaration of classes ns3::NullMessageSentBuffer and ns3::NullMessageMpiInterface.