Zoltan2
Loading...
Searching...
No Matches
Zoltan2_ImbalanceMetrics.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Zoltan2: A package of combinatorial algorithms for scientific computing
4//
5// Copyright 2012 NTESS and the Zoltan2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
13#ifndef ZOLTAN2_IMBALANCEMETRICS_HPP
14#define ZOLTAN2_IMBALANCEMETRICS_HPP
15
19
20#define IMBALANCE_METRICS_TYPE_NAME "ImbalanceMetrics"
21
22namespace Zoltan2{
23
25template <typename scalar_t>
26 class ImbalanceMetrics : public BaseClassMetrics<scalar_t> {
27
28private:
29 multiCriteriaNorm mcnorm_; // store "actualNorm + 1"
30
31public:
33ImbalanceMetrics(std::string mname) : BaseClassMetrics<scalar_t>(static_metricNames_.size(), mname),mcnorm_(multiCriteriaNorm(0)) {}
34
37
39virtual const std::string & getMetricType() const { return static_metricTypeName_; }
40
42static void printHeader(std::ostream &os);
43
45virtual void printLine(std::ostream &os) const;
46
48void setNorm(multiCriteriaNorm normVal) { mcnorm_ = multiCriteriaNorm(normVal+1);}
49
52
54void setLocalSum(scalar_t x) { this->setMetricValue("local sum", x);}
55
57void setGlobalSum(scalar_t x) { this->setMetricValue("global sum", x );}
58
60void setGlobalMin(scalar_t x) { this->setMetricValue("global minimum", x );}
61
63void setGlobalMax(scalar_t x) { this->setMetricValue("global maximum", x );}
64
66void setMaxImbalance(scalar_t x) { this->setMetricValue("maximum imbalance", x);}
67
69void setAvgImbalance(scalar_t x) { this->setMetricValue("average imbalance", x);}
70
72scalar_t getLocalSum() const { return this->getMetricValue("local sum");}
73
75scalar_t getGlobalSum() const { return this->getMetricValue("global sum");}
76
78scalar_t getGlobalMin() const { return this->getMetricValue("global minimum");}
79
81scalar_t getGlobalMax() const { return this->getMetricValue("global maximum");}
82
86scalar_t getMaxImbalance() const { return this->getMetricValue("maximum imbalance");}
87
89scalar_t getAvgImbalance() const { return this->getMetricValue("average imbalance");}
90
92virtual const std::vector<std::string> & getMetrics() const { return ImbalanceMetrics<scalar_t>::static_metricNames_; }
93
95static std::string static_metricTypeName_;
96
98static std::vector<std::string> static_metricNames_;
99}; // end class
100
103
105template <typename scalar_t>
106std::vector<std::string> ImbalanceMetrics<scalar_t>::static_metricNames_ = {
107 "local sum",
108 "global sum",
109 "global minimum",
110 "global maximum",
111 "global average",
112 "average imbalance",
113 "maximum imbalance",
114};
115
116template <typename scalar_t>
118{
119 os << std::setw(20) << " ";
120 os << std::setw(15) << "min" << std::setw(15) << "max" << std::setw(15) << "avg";
121 os << std::setw(2) << " ";
122 os << std::setw(10) << "imbalance";
123 os << std::endl;
124}
125
126template <typename scalar_t>
127 void ImbalanceMetrics<scalar_t>::printLine(std::ostream &os) const
128{
129 std::string label( this->getName() );
130 if (mcnorm_ > 0){
131 multiCriteriaNorm realNorm = multiCriteriaNorm(mcnorm_ - 1);
132 std::ostringstream oss;
133 switch (realNorm) {
134 case normMinimizeTotalWeight: // 1-norm = Manhattan norm
135 oss << this->getName() << " (1)";
136 break;
137 case normBalanceTotalMaximum: // 2-norm = sqrt of sum of squares
138 oss << this->getName() << " (2)";
139 break;
140 case normMinimizeMaximumWeight: // inf-norm = maximum norm
141 oss << this->getName() << " (inf)";
142 break;
143 default:
144 oss << this->getName() << " (?)";
145 break;
146 }
147
148 label = oss.str();
149 }
150
151 auto min = this->getMetricValue("global minimum");
152 auto max = this->getMetricValue("global maximum");
153 auto avg = this->getMetricValue("global average");
154 int precision = 4;
155 if( min > 999 ) { precision = 0; }
156 else if( min > 99 ) { precision = 2; }
157
158 os << std::setw(20) << label;
159 os << std::setw(15) << std::setprecision(precision) << min;
160 os << std::setw(15) << std::setprecision(precision) << max;
161 os << std::setw(15) << std::setprecision(precision) << avg;
162
163 os << std::setw(2) << " ";
164 os << std::setw(10) << std::setprecision(4)
165 << this->getMetricValue("maximum imbalance");
166
167 os << std::endl;
168}
169} // namespace Zoltan2
170#endif
Defines the GraphModel interface.
#define IMBALANCE_METRICS_TYPE_NAME
void setMetricValue(const std::string &metric_name, scalar_t value) const
scalar_t getMetricValue(const std::string &metric_name) const
scalar_t getMaxImbalance() const
Get the imbalance of the most imbalanced part. This is what we normally call the imbalance of a parti...
virtual const std::vector< std::string > & getMetrics() const
multiCriteriaNorm getNorm()
Get the norm.
virtual const std::string & getMetricType() const
Get the class type of the metric.
scalar_t getGlobalSum() const
Get the global sum for all parts.
void setGlobalMax(scalar_t x)
Set the global maximum across parts.
scalar_t getAvgImbalance() const
Get the average of the part imbalances.
void setGlobalSum(scalar_t x)
Set the global sum.
void setNorm(multiCriteriaNorm normVal)
Set or reset the norm.
void setGlobalMin(scalar_t x)
Set the global minimum across parts.
void setLocalSum(scalar_t x)
Set the sum on the local process.
ImbalanceMetrics(std::string mname)
Constructor.
scalar_t getGlobalMax() const
Get the global maximum across all parts.
void setMaxImbalance(scalar_t x)
Set the imbalance of the worst imbalanced part. This is what we normally call the imbalance of a part...
void setAvgImbalance(scalar_t x)
Set the average imbalance of all parts.
scalar_t getLocalSum() const
Get the sum on the local process.
static void printHeader(std::ostream &os)
Print a standard header.
virtual void printLine(std::ostream &os) const
Print a standard line of data that fits under the header.
static std::vector< std::string > static_metricNames_
scalar_t getGlobalMin() const
Get the global minimum across all parts.
Created by mbenlioglu on Aug 31, 2020.
multiCriteriaNorm
Enumerator used in code for multicriteria norm choice.