A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
mpi-test-fixtures.h
Go to the documentation of this file.
1
/*
2
* Copyright 2018. 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
#ifndef MPI_TEST_FIXTURES_H
21
#define MPI_TEST_FIXTURES_H
22
23
#include <iomanip>
24
#include <ios>
25
#include <sstream>
26
27
/**
28
* \file
29
* \ingroup mpi
30
*
31
* Common methods for MPI examples.
32
*
33
* Since MPI output is coming from multiple processors it is the
34
* ordering between the processors is non-deterministic. For
35
* regression testing the output is sorted to force a deterministic
36
* ordering. Methods include here add line number to support
37
* this sorting.
38
*
39
* Testing output is also grepped so only lines with "TEST" are
40
* included. Some MPI launchers emit extra text to output which must
41
* be excluded for regression comparisons.
42
*/
43
44
namespace
ns3
45
{
46
47
template
<
typename
T>
48
class
Ptr;
49
class
Address;
50
class
Packet;
51
52
/**
53
* \ingroup mpi
54
*
55
* Write to std::cout only from rank 0.
56
* Number line for sorting output of parallel runs.
57
*
58
* \param x The output operators.
59
*/
60
#define RANK0COUT(x) \
61
do \
62
if (SinkTracer::GetWorldRank() == 0) \
63
{ \
64
std::cout << "TEST : "
; \
65
std::ios_base::fmtflags f(std::cout.flags()); \
66
std::cout << std::setfill('0') << std::setw(5) << SinkTracer::GetLineCount(); \
67
std::cout.flags(f); \
68
std::cout << " : " << x; \
69
} \
70
while (false)
71
72
/**
73
* \ingroup mpi
74
*
75
* Append to std::cout only from rank 0.
76
* Number line for sorting output of parallel runs.
77
*
78
* \param x The output operators.
79
*/
80
#define RANK0COUTAPPEND(x) \
81
do \
82
if (SinkTracer::GetWorldRank() == 0) \
83
{ \
84
std::cout << x; \
85
} \
86
while (false)
87
88
/**
89
* \ingroup mpi
90
*
91
* Collects data about incoming packets.
92
*/
93
class
SinkTracer
94
{
95
public
:
96
/**
97
* PacketSink Init.
98
*/
99
static
void
Init
();
100
101
/**
102
* PacketSink receive trace callback.
103
* \copydetails ns3::Packet::TwoAddressTracedCallback
104
*/
105
static
void
SinkTrace
(
const
ns3::Ptr<const ns3::Packet>
packet,
106
const
ns3::Address
& srcAddress,
107
const
ns3::Address
& destAddress);
108
109
/**
110
* Verify the sink trace count observed matches the expected count.
111
* Prints message to std::cout indicating success or fail.
112
*
113
* \param expectedCount Expected number of packet received.
114
*/
115
static
void
Verify
(
unsigned
long
expectedCount);
116
117
/**
118
* Get the source address and port, as a formatted string.
119
*
120
* \param [in] address The ns3::Address.
121
* \return A string with the formatted address and port number.
122
*/
123
static
std::string
FormatAddress
(
const
ns3::Address
address);
124
125
/**
126
* Get the MPI rank in the world communicator.
127
*
128
* \return MPI world rank.
129
*/
130
static
int
GetWorldRank
()
131
{
132
return
m_worldRank
;
133
}
134
135
/**
136
* Get the MPI size of the world communicator.
137
*
138
* \return MPI world size.
139
*/
140
static
int
GetWorldSize
()
141
{
142
return
m_worldSize
;
143
}
144
145
/**
146
* Get current line count and increment it.
147
* \return the line count.
148
*/
149
static
int
GetLineCount
()
150
{
151
return
m_line
++;
152
}
153
154
private
:
155
static
unsigned
long
m_sinkCount
;
//!< Running sum of number of SinkTrace calls observed
156
static
unsigned
long
m_line
;
//!< Current output line number for ordering output
157
static
int
m_worldRank
;
//!< MPI CommWorld rank
158
static
int
m_worldSize
;
//!< MPI CommWorld size
159
};
160
161
}
// namespace ns3
162
163
#endif
// MPI_TEST_FIXTURES_H
ns3::Address
a polymophic address class
Definition:
address.h:101
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:77
ns3::SinkTracer
Collects data about incoming packets.
Definition:
mpi-test-fixtures.h:94
ns3::SinkTracer::SinkTrace
static void SinkTrace(const ns3::Ptr< const ns3::Packet > packet, const ns3::Address &srcAddress, const ns3::Address &destAddress)
PacketSink receive trace callback.
Definition:
mpi-test-fixtures.cc:49
ns3::SinkTracer::m_worldRank
static int m_worldRank
MPI CommWorld rank.
Definition:
mpi-test-fixtures.h:157
ns3::SinkTracer::Verify
static void Verify(unsigned long expectedCount)
Verify the sink trace count observed matches the expected count.
Definition:
mpi-test-fixtures.cc:57
ns3::SinkTracer::m_worldSize
static int m_worldSize
MPI CommWorld size.
Definition:
mpi-test-fixtures.h:158
ns3::SinkTracer::m_line
static unsigned long m_line
Current output line number for ordering output.
Definition:
mpi-test-fixtures.h:156
ns3::SinkTracer::Init
static void Init()
PacketSink Init.
Definition:
mpi-test-fixtures.cc:40
ns3::SinkTracer::GetWorldSize
static int GetWorldSize()
Get the MPI size of the world communicator.
Definition:
mpi-test-fixtures.h:140
ns3::SinkTracer::GetLineCount
static int GetLineCount()
Get current line count and increment it.
Definition:
mpi-test-fixtures.h:149
ns3::SinkTracer::GetWorldRank
static int GetWorldRank()
Get the MPI rank in the world communicator.
Definition:
mpi-test-fixtures.h:130
ns3::SinkTracer::m_sinkCount
static unsigned long m_sinkCount
Running sum of number of SinkTrace calls observed.
Definition:
mpi-test-fixtures.h:155
ns3::SinkTracer::FormatAddress
static std::string FormatAddress(const ns3::Address address)
Get the source address and port, as a formatted string.
Definition:
mpi-test-fixtures.cc:79
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
mpi
examples
mpi-test-fixtures.h
Generated on Tue May 28 2024 23:38:21 for ns-3 by
1.9.6