Zoltan2
Loading...
Searching...
No Matches
Zoltan2_BaseClassMetrics.hpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// Zoltan2: A package of combinatorial algorithms for scientific computing
6// Copyright 2012 Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact Karen Devine (kddevin@sandia.gov)
39// Erik Boman (egboman@sandia.gov)
40// Siva Rajamanickam (srajama@sandia.gov)
41//
42// ***********************************************************************
43//
44// @HEADER
45
50#ifndef ZOLTAN2_BASEMETRICVALUES_HPP
51#define ZOLTAN2_BASEMETRICVALUES_HPP
52
53#include <Zoltan2_Standards.hpp>
54
55#define UNKNOWN_METRICS_TYPE_NAME "UnknownMetricClass" // Unknown would be error
56#define METRICS_UNSET_STRING "unset"
57
58namespace Zoltan2{
59
61template <typename scalar_t>
63
64private:
66void resetValues( int memCount ){
67 scalar_t *tmp = new scalar_t [memCount];
68 memset(tmp, 0, sizeof(scalar_t) * memCount);
69 values_ = arcp(tmp, 0, memCount, true);
70}
71
73std::string metricName_;
74
78ArrayRCP<scalar_t> values_;
79
80protected:
81
83scalar_t getValue(int enumIndex) const { return values_[enumIndex]; }
84
86void setValue(int enumIndex, scalar_t value) { values_[enumIndex] = value; }
87
88public:
89
92 metricName_(METRICS_UNSET_STRING), values_() {
93}
94
96BaseClassMetrics(int memCount, std::string mname) :
97 metricName_(mname), values_() {
98 resetValues(memCount);
99}
100
102BaseClassMetrics(int memCount) :
103 metricName_(METRICS_UNSET_STRING), values_() {
104 resetValues(memCount);
105}
106
109
113virtual void printLine(std::ostream &os) const {};
114
118virtual const std::vector<std::string> & getMetrics() const
119 { return static_metricNames_; }
120
122virtual const std::string & getMetricType() const
124
126const std::string &getName() const { return metricName_; }
127
129void setName(std::string name) { metricName_ = name;}
130
132bool hasMetricValue(const std::string & metric_name) const {
133 return( convertMetricNameToIndex( metric_name ) != getMetrics().size() );
134}
135
137scalar_t getMetricValue(const std::string & metric_name) const
138{
139 size_t metricIndex = convertMetricNameToIndex(metric_name);
140 if( metricIndex == getMetrics().size() )
141 return 0.0; // throw an error
142 return values_[metricIndex];
143}
144
146void setMetricValue(const std::string & metric_name, scalar_t value) const
147{
148 size_t metricIndex = convertMetricNameToIndex(metric_name);
149 if( metricIndex != getMetrics().size() )
150 values_[metricIndex] = value;
151}
152
154size_t convertMetricNameToIndex(const std::string & metric_name) const
155{
156 const std::vector<std::string> & metricNames = getMetrics();
157 size_t metricIndex = std::find(metricNames.begin(), metricNames.end(),
158 metric_name) - metricNames.begin();
159 return metricIndex; // this can return metricNames.size() if not found
160}
161
167
171static std::vector<std::string> static_metricNames_;
172
176static std::vector<std::string> static_allMetricNames_;
177};
178
183template <typename scalar_t>
186
190template <typename scalar_t>
191std::vector<std::string> BaseClassMetrics<scalar_t>::static_metricNames_ = {};
192
193} // namespace Zoltan2
194#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.