/usr/include/trilinos/Zoltan2_PartitioningSolutionQuality.hpp is in libtrilinos-zoltan2-dev 12.4.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | // @HEADER
//
// ***********************************************************************
//
// Zoltan2: A package of combinatorial algorithms for scientific computing
// Copyright 2012 Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Karen Devine (kddevin@sandia.gov)
// Erik Boman (egboman@sandia.gov)
// Siva Rajamanickam (srajama@sandia.gov)
//
// ***********************************************************************
//
// @HEADER
/*! \file Zoltan2_PartitioningSolutionQuality.hpp
* \brief Defines the PartitioningSolutionQuality class.
*/
#ifndef ZOLTAN2_SOLUTIONQUALITY_HPP
#define ZOLTAN2_SOLUTIONQUALITY_HPP
#include <Zoltan2_Metric.hpp>
#include <Zoltan2_PartitioningSolution.hpp>
namespace Zoltan2{
/*! \brief A class that computes and returns quality metrics.
* \todo For some problems it will be necessary to build the
* Model again in order to compute metrics. For now
* we don't have any problems like that.
\todo write a unit test for this class
*/
template <typename Adapter>
class PartitioningSolutionQuality {
private:
typedef typename Adapter::lno_t lno_t;
typedef typename Adapter::part_t part_t;
typedef typename Adapter::scalar_t scalar_t;
const RCP<const Environment> env_;
part_t numGlobalParts_; // desired
part_t targetGlobalParts_; // actual
part_t numNonEmpty_; // of actual
ArrayRCP<MetricValues<scalar_t> > metrics_;
ArrayRCP<const MetricValues<scalar_t> > metricsConst_;
public:
/*! \brief Constructor
\param env the problem environment
\param problemComm the problem communicator
\param ia the problem input adapter
\param soln the solution
The constructor does global communication to compute the metrics.
The rest of the methods are local.
*/
PartitioningSolutionQuality(const RCP<const Environment> &env,
const RCP<const Comm<int> > &problemComm,
const RCP<const Adapter> &ia,
const RCP<const PartitioningSolution<Adapter> > &soln);
/*! \brief Return the metric values.
* \param values on return is the array of values.
*/
ArrayRCP<const MetricValues<scalar_t> > getMetrics() const{
//BDD return metricsConst_;
if(metricsConst_.is_null()) return metrics_;
return metricsConst_;
}
/*! \brief Return the object count imbalance.
* \param imbalance on return is the object count imbalance.
*/
void getObjectCountImbalance(scalar_t &imbalance) const{
imbalance = metrics_[0].getMaxImbalance();
}
/*! \brief Return the object normed weight imbalance.
* \param imbalance on return is the object normed weight imbalance.
* If there were no weights, this is the object count imbalance.
* If there was one weight, it is the imbalance with respect to that weight.
*/
void getNormedImbalance(scalar_t &imbalance) const{
if (metrics_.size() > 1)
imbalance = metrics_[1].getMaxImbalance();
else
imbalance = metrics_[0].getMaxImbalance();
}
/*! \brief Return the imbalance for the requested weight.
* \param imbalance on return is the requested value.
* \param idx is the weight index requested, ranging from zero
* to one less than the number of weights provided in the input.
* If there were no weights, this is the object count imbalance.
*/
void getWeightImbalance(scalar_t &imbalance, int idx=0) const{
imbalance = 0;
if (metrics_.size() > 2) // idx of multiple weights
imbalance = metrics_[idx+2].getMaxImbalance();
else if (metrics_.size() == 2) // only one weight
imbalance = metrics_[1].getMaxImbalance();
else // no weights, return object count imbalance
imbalance = metrics_[0].getMaxImbalance();
}
/*! \brief Print all the metrics
*/
void printMetrics(std::ostream &os) const {
Zoltan2::printMetrics<scalar_t, part_t>(os,
targetGlobalParts_, numGlobalParts_, numNonEmpty_,
metrics_.view(0, metrics_.size()));
}
};
template <typename Adapter>
class GraphPartitioningSolutionQuality {
private:
typedef typename Adapter::lno_t lno_t;
typedef typename Adapter::part_t part_t;
typedef typename Adapter::scalar_t scalar_t;
const RCP<const Environment> env_;
part_t numGlobalParts_; // desired
part_t targetGlobalParts_; // actual
ArrayRCP<GraphMetricValues<scalar_t> > metrics_;
ArrayRCP<const GraphMetricValues<scalar_t> > metricsConst_;
public:
/*! \brief Constructor
\param env the problem environment
\param problemComm the problem communicator
\param ia the problem input adapter
\param soln the solution
The constructor does global communication to compute the metrics.
The rest of the methods are local.
*/
GraphPartitioningSolutionQuality(const RCP<const Environment> &env,
const RCP<const Comm<int> > &problemComm,
const RCP<const GraphModel<typename Adapter::base_adapter_t> > &graph,
const RCP<const Adapter> &ia,
const RCP<const PartitioningSolution<Adapter> > &soln);
/*! \brief Return the graph metric values.
* \param values on return is the array of values.
*/
ArrayRCP<const GraphMetricValues<scalar_t> > getGraphMetrics() const{
if(metricsConst_.is_null()) return metrics_;
return metricsConst_;
}
/*! \brief Return the max cut for the requested weight.
* \param cut on return is the requested value.
* \param idx is the weight index reqested, ranging from zero
* to one less than the number of weights provided in the input.
* If there were no weights, this is the cut count.
*/
void getWeightCut(scalar_t &cut, int idx=0) const{
if (metrics_.size() < idx) // idx too high
cut = metrics_[metrics_.size()-1].getGlobalMax();
else if (idx < 0) // idx too low
cut = metrics_[0].getGlobalMax();
else // idx weight
cut = metrics_[idx].getGlobalMax();
}
};
template <typename Adapter>
PartitioningSolutionQuality<Adapter>::PartitioningSolutionQuality(
const RCP<const Environment> &env,
const RCP<const Comm<int> > &problemComm,
const RCP<const Adapter> &ia,
const RCP<const PartitioningSolution<Adapter> > &soln):
env_(env), numGlobalParts_(0), targetGlobalParts_(0), numNonEmpty_(0),
metrics_(), metricsConst_()
{
env->debug(DETAILED_STATUS, std::string("Entering PartitioningSolutionQuality"));
env->timerStart(MACRO_TIMERS, "Computing metrics");
// When we add parameters for which weights to use, we
// should check those here. For now we compute metrics
// using all weights.
const Teuchos::ParameterList &pl = env->getParameters();
multiCriteriaNorm mcnorm = normBalanceTotalMaximum;
const Teuchos::ParameterEntry *pe = pl.getEntryPtr("partitioning_objective");
if (pe){
std::string strChoice = pe->getValue<std::string>(&strChoice);
if (strChoice == std::string("multicriteria_minimize_total_weight"))
mcnorm = normMinimizeTotalWeight;
else if (strChoice == std::string("multicriteria_minimize_maximum_weight"))
mcnorm = normMinimizeMaximumWeight;
}
try{
objectMetrics<Adapter>(env, problemComm, mcnorm, ia, soln,
numGlobalParts_, numNonEmpty_, metrics_);
}
Z2_FORWARD_EXCEPTIONS;
targetGlobalParts_ = soln->getTargetGlobalNumberOfParts();
env->timerStop(MACRO_TIMERS, "Computing metrics");
env->debug(DETAILED_STATUS, std::string("Exiting PartitioningSolutionQuality"));
}
template <typename Adapter>
GraphPartitioningSolutionQuality<Adapter>::GraphPartitioningSolutionQuality(
const RCP<const Environment> &env,
const RCP<const Comm<int> > &problemComm,
const RCP<const GraphModel<typename Adapter::base_adapter_t> > &graph,
const RCP<const Adapter> &ia,
const RCP<const PartitioningSolution<Adapter> > &soln):
env_(env), numGlobalParts_(0), targetGlobalParts_(0),
metrics_(), metricsConst_()
{
env->debug(DETAILED_STATUS,
std::string("Entering GraphPartitioningSolutionQuality"));
env->timerStart(MACRO_TIMERS, "Computing graph metrics");
// When we add parameters for which weights to use, we
// should check those here. For now we compute graph metrics
// using all weights.
typedef typename Adapter::part_t part_t;
// Local number of objects.
size_t numLocalObjects = ia->getLocalNumIDs();
// Parts to which objects are assigned.
const part_t *parts = soln->getPartListView();
env->localInputAssertion(__FILE__, __LINE__, "parts not set",
((numLocalObjects == 0) || parts), BASIC_ASSERTION);
ArrayView<const part_t> partArray(parts, numLocalObjects);
ArrayRCP<scalar_t> globalSums;
try{
globalWeightedCutsByPart<Adapter>(env,
problemComm, graph, partArray, numGlobalParts_, metrics_, globalSums);
}
Z2_FORWARD_EXCEPTIONS;
targetGlobalParts_ = soln->getTargetGlobalNumberOfParts();
env->timerStop(MACRO_TIMERS, "Computing graph metrics");
env->debug(DETAILED_STATUS,
std::string("Exiting GraphPartitioningSolutionQuality"));
}
} // namespace Zoltan2
#endif
|