Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_GraphMetrics.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 
49 #ifndef ZOLTAN2_GRAPHCMETRICS_HPP
50 #define ZOLTAN2_GRAPHCMETRICS_HPP
51 
53 #include <Zoltan2_GraphModel.hpp>
55 
56 #define GRAPH_METRICS_TYPE_NAME "GraphMetrics"
57 
58 namespace Zoltan2{
59 
61 template <typename scalar_t>
62  class GraphMetrics : public BaseClassMetrics<scalar_t> {
63 
64 public:
66 GraphMetrics(std::string mname) : BaseClassMetrics<scalar_t>(static_metricNames_.size(), mname) {}
67 
70 
72 virtual const std::string & getMetricType() const { return GraphMetrics<scalar_t>::static_metricTypeName_; }
73 
75 static void printHeader(std::ostream &os);
76 
78 virtual void printLine(std::ostream &os) const;
79 
81 void setGlobalSum(scalar_t x) { this->setMetricValue("global sum", x);}
82 
84 void setGlobalMax(scalar_t x) { this->setValue("global maximum", x);}
85 
87 scalar_t getGlobalSum() const { return this->getMetricValue("global sum");}
88 
90 scalar_t getGlobalMax() const { return this->getMetricValue("global maximum");}
91 
93 virtual const std::vector<std::string> & getMetrics() const { return GraphMetrics<scalar_t>::static_metricNames_; }
94 
96 static std::vector<std::string> static_metricNames_;
97 
99 static std::string static_metricTypeName_;
100 }; // end class
101 
103 template <typename scalar_t>
105 
107 template <typename scalar_t>
108 std::vector<std::string> GraphMetrics<scalar_t>::static_metricNames_ = {
109  "global sum",
110  "global maximum"
111 };
112 
113 template <typename scalar_t>
114  void GraphMetrics<scalar_t>::printHeader(std::ostream &os)
115 {
116  os << std::setw(20) << " ";
117  os << std::setw(12) << "total" << std::setw(12) << "max";
118  os << std::endl;
119 }
120 
121 template <typename scalar_t>
122  void GraphMetrics<scalar_t>::printLine(std::ostream &os) const
123 {
124  std::string label( this->getName() );
125 
126  os << std::setw(20) << label;
127  os << std::setw(12) << std::setprecision(4) << this->getMetricValue("global sum");
128  os << std::setw(12) << std::setprecision(4) << this->getMetricValue("global maximum");
129 
130  os << std::endl;
131 }
132 
133 } //namespace Zoltan2
134 #endif
virtual const std::vector< std::string > & getMetrics() const
virtual void printLine(std::ostream &os) const
Print a standard line of data that fits under the header.
static void printHeader(std::ostream &os)
Print a standard header.
GraphMetrics(std::string mname)
Constructor.
virtual const std::string & getMetricType() const
Get the class type of the metric.
scalar_t getMetricValue(const std::string &metric_name) const
static std::string static_metricTypeName_
void setMetricValue(const std::string &metric_name, scalar_t value) const
void setGlobalMax(scalar_t x)
Set the global maximum across parts.
void setValue(int enumIndex, scalar_t value)
#define GRAPH_METRICS_TYPE_NAME
void setGlobalSum(scalar_t x)
Set the global sum.
scalar_t getGlobalSum() const
Get the global sum of edge cuts for all parts.
static std::vector< std::string > static_metricNames_
Defines the GraphModel interface.
scalar_t getGlobalMax() const
Get the global maximum of edge cuts per part across all parts.