94 #ifndef ZOLTAN2_EVALUATEPARTITION_HPP 95 #define ZOLTAN2_EVALUATEPARTITION_HPP 113 template <
typename Adapter>
119 typedef typename Adapter::lno_t lno_t;
121 typedef typename Adapter::scalar_t scalar_t;
125 part_t numGlobalParts_;
126 part_t targetGlobalParts_;
130 typedef ArrayRCP<RCP<base_metric_type> > base_metric_array_type;
131 base_metric_array_type metricsBase_;
136 const RCP<
const Comm<int> > &problemComm,
157 const RCP<
const Comm<int> > &problemComm,
162 numGlobalParts_(0), targetGlobalParts_(0), numNonEmpty_(0), metricsBase_() {
169 const RCP<const Environment> &_env,
170 const RCP<
const Comm<int> > &_problemComm,
172 const ArrayView<const typename Adapter::part_t> &_partArray,
175 ArrayRCP<typename Adapter::scalar_t> &_globalSums){
176 globalWeightedCutsMessagesByPart <Adapter>(_env,
177 _problemComm, _graph, _partArray,
178 _numGlobalParts, _metricsBase,
198 numGlobalParts_(0), targetGlobalParts_(0), numNonEmpty_(0), metricsBase_()
200 RCP<const Comm<int> > problemComm = DefaultComm<int>::getComm();
217 const RCP<
const Comm<int> > &problemComm,
221 numGlobalParts_(0), targetGlobalParts_(0), numNonEmpty_(0), metricsBase_()
226 #ifdef HAVE_ZOLTAN2_MPI 243 numGlobalParts_(0), targetGlobalParts_(0), numNonEmpty_(0), metricsBase_()
245 RCP<Teuchos::OpaqueWrapper<MPI_Comm> > wrapper =
246 Teuchos::opaqueWrapper(comm);
247 RCP<const Comm<int> > problemComm =
248 rcp<const Comm<int> >(
new Teuchos::MpiComm<int>(wrapper));
261 std::string metricType)
const {
265 int sizeOfArrayView = 0;
266 for(
auto n = 0; n < metricsBase_.size(); ++n) {
267 if( metricsBase_[n]->getMetricType() == metricType ) {
268 if (beginIndex == -1) {
274 if (sizeOfArrayView == 0) {
275 return ArrayView<RCP<base_metric_type> >();
277 return metricsBase_.view(beginIndex, sizeOfArrayView);
284 if( metrics.size() <= 0 ) {
285 throw std::logic_error(
"getObjectCountImbalance() was called " 286 "but no metrics data was generated for " +
289 return metrics[0]->getMetricValue(
"maximum imbalance");
300 if( metrics.size() <= 0 ) {
301 throw std::logic_error(
"getNormedImbalance() was called " 302 "but no metrics data was generated for " +
305 if( metrics.size() <= 1 ) {
306 throw std::logic_error(
"getNormedImbalance() was called " 307 "but the normed data does not exist." );
309 return metrics[1]->getMetricValue(
"maximum imbalance");
331 int weight0IndexStartsAtThisArrayIndex = ( metrics.size() > 2 ) ? 2 : 1;
332 int numberOfWeights = metrics.size() - weight0IndexStartsAtThisArrayIndex;
333 int indexInArray = weight0IndexStartsAtThisArrayIndex + weightIndex;
334 if( metrics.size() <= indexInArray ) {
335 throw std::logic_error(
"getWeightImbalance was called with weight index "+
336 std::to_string(weightIndex) +
337 " but the maximum weight available for " +
339 " is weight " + std::to_string(numberOfWeights-1) +
342 return metrics[indexInArray]->getMetricValue(
"maximum imbalance");
349 if( graphMetrics.size() < 1 ) {
350 throw std::logic_error(
"getMaxEdgeCut() was called " 351 "but no metrics data was generated for " +
354 return graphMetrics[0]->getMetricValue(
"global maximum");
361 int indexInArray = weightIndex + 1;
362 if( graphMetrics.size() <= 1 ) {
363 throw std::logic_error(
"getMaxWeightEdgeCut was called with " 364 "weight index " + std::to_string(weightIndex) +
365 " but no weights were available for " +
368 else if( graphMetrics.size() <= indexInArray ) {
372 throw std::logic_error(
"getMaxWeightEdgeCut was called with " 373 "weight index " + std::to_string(weightIndex) +
374 " but the maximum weight available for " +
377 std::to_string(graphMetrics.size() - 2) +
"." );
379 return graphMetrics[indexInArray]->getMetricValue(
"global maximum");
386 if( graphMetrics.size() < 1 ) {
387 throw std::logic_error(
"getTotalEdgeCut() was called but no metrics " 388 "data was generated for " +
391 return graphMetrics[0]->getMetricValue(
"global sum");
398 int indexInArray = weightIndex + 1;
399 if( graphMetrics.size() <= 1 ) {
403 throw std::logic_error(
"getTotalWeightEdgeCut was called with " 404 "weight index " + std::to_string(weightIndex) +
405 " but no weights were available for " +
408 else if( graphMetrics.size() <= indexInArray ) {
409 throw std::logic_error(
"getTotalWeightEdgeCut was called with " 410 "weight index " + std::to_string(weightIndex) +
411 " but the maximum weight available for " +
414 std::to_string(graphMetrics.size() - 2) +
"." );
416 return graphMetrics[indexInArray]->getMetricValue(
"global sum");
425 ArrayView<RCP<base_metric_type>> graphMetrics =
427 if (graphMetrics.size() != 0) {
428 Zoltan2::printGraphMetrics<scalar_t, part_t>(os, targetGlobalParts_,
429 numGlobalParts_, graphMetrics);
434 if (imbalanceMetrics.size() != 0) {
435 Zoltan2::printImbalanceMetrics<scalar_t, part_t>(os, targetGlobalParts_,
442 template <
typename Adapter>
446 const RCP<
const Comm<int> > &comm,
451 RCP<const Comm<int> > problemComm;
452 if (comm == Teuchos::null) {
453 problemComm = DefaultComm<int>::getComm();
458 RCP<Environment> env;
465 env->debug(
DETAILED_STATUS, std::string(
"Entering EvaluatePartition"));
469 size_t numLocalObjects = ia->getLocalNumIDs();
470 ArrayRCP<const part_t> parts;
475 env->localInputAssertion(__FILE__, __LINE__,
"parts not set",
480 const part_t *tmp = NULL;
481 ia->getPartsView(tmp);
483 parts = arcp(tmp, 0, numLocalObjects,
false);
486 part_t *procs =
new part_t[numLocalObjects];
487 for (
size_t i=0;i<numLocalObjects;i++) procs[i]=problemComm->getRank();
488 parts = arcp(procs, 0, numLocalObjects,
true);
491 ArrayView<const part_t> partArray = parts(0, numLocalObjects);
498 const Teuchos::ParameterEntry *pe = p->getEntryPtr(
"partitioning_objective");
500 std::string strChoice = pe->getValue<std::string>(&strChoice);
501 if (strChoice == std::string(
"multicriteria_minimize_total_weight"))
503 else if (strChoice == std::string(
"multicriteria_minimize_maximum_weight"))
507 const RCP<const base_adapter_t> bia =
508 rcp(dynamic_cast<const base_adapter_t *>(ia),
false);
511 imbalanceMetrics<Adapter>(env, problemComm, mcnorm, ia, soln, partArray,
513 numGlobalParts_, numNonEmpty_, metricsBase_);
520 targetGlobalParts_ = problemComm->getSize();
529 env->timerStart(
MACRO_TIMERS,
"Computing graph metrics");
534 std::bitset<NUM_MODEL_FLAGS> modelFlags;
538 RCP<const GraphModel<base_adapter_t> > graph = graphModel;
539 if (graphModel == Teuchos::null) {
545 ArrayRCP<scalar_t> globalSums;
547 globalWeightedCutsByPart<Adapter>(env,
548 problemComm, graph, partArray,
549 numGlobalParts_, metricsBase_,
552 problemComm, graph, partArray,
553 numGlobalParts_, metricsBase_,
558 env->timerStop(
MACRO_TIMERS,
"Computing graph metrics");
void imbalanceMetrics(const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, multiCriteriaNorm mcNorm, const Adapter *ia, const PartitioningSolution< Adapter > *solution, const ArrayView< const typename Adapter::part_t > &partArray, const RCP< const GraphModel< typename Adapter::base_adapter_t > > &graphModel, typename Adapter::part_t &numExistingParts, typename Adapter::part_t &numNonemptyParts, ArrayRCP< RCP< BaseClassMetrics< typename Adapter::scalar_t > > > &metrics)
Compute imbalance metrics for a distribution.
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
Time an algorithm (or other entity) as a whole.
fast typical checks for valid arguments
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
void printMetrics(std::ostream &os) const
Print all metrics.
virtual void calculate_graph_metrics(const RCP< const Environment > &_env, const RCP< const Comm< int > > &_problemComm, const RCP< const GraphModel< typename Adapter::base_adapter_t > > &_graph, const ArrayView< const typename Adapter::part_t > &_partArray, typename Adapter::part_t &_numGlobalParts, ArrayRCP< RCP< BaseClassMetrics< typename Adapter::scalar_t > > > &_metricsBase, ArrayRCP< typename Adapter::scalar_t > &_globalSums)
scalar_t getNormedImbalance() const
Return the object normed weight imbalance. Normed imbalance is only valid if there is at least 2 elem...
Defines the PartitioningSolution class.
scalar_t getObjectCountImbalance() const
Return the object count imbalance.
scalar_t getTotalEdgeCut() const
getTotalEdgeCut
sub-steps, each method's entry and exit
scalar_t getMaxWeightEdgeCut(int weightIndex) const
getMaxWeightEdgeCuts weighted for the specified index
scalar_t getTotalWeightEdgeCut(int weightIndex) const
getTotalWeightEdgeCut weighted for the specified index
#define IMBALANCE_METRICS_TYPE_NAME
SparseMatrixAdapter_t::part_t part_t
A PartitioningSolution is a solution to a partitioning problem.
BaseAdapterType
An enum to identify general types of adapters.
EvaluatePartition(const Adapter *ia, ParameterList *p, const RCP< const Comm< int > > &problemComm, const PartitioningSolution< Adapter > *soln, const RCP< const GraphModel< typename Adapter::base_adapter_t > > &graphModel=Teuchos::null)
Constructor where Teuchos communicator is specified.
The StridedData class manages lists of weights or coordinates.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
Base class for the EvaluatePartition and EvaluateOrdering classes.
void sharedConstructor(const Adapter *ia, ParameterList *p, const RCP< const Comm< int > > &problemComm, const PartitioningSolution< Adapter > *soln, const RCP< const GraphModel< typename Adapter::base_adapter_t > > &graphModel)
#define GRAPH_METRICS_TYPE_NAME
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
GraphModel defines the interface required for graph models.
multiCriteriaNorm
Enumerator used in code for multicriteria norm choice.
EvaluatePartition(const Adapter *ia, ParameterList *p, const PartitioningSolution< Adapter > *soln, const RCP< const GraphModel< typename Adapter::base_adapter_t > > &graphModel=Teuchos::null)
Constructor where communicator is Teuchos default.
size_t getTargetGlobalNumberOfParts() const
Returns the global number of parts desired in the solution.
ArrayView< RCP< base_metric_type > > getAllMetricsOfType(std::string metricType) const
Return the metric list for types matching the given metric type.
A class that computes and returns quality metrics.
virtual ~EvaluatePartition()
scalar_t getWeightImbalance(int weightIndex) const
Return the imbalance for the requested weight.
EvaluatePartition(const Adapter *ia, ParameterList *p, const RCP< const Comm< int > > &problemComm, const PartitioningSolution< Adapter > *soln, bool force_evaluate, const RCP< const GraphModel< typename Adapter::base_adapter_t > > &graphModel=Teuchos::null)
Constructor where communicator is Teuchos default, and takes another parameter whether to evaluate me...
scalar_t getMaxEdgeCut() const
Return the max cut for the requested weight.