A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mpi-interface.h
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 * Declaration of class ns3::MpiInterface.
24 */
25
26#ifndef NS3_MPI_INTERFACE_H
27#define NS3_MPI_INTERFACE_H
28
29#include <ns3/nstime.h>
30#include <ns3/packet.h>
31
32#include <mpi.h>
33
34namespace ns3
35{
36/**
37 * \defgroup mpi MPI Distributed Simulation
38 */
39
40/**
41 * \ingroup mpi
42 * \ingroup tests
43 * \defgroup mpi-tests MPI Distributed Simulation tests
44 */
45
46class ParallelCommunicationInterface;
47
48/**
49 * \ingroup mpi
50 *
51 * \brief Singleton used to interface to the communications infrastructure
52 * when running NS3 in parallel.
53 *
54 * Delegates the implementation to the specific parallel
55 * infrastructure being used. Implementation is defined in the
56 * ParallelCommunicationInterface virtual base class; this API mirrors
57 * that interface. This singleton is responsible for instantiating an
58 * instance of the communication interface based on
59 * SimulatorImplementationType attribute in ns3::GlobalValues. The
60 * attribute must be set before Enable is invoked.
61 */
63{
64 public:
65 /**
66 * \brief Deletes storage used by the parallel environment.
67 */
68 static void Destroy();
69 /**
70 * \brief Get the id number of this rank.
71 *
72 * When running a sequential simulation this will return a systemID of 0.
73 *
74 * \return system identification
75 */
76 static uint32_t GetSystemId();
77 /**
78 * \brief Get the number of ranks used by ns-3.
79 *
80 * Returns the size (number of MPI ranks) of the communicator used by
81 * ns-3. When running a sequential simulation this will return a
82 * size of 1.
83 *
84 * \return number of parallel tasks
85 */
86 static uint32_t GetSize();
87 /**
88 * \brief Returns enabled state of parallel environment.
89 *
90 * \return true if parallel communication is enabled
91 */
92 static bool IsEnabled();
93 /**
94 * \brief Setup the parallel communication interface.
95 *
96 * There are two ways to setup the communications interface. This
97 * Enable method is the easiest method and should be used in most
98 * situations.
99 *
100 * Disable() must be invoked at end of an ns-3 application to
101 * properly cleanup the parallel communication interface.
102 *
103 * This method will call MPI_Init and configure ns-3 to use the
104 * MPI_COMM_WORLD communicator.
105 *
106 * For more complex situations, such as embedding ns-3 with other
107 * MPI simulators or libraries, the Enable(MPI_Comm communcicator)
108 * may be used if MPI is initialized externally or if ns-3 needs to
109 * be run unique communicator. For example if there are two
110 * parallel simulators and the goal is to run each simulator on a
111 * different set of ranks.
112 *
113 * \note The `SimulatorImplementationType attribute in
114 * ns3::GlobalValues must be set before calling Enable()
115 *
116 * \param pargc number of command line arguments
117 * \param pargv command line arguments
118 */
119 static void Enable(int* pargc, char*** pargv);
120 /**
121 * \brief Setup the parallel communication interface using the specified communicator.
122 *
123 * See @ref Enable (int* pargc, char*** pargv) for additional information.
124 *
125 * \param communicator MPI Communicator that should be used by ns-3
126 */
127 static void Enable(MPI_Comm communicator);
128 /**
129 * \brief Clean up the ns-3 parallel communications interface.
130 *
131 * MPI_Finalize will be called only if Enable (int* pargc, char***
132 * pargv) was called.
133 */
134 static void Disable();
135 /**
136 * \brief Send a packet to a remote node.
137 *
138 * \param p packet to send
139 * \param rxTime received time at destination node
140 * \param node destination node
141 * \param dev destination device
142 *
143 * Serialize and send a packet to the specified node and net device
144 */
145 static void SendPacket(Ptr<Packet> p, const Time& rxTime, uint32_t node, uint32_t dev);
146
147 /**
148 * \brief Return the communicator used to run ns-3.
149 *
150 * The communicator returned will be MPI_COMM_WORLD if Enable (int*
151 * pargc, char*** pargv) is used to enable or the user specified
152 * communicator if Enable (MPI_Comm communicator) is used.
153 *
154 * \return The MPI Communicator.
155 */
156 static MPI_Comm GetCommunicator();
157
158 private:
159 /**
160 * Common enable logic.
161 */
162 static void SetParallelSimulatorImpl();
163
164 /**
165 * Static instance of the instantiated parallel controller.
166 */
168};
169
170} // namespace ns3
171
172#endif /* NS3_MPI_INTERFACE_H */
Singleton used to interface to the communications infrastructure when running NS3 in parallel.
Definition: mpi-interface.h:63
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.
Pure virtual base class for the interface between ns-3 and the parallel communication layer being use...
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Every class exported by the ns3 library is enclosed in the ns3 namespace.