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 // ***********************************************************************
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 
58 namespace Zoltan2{
59 
61 template <typename scalar_t>
63 
64 private:
66 void 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 
73 std::string metricName_;
74 
78 ArrayRCP<scalar_t> values_;
79 
80 protected:
81 
83 scalar_t getValue(int enumIndex) const { return values_[enumIndex]; }
84 
86 void setValue(int enumIndex, scalar_t value) { values_[enumIndex] = value; }
87 
88 public:
89 
92  metricName_(METRICS_UNSET_STRING), values_() {
93 }
94 
96 BaseClassMetrics(int memCount, std::string mname) :
97  metricName_(mname), values_() {
98  resetValues(memCount);
99 }
100 
102 BaseClassMetrics(int memCount) :
103  metricName_(METRICS_UNSET_STRING), values_() {
104  resetValues(memCount);
105 }
106 
108 virtual ~BaseClassMetrics() {}
109 
113 virtual void printLine(std::ostream &os) const {};
114 
118 virtual const std::vector<std::string> & getMetrics() const
119  { return static_metricNames_; }
120 
122 virtual const std::string & getMetricType() const
124 
126 const std::string &getName() const { return metricName_; }
127 
129 void setName(std::string name) { metricName_ = name;}
130 
132 bool hasMetricValue(const std::string & metric_name) const {
133  return( convertMetricNameToIndex( metric_name ) != getMetrics().size() );
134 }
135 
137 scalar_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 
146 void 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 
154 size_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 
171 static std::vector<std::string> static_metricNames_;
172 
176 static std::vector<std::string> static_allMetricNames_;
177 };
178 
183 template <typename scalar_t>
186 
190 template <typename scalar_t>
191 std::vector<std::string> BaseClassMetrics<scalar_t>::static_metricNames_ = {};
192 
193 } // namespace Zoltan2
194 #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