A Discrete-Event Network Simulator
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
33namespace ns3
34{
35
36template <typename T>
37class Ptr;
38class Address;
39class 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 */
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
a polymophic address class
Definition address.h:90
network packets
Definition packet.h:228
Smart pointer class similar to boost::intrusive_ptr.
Collects data about incoming packets.
static void SinkTrace(const ns3::Ptr< const ns3::Packet > packet, const ns3::Address &srcAddress, const ns3::Address &destAddress)
PacketSink receive trace callback.
static int m_worldRank
MPI CommWorld rank.
static void Verify(unsigned long expectedCount)
Verify the sink trace count observed matches the expected count.
static int m_worldSize
MPI CommWorld size.
static unsigned long m_line
Current output line number for ordering output.
static void Init()
PacketSink Init.
static int GetWorldSize()
Get the MPI size of the world communicator.
static int GetLineCount()
Get current line count and increment it.
static int GetWorldRank()
Get the MPI rank in the world communicator.
static unsigned long m_sinkCount
Running sum of number of SinkTrace calls observed.
static std::string FormatAddress(const ns3::Address address)
Get the source address and port, as a formatted string.
Every class exported by the ns3 library is enclosed in the ns3 namespace.