Zoltan2  Version of the Day
Zoltan2_PartitioningSolutionQuality.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_SOLUTIONQUALITY_HPP
51 #define ZOLTAN2_SOLUTIONQUALITY_HPP
52 
53 #include <Zoltan2_Metric.hpp>
55 
56 namespace Zoltan2{
57 
65 template <typename Adapter>
67 
68 private:
69 
70  typedef typename Adapter::lno_t lno_t;
71  typedef typename Adapter::gid_t gid_t;
72  typedef typename Adapter::scalar_t scalar_t;
73 
74  const RCP<const Environment> env_;
75 
76  partId_t numGlobalParts_; // desired
77  partId_t targetGlobalParts_; // actual
78  partId_t numNonEmpty_; // of actual
79 
80  ArrayRCP<MetricValues<scalar_t> > metrics_;
81  ArrayRCP<const MetricValues<scalar_t> > metricsConst_;
82 
83 public:
84 
94  PartitioningSolutionQuality(const RCP<const Environment> &env,
95  const RCP<const Comm<int> > &problemComm,
96  const RCP<const Adapter> &ia,
97  const RCP<const PartitioningSolution<Adapter> > &soln);
98 
102  ArrayRCP<const MetricValues<scalar_t> > getMetrics() const{
103  return metricsConst_;
104  }
105 
109  void getObjectCountImbalance(scalar_t &imbalance) const{
110  imbalance = metrics_[0].getMaxImbalance();
111  }
112 
118  void getNormedImbalance(scalar_t &imbalance) const{
119  if (metrics_.size() > 1)
120  imbalance = metrics_[1].getMaxImbalance();
121  else
122  imbalance = metrics_[0].getMaxImbalance();
123  }
124 
131  void getWeightImbalance(scalar_t &imbalance, int dim=0) const{
132  imbalance = 0;
133  if (metrics_.size() > 2) // dimension dim of multiple weights
134  imbalance = metrics_[dim+2].getMaxImbalance();
135  else if (metrics_.size() == 2) // only one weight
136  imbalance = metrics_[1].getMaxImbalance();
137  else // no weights, return object count imbalance
138  imbalance = metrics_[0].getMaxImbalance();
139  }
140 
143  void printMetrics(ostream &os) const {
144  Zoltan2::printMetrics<scalar_t>(os,
145  targetGlobalParts_, numGlobalParts_, numNonEmpty_,
146  metrics_.view(0, metrics_.size()));
147  }
148 };
149 
150 template <typename Adapter>
152  const RCP<const Environment> &env,
153  const RCP<const Comm<int> > &problemComm,
154  const RCP<const Adapter> &ia,
155  const RCP<const PartitioningSolution<Adapter> > &soln):
156  env_(env), numGlobalParts_(0), targetGlobalParts_(0), numNonEmpty_(0),
157  metrics_(), metricsConst_()
158 {
159 
160  env->debug(DETAILED_STATUS, string("Entering PartitioningSolutionQuality"));
161  env->timerStart(MACRO_TIMERS, "Computing metrics");
162 
163  // When we add parameters for which weights to use, we
164  // should check those here. For now we compute metrics
165  // using all weights.
166 
167  const Teuchos::ParameterList &pl = env->getParameters();
169 
170  const Teuchos::ParameterEntry *pe = pl.getEntryPtr("partitioning_objective");
171 
172  if (pe){
173  string strChoice = pe->getValue<string>(&strChoice);
174  if (strChoice == string("multicriteria_minimize_total_weight"))
175  mcnorm = normMinimizeTotalWeight;
176  else if (strChoice == string("multicriteria_minimize_maximum_weight"))
177  mcnorm = normMinimizeMaximumWeight;
178  }
179 
180  try{
181  objectMetrics<Adapter>(env, problemComm, mcnorm, ia, soln,
182  numGlobalParts_, numNonEmpty_, metrics_);
183  }
185 
186  targetGlobalParts_ = soln->getTargetGlobalNumberOfParts();
187 
188  env->timerStop(MACRO_TIMERS, "Computing metrics");
189  env->debug(DETAILED_STATUS, string("Exiting PartitioningSolutionQuality"));
190 }
191 
192 } // namespace Zoltan2
193 
194 #endif
Time an algorithm (or other entity) as a whole.
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Metric class and namespace methods to compute quality metrics.
void getObjectCountImbalance(scalar_t &imbalance) const
Return the object count imbalance.
zoltan2_partId_t partId_t
Defines the PartitioningSolution class.
sub-steps, each method&#39;s entry and exit
void printMetrics(ostream &os) const
Print all the metrics.
A class that computes and returns quality metrics.
A PartitioningSolution is a solution to a partitioning problem.
void getWeightImbalance(scalar_t &imbalance, int dim=0) const
Return the imbalance for the requested weight dimension.
double scalar_t
multiCriteriaNorm
Enumerator used in code for multicriteria norm choice.
void getNormedImbalance(scalar_t &imbalance) const
Return the object normed weight imbalance.
ArrayRCP< const MetricValues< scalar_t > > getMetrics() const
Return the metric values.
PartitioningSolutionQuality(const RCP< const Environment > &env, const RCP< const Comm< int > > &problemComm, const RCP< const Adapter > &ia, const RCP< const PartitioningSolution< Adapter > > &soln)
Constructor.