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