Zoltan2
Loading...
Searching...
No Matches
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
22namespace Zoltan2{
23
25template <typename scalar_t>
27
28private:
30void 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
37std::string metricName_;
38
42ArrayRCP<scalar_t> values_;
43
44protected:
45
47scalar_t getValue(int enumIndex) const { return values_[enumIndex]; }
48
50void setValue(int enumIndex, scalar_t value) { values_[enumIndex] = value; }
51
52public:
53
56 metricName_(METRICS_UNSET_STRING), values_() {
57}
58
60BaseClassMetrics(int memCount, std::string mname) :
61 metricName_(mname), values_() {
62 resetValues(memCount);
63}
64
66BaseClassMetrics(int memCount) :
67 metricName_(METRICS_UNSET_STRING), values_() {
68 resetValues(memCount);
69}
70
73
77virtual void printLine(std::ostream &os) const {};
78
82virtual const std::vector<std::string> & getMetrics() const
83 { return static_metricNames_; }
84
86virtual const std::string & getMetricType() const
88
90const std::string &getName() const { return metricName_; }
91
93void setName(std::string name) { metricName_ = name;}
94
96bool hasMetricValue(const std::string & metric_name) const {
97 return( convertMetricNameToIndex( metric_name ) != getMetrics().size() );
98}
99
101scalar_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
110void 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
118size_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
135static std::vector<std::string> static_metricNames_;
136
140static std::vector<std::string> static_allMetricNames_;
141};
142
147template <typename scalar_t>
150
154template <typename scalar_t>
155std::vector<std::string> BaseClassMetrics<scalar_t>::static_metricNames_ = {};
156
157} // namespace Zoltan2
158#endif
#define METRICS_UNSET_STRING
#define UNKNOWN_METRICS_TYPE_NAME
Gathering definitions used in software development.
void setMetricValue(const std::string &metric_name, scalar_t value) const
bool hasMetricValue(const std::string &metric_name) const
virtual const std::vector< std::string > & getMetrics() const
virtual void printLine(std::ostream &os) const
BaseClassMetrics(int memCount)
Constructor.
static std::vector< std::string > static_allMetricNames_
void setName(std::string name)
Set or reset the name.
void setValue(int enumIndex, scalar_t value)
size_t convertMetricNameToIndex(const std::string &metric_name) const
BaseClassMetrics(int memCount, std::string mname)
Constructor.
scalar_t getValue(int enumIndex) const
virtual const std::string & getMetricType() const
Get the class type of the metric.
scalar_t getMetricValue(const std::string &metric_name) const
static std::vector< std::string > static_metricNames_
BaseClassMetrics()
Constructor - for compiling but not used.
static std::string static_unknown_metricTypeName_
const std::string & getName() const
Get the name of the item measured.
Created by mbenlioglu on Aug 31, 2020.