Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_BaseClassMetrics.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 
14 #ifndef ZOLTAN2_BASEMETRICVALUES_HPP
15 #define ZOLTAN2_BASEMETRICVALUES_HPP
16 
17 #include <Zoltan2_Standards.hpp>
18 
19 #define UNKNOWN_METRICS_TYPE_NAME "UnknownMetricClass" // Unknown would be error
20 #define METRICS_UNSET_STRING "unset"
21 
22 namespace Zoltan2{
23 
25 template <typename scalar_t>
27 
28 private:
30 void resetValues( int memCount ){
31  scalar_t *tmp = new scalar_t [memCount];
32  memset(tmp, 0, sizeof(scalar_t) * memCount);
33  values_ = arcp(tmp, 0, memCount, true);
34 }
35 
37 std::string metricName_;
38 
42 ArrayRCP<scalar_t> values_;
43 
44 protected:
45 
47 scalar_t getValue(int enumIndex) const { return values_[enumIndex]; }
48 
50 void setValue(int enumIndex, scalar_t value) { values_[enumIndex] = value; }
51 
52 public:
53 
56  metricName_(METRICS_UNSET_STRING), values_() {
57 }
58 
60 BaseClassMetrics(int memCount, std::string mname) :
61  metricName_(mname), values_() {
62  resetValues(memCount);
63 }
64 
66 BaseClassMetrics(int memCount) :
67  metricName_(METRICS_UNSET_STRING), values_() {
68  resetValues(memCount);
69 }
70 
72 virtual ~BaseClassMetrics() {}
73 
77 virtual void printLine(std::ostream &os) const {};
78 
82 virtual const std::vector<std::string> & getMetrics() const
83  { return static_metricNames_; }
84 
86 virtual const std::string & getMetricType() const
88 
90 const std::string &getName() const { return metricName_; }
91 
93 void setName(std::string name) { metricName_ = name;}
94 
96 bool hasMetricValue(const std::string & metric_name) const {
97  return( convertMetricNameToIndex( metric_name ) != getMetrics().size() );
98 }
99 
101 scalar_t getMetricValue(const std::string & metric_name) const
102 {
103  size_t metricIndex = convertMetricNameToIndex(metric_name);
104  if( metricIndex == getMetrics().size() )
105  return 0.0; // throw an error
106  return values_[metricIndex];
107 }
108 
110 void setMetricValue(const std::string & metric_name, scalar_t value) const
111 {
112  size_t metricIndex = convertMetricNameToIndex(metric_name);
113  if( metricIndex != getMetrics().size() )
114  values_[metricIndex] = value;
115 }
116 
118 size_t convertMetricNameToIndex(const std::string & metric_name) const
119 {
120  const std::vector<std::string> & metricNames = getMetrics();
121  size_t metricIndex = std::find(metricNames.begin(), metricNames.end(),
122  metric_name) - metricNames.begin();
123  return metricIndex; // this can return metricNames.size() if not found
124 }
125 
131 
135 static std::vector<std::string> static_metricNames_;
136 
140 static std::vector<std::string> static_allMetricNames_;
141 };
142 
147 template <typename scalar_t>
150 
154 template <typename scalar_t>
155 std::vector<std::string> BaseClassMetrics<scalar_t>::static_metricNames_ = {};
156 
157 } // namespace Zoltan2
158 #endif
virtual const std::string & getMetricType() const
Get the class type of the metric.
static std::vector< std::string > static_metricNames_
virtual void printLine(std::ostream &os) const
static std::string static_unknown_metricTypeName_
size_t convertMetricNameToIndex(const std::string &metric_name) const
BaseClassMetrics(int memCount, std::string mname)
Constructor.
void setName(std::string name)
Set or reset the name.
scalar_t getMetricValue(const std::string &metric_name) const
virtual const std::vector< std::string > & getMetrics() const
void setMetricValue(const std::string &metric_name, scalar_t value) const
void setValue(int enumIndex, scalar_t value)
BaseClassMetrics()
Constructor - for compiling but not used.
scalar_t getValue(int enumIndex) const
static std::vector< std::string > static_allMetricNames_
#define UNKNOWN_METRICS_TYPE_NAME
bool hasMetricValue(const std::string &metric_name) const
Gathering definitions used in software development.
const std::string & getName() const
Get the name of the item measured.
BaseClassMetrics(int memCount)
Constructor.
#define METRICS_UNSET_STRING