mtp, mpi: Fix clang-tidy warnings

This commit is contained in:
F5
2023-11-22 16:11:42 +08:00
parent b3fdcbc6bd
commit 2f84697f6b
9 changed files with 154 additions and 130 deletions

View File

@@ -52,15 +52,16 @@ class Distribution
{
public:
// load a distribution from a CDF file
Distribution(string filename = "src/mtp/examples/web-search.txt")
Distribution(const string filename)
{
ifstream fin;
fin.open(filename);
while (!fin.eof())
{
double x, cdf;
double x;
double cdf;
fin >> x >> cdf;
m_cdf.push_back(std::make_pair(x, cdf));
m_cdf.emplace_back(x, cdf);
}
fin.close();
@@ -68,7 +69,7 @@ class Distribution
}
// expectation value of the distribution
double Expectation()
double Expectation() const
{
double ex = 0;
for (uint32_t i = 1; i < m_cdf.size(); i++)
@@ -106,22 +107,20 @@ class Distribution
class TrafficGenerator
{
public:
TrafficGenerator(string cdfFile,
uint32_t hostTotal,
double dataRate,
double incastRatio,
vector<uint32_t> victims)
TrafficGenerator(const string cdfFile,
const uint32_t hostTotal,
const double dataRate,
const double incastRatio,
const vector<uint32_t> victims)
: m_currentTime(0),
m_incastRatio(incastRatio),
m_hostTotal(hostTotal),
m_victims(victims),
m_flowCount(0),
m_flowSizeTotal(0),
m_distribution(cdfFile)
{
m_distribution = Distribution(cdfFile);
m_currentTime = 0;
m_averageInterval = m_distribution.Expectation() * 8 / dataRate;
m_incastRatio = incastRatio;
m_hostTotal = hostTotal;
m_victims = victims;
m_flowCount = 0;
m_flowSizeTotal = 0;
m_uniformRand = CreateObject<UniformRandomVariable>();
m_expRand = CreateObject<ExponentialRandomVariable>();
}
@@ -129,7 +128,8 @@ class TrafficGenerator
// get one flow with incremental time and random src, dst and size
tuple<double, uint32_t, uint32_t, uint32_t> GetFlow()
{
uint32_t src, dst;
uint32_t src;
uint32_t dst;
if (m_uniformRand->GetValue(0, 1) < m_incastRatio)
{
dst = m_victims[m_uniformRand->GetInteger(0, m_victims.size() - 1)];
@@ -151,22 +151,22 @@ class TrafficGenerator
return make_tuple(m_currentTime, src, dst, flowSize);
}
double GetActualDataRate()
double GetActualDataRate() const
{
return m_flowSizeTotal / m_currentTime * 8;
}
double GetAvgFlowSize()
double GetAvgFlowSize() const
{
return m_distribution.Expectation();
}
double GetActualAvgFlowSize()
double GetActualAvgFlowSize() const
{
return m_flowSizeTotal / (double)m_flowCount;
}
uint32_t GetFlowCount()
uint32_t GetFlowCount() const
{
return m_flowCount;
}
@@ -463,10 +463,17 @@ StartSimulation()
uint64_t eventCount = Simulator::GetEventCount();
if (conf::flowmon)
{
uint64_t dropped = 0, totalTx = 0, totalRx = 0, totalTxBytes = 0, flowCount = 0,
finishedFlowCount = 0;
uint64_t dropped = 0;
uint64_t totalTx = 0;
uint64_t totalRx = 0;
uint64_t totalTxBytes = 0;
uint64_t flowCount = 0;
uint64_t finishedFlowCount = 0;
double totalThroughput = 0;
Time totalFct(0), totalFinishedFct(0), totalDelay(0);
Time totalFct(0);
Time totalFinishedFct(0);
Time totalDelay(0);
flowMonitor->CheckForLostPackets();
for (auto& p : flowMonitor->GetFlowStats())
{
@@ -490,6 +497,7 @@ StartSimulation()
flowCount++;
}
}
double avgFct = (double)totalFct.GetMicroSeconds() / flowCount;
double avgFinishedFct = (double)totalFinishedFct.GetMicroSeconds() / finishedFlowCount;
double avgDelay = (double)totalDelay.GetMicroSeconds() / totalRx;
@@ -542,7 +550,10 @@ main(int argc, char* argv[])
uint32_t nAgg = conf::k / 2; // number of aggregation switch in a pod
uint32_t nEdge = conf::k / 2; // number of edge switch in a pod
uint32_t nHost = conf::k / 2; // number of hosts under a switch
NodeContainer core[nGroup], agg[nPod], edge[nPod], host[nPod][nEdge];
NodeContainer core[nGroup];
NodeContainer agg[nPod];
NodeContainer edge[nPod];
NodeContainer host[nPod][nEdge];
// create nodes
for (uint32_t i = 0; i < nGroup; i++)

View File

@@ -51,15 +51,16 @@ class Distribution
{
public:
// load a distribution from a CDF file
Distribution(string filename = "src/mtp/examples/web-search.txt")
Distribution(const string filename)
{
ifstream fin;
fin.open(filename);
while (!fin.eof())
{
double x, cdf;
double x;
double cdf;
fin >> x >> cdf;
m_cdf.push_back(std::make_pair(x, cdf));
m_cdf.emplace_back(x, cdf);
}
fin.close();
@@ -67,7 +68,7 @@ class Distribution
}
// expectation value of the distribution
double Expectation()
double Expectation() const
{
double ex = 0;
for (uint32_t i = 1; i < m_cdf.size(); i++)
@@ -105,22 +106,20 @@ class Distribution
class TrafficGenerator
{
public:
TrafficGenerator(string cdfFile,
uint32_t hostTotal,
double dataRate,
double incastRatio,
vector<uint32_t> victims)
TrafficGenerator(const string cdfFile,
const uint32_t hostTotal,
const double dataRate,
const double incastRatio,
const vector<uint32_t> victims)
: m_currentTime(0),
m_incastRatio(incastRatio),
m_hostTotal(hostTotal),
m_victims(victims),
m_flowCount(0),
m_flowSizeTotal(0),
m_distribution(cdfFile)
{
m_distribution = Distribution(cdfFile);
m_currentTime = 0;
m_averageInterval = m_distribution.Expectation() * 8 / dataRate;
m_incastRatio = incastRatio;
m_hostTotal = hostTotal;
m_victims = victims;
m_flowCount = 0;
m_flowSizeTotal = 0;
m_uniformRand = CreateObject<UniformRandomVariable>();
m_expRand = CreateObject<ExponentialRandomVariable>();
}
@@ -128,7 +127,8 @@ class TrafficGenerator
// get one flow with incremental time and random src, dst and size
tuple<double, uint32_t, uint32_t, uint32_t> GetFlow()
{
uint32_t src, dst;
uint32_t src;
uint32_t dst;
if (m_uniformRand->GetValue(0, 1) < m_incastRatio)
{
dst = m_victims[m_uniformRand->GetInteger(0, m_victims.size() - 1)];
@@ -150,22 +150,22 @@ class TrafficGenerator
return make_tuple(m_currentTime, src, dst, flowSize);
}
double GetActualDataRate()
double GetActualDataRate() const
{
return m_flowSizeTotal / m_currentTime * 8;
}
double GetAvgFlowSize()
double GetAvgFlowSize() const
{
return m_distribution.Expectation();
}
double GetActualAvgFlowSize()
double GetActualAvgFlowSize() const
{
return m_flowSizeTotal / (double)m_flowCount;
}
uint32_t GetFlowCount()
uint32_t GetFlowCount() const
{
return m_flowCount;
}
@@ -467,10 +467,17 @@ StartSimulation()
uint64_t eventCount = Simulator::GetEventCount();
if (conf::flowmon)
{
uint64_t dropped = 0, totalTx = 0, totalRx = 0, totalTxBytes = 0, flowCount = 0,
finishedFlowCount = 0;
uint64_t dropped = 0;
uint64_t totalTx = 0;
uint64_t totalRx = 0;
uint64_t totalTxBytes = 0;
uint64_t flowCount = 0;
uint64_t finishedFlowCount = 0;
double totalThroughput = 0;
Time totalFct(0), totalFinishedFct(0), totalDelay(0);
Time totalFct(0);
Time totalFinishedFct(0);
Time totalDelay(0);
flowMonitor->CheckForLostPackets();
for (auto& p : flowMonitor->GetFlowStats())
{
@@ -494,6 +501,7 @@ StartSimulation()
flowCount++;
}
}
double avgFct = (double)totalFct.GetMicroSeconds() / flowCount;
double avgFinishedFct = (double)totalFinishedFct.GetMicroSeconds() / finishedFlowCount;
double avgDelay = (double)totalDelay.GetMicroSeconds() / totalRx;
@@ -546,7 +554,10 @@ main(int argc, char* argv[])
uint32_t nAgg = conf::k / 2; // number of aggregation switch in a pod
uint32_t nEdge = conf::k / 2; // number of edge switch in a pod
uint32_t nHost = conf::k / 2; // number of hosts under a switch
NodeContainer core[nGroup], agg[nPod], edge[nPod], host[nPod][nEdge];
NodeContainer core[nGroup];
NodeContainer agg[nPod];
NodeContainer edge[nPod];
NodeContainer host[nPod][nEdge];
// create nodes
for (uint32_t i = 0; i < nGroup; i++)

View File

@@ -225,7 +225,8 @@ GrantedTimeWindowMpiInterface::SendPacket(Ptr<Packet> p,
#ifdef NS3_MTP
while (g_sending.exchange(true, std::memory_order_acquire))
;
{
};
#endif
SentBuffer sendBuf;

View File

@@ -178,8 +178,7 @@ HybridSimulatorImpl::Remove(const EventId& id)
if (id.GetUid() == EventId::DESTROY)
{
// destroy events.
for (std::list<EventId>::iterator i = m_destroyEvents.begin(); i != m_destroyEvents.end();
i++)
for (auto i = m_destroyEvents.begin(); i != m_destroyEvents.end(); i++)
{
if (*i == id)
{
@@ -209,13 +208,11 @@ HybridSimulatorImpl::IsExpired(const EventId& id) const
if (id.GetUid() == EventId::DESTROY)
{
// destroy events.
if (id.PeekEventImpl() == 0 || id.PeekEventImpl()->IsCancelled())
if (id.PeekEventImpl() == nullptr || id.PeekEventImpl()->IsCancelled())
{
return true;
}
for (std::list<EventId>::const_iterator i = m_destroyEvents.begin();
i != m_destroyEvents.end();
i++)
for (auto i = m_destroyEvents.begin(); i != m_destroyEvents.end(); i++)
{
if (*i == id)
{
@@ -374,7 +371,7 @@ HybridSimulatorImpl::Partition()
if (m_minLookahead == TimeStep(0))
{
std::vector<Time> delays;
for (NodeContainer::Iterator it = nodes.Begin(); it != nodes.End(); it++)
for (auto it = nodes.Begin(); it != nodes.End(); it++)
{
Ptr<Node> node = *it;
if (node->GetSystemId() == m_myId)
@@ -398,7 +395,7 @@ HybridSimulatorImpl::Partition()
}
}
std::sort(delays.begin(), delays.end());
if (delays.size() == 0)
if (delays.empty())
{
m_minLookahead = TimeStep(0);
}
@@ -414,7 +411,7 @@ HybridSimulatorImpl::Partition()
}
// perform a BFS on the whole network topo to assign each node a localSystemId
for (NodeContainer::Iterator it = nodes.Begin(); it != nodes.End(); it++)
for (auto it = nodes.Begin(); it != nodes.End(); it++)
{
Ptr<Node> node = *it;
if (!visited[node->GetId()] && node->GetSystemId() == m_myId)

View File

@@ -49,15 +49,16 @@ class Distribution
{
public:
// load a distribution from a CDF file
Distribution(string filename = "src/mtp/examples/web-search.txt")
Distribution(const string filename)
{
ifstream fin;
fin.open(filename);
while (!fin.eof())
{
double x, cdf;
double x;
double cdf;
fin >> x >> cdf;
m_cdf.push_back(std::make_pair(x, cdf));
m_cdf.emplace_back(x, cdf);
}
fin.close();
@@ -65,7 +66,7 @@ class Distribution
}
// expectation value of the distribution
double Expectation()
double Expectation() const
{
double ex = 0;
for (uint32_t i = 1; i < m_cdf.size(); i++)
@@ -103,22 +104,20 @@ class Distribution
class TrafficGenerator
{
public:
TrafficGenerator(string cdfFile,
uint32_t hostTotal,
double dataRate,
double incastRatio,
vector<uint32_t> victims)
TrafficGenerator(const string cdfFile,
const uint32_t hostTotal,
const double dataRate,
const double incastRatio,
const vector<uint32_t> victims)
: m_currentTime(0),
m_incastRatio(incastRatio),
m_hostTotal(hostTotal),
m_victims(victims),
m_flowCount(0),
m_flowSizeTotal(0),
m_distribution(cdfFile)
{
m_distribution = Distribution(cdfFile);
m_currentTime = 0;
m_averageInterval = m_distribution.Expectation() * 8 / dataRate;
m_incastRatio = incastRatio;
m_hostTotal = hostTotal;
m_victims = victims;
m_flowCount = 0;
m_flowSizeTotal = 0;
m_uniformRand = CreateObject<UniformRandomVariable>();
m_expRand = CreateObject<ExponentialRandomVariable>();
}
@@ -126,7 +125,8 @@ class TrafficGenerator
// get one flow with incremental time and random src, dst and size
tuple<double, uint32_t, uint32_t, uint32_t> GetFlow()
{
uint32_t src, dst;
uint32_t src;
uint32_t dst;
if (m_uniformRand->GetValue(0, 1) < m_incastRatio)
{
dst = m_victims[m_uniformRand->GetInteger(0, m_victims.size() - 1)];
@@ -148,22 +148,22 @@ class TrafficGenerator
return make_tuple(m_currentTime, src, dst, flowSize);
}
double GetActualDataRate()
double GetActualDataRate() const
{
return m_flowSizeTotal / m_currentTime * 8;
}
double GetAvgFlowSize()
double GetAvgFlowSize() const
{
return m_distribution.Expectation();
}
double GetActualAvgFlowSize()
double GetActualAvgFlowSize() const
{
return m_flowSizeTotal / (double)m_flowCount;
}
uint32_t GetFlowCount()
uint32_t GetFlowCount() const
{
return m_flowCount;
}
@@ -443,10 +443,17 @@ StartSimulation()
uint64_t eventCount = Simulator::GetEventCount();
if (conf::flowmon)
{
uint64_t dropped = 0, totalTx = 0, totalRx = 0, totalTxBytes = 0, flowCount = 0,
finishedFlowCount = 0;
uint64_t dropped = 0;
uint64_t totalTx = 0;
uint64_t totalRx = 0;
uint64_t totalTxBytes = 0;
uint64_t flowCount = 0;
uint64_t finishedFlowCount = 0;
double totalThroughput = 0;
Time totalFct(0), totalFinishedFct(0), totalDelay(0);
Time totalFct(0);
Time totalFinishedFct(0);
Time totalDelay(0);
flowMonitor->CheckForLostPackets();
for (auto& p : flowMonitor->GetFlowStats())
{
@@ -470,6 +477,7 @@ StartSimulation()
flowCount++;
}
}
double avgFct = (double)totalFct.GetMicroSeconds() / flowCount;
double avgFinishedFct = (double)totalFinishedFct.GetMicroSeconds() / finishedFlowCount;
double avgDelay = (double)totalDelay.GetMicroSeconds() / totalRx;
@@ -508,7 +516,10 @@ main(int argc, char* argv[])
uint32_t nAgg = conf::k / 2; // number of aggregation switch in a pod
uint32_t nEdge = conf::k / 2; // number of edge switch in a pod
uint32_t nHost = conf::k / 2; // number of hosts under a switch
NodeContainer core[nGroup], agg[nPod], edge[nPod], host[nPod][nEdge];
NodeContainer core[nGroup];
NodeContainer agg[nPod];
NodeContainer edge[nPod];
NodeContainer host[nPod][nEdge];
// create nodes
for (uint32_t i = 0; i < nGroup; i++)

View File

@@ -33,18 +33,18 @@ namespace ns3
NS_LOG_COMPONENT_DEFINE("LogicalProcess");
LogicalProcess::LogicalProcess()
: m_systemId(0),
m_systemCount(0),
m_stop(false),
m_uid(EventId::UID::VALID),
m_currentContext(Simulator::NO_CONTEXT),
m_currentUid(0),
m_currentTs(0),
m_eventCount(0),
m_pendingEventCount(0),
m_events(nullptr),
m_lookAhead(TimeStep(0))
{
m_systemId = 0;
m_systemCount = 0;
m_uid = EventId::UID::VALID;
m_stop = false;
m_currentContext = Simulator::NO_CONTEXT;
m_currentUid = 0;
m_currentTs = 0;
m_eventCount = 0;
m_pendingEventCount = 0;
m_events = 0;
m_lookAhead = TimeStep(0);
}
LogicalProcess::~LogicalProcess()
@@ -82,7 +82,7 @@ LogicalProcess::CalculateLookAhead()
{
m_lookAhead = Time::Max() / 2 - TimeStep(1);
NodeContainer c = NodeContainer::GetGlobal();
for (NodeContainer::Iterator iter = c.Begin(); iter != c.End(); ++iter)
for (auto iter = c.Begin(); iter != c.End(); ++iter)
{
#ifdef NS3_MPI
if (((*iter)->GetSystemId() >> 16) != m_systemId)
@@ -241,8 +241,7 @@ LogicalProcess::ScheduleWithContext(LogicalProcess* remote,
else
{
ev.key.m_uid = EventId::UID::INVALID;
remote->m_mailbox[m_systemId].push_back(
std::make_tuple(m_currentTs, m_systemId, m_uid, ev));
remote->m_mailbox[m_systemId].emplace_back(m_currentTs, m_systemId, m_uid, ev);
}
}
@@ -288,16 +287,9 @@ LogicalProcess::Remove(const EventId& id)
bool
LogicalProcess::IsExpired(const EventId& id) const
{
if (id.PeekEventImpl() == 0 || id.GetTs() < m_currentTs ||
(id.GetTs() == m_currentTs && id.GetUid() <= m_currentUid) ||
id.PeekEventImpl()->IsCancelled())
{
return true;
}
else
{
return false;
}
return id.PeekEventImpl() == nullptr || id.GetTs() < m_currentTs ||
(id.GetTs() == m_currentTs && id.GetUid() <= m_currentUid) ||
id.PeekEventImpl()->IsCancelled();
}
void

View File

@@ -233,7 +233,8 @@ MtpInterface::ProcessOneRound()
// logical process barriar synchronization
while (g_finishedSystemCount.load(std::memory_order_acquire) != g_systemCount)
;
{
};
// stage 2: process the public LP
g_systems[0].ProcessOneRound();
@@ -256,7 +257,8 @@ MtpInterface::ProcessOneRound()
// logical process barriar synchronization
while (g_finishedSystemCount.load(std::memory_order_acquire) != g_systemCount)
;
{
};
}
void
@@ -324,7 +326,8 @@ MtpInterface::ThreadFunc(void* arg)
if (index >= g_systemCount)
{
while (g_systemIndex.load(std::memory_order_acquire) >= g_systemCount)
;
{
};
continue;
}
LogicalProcess* system = &g_systems[g_sortedSystemIndices[index]];