94 #ifndef ZOLTAN2_EVALUATEPARTITION_HPP
95 #define ZOLTAN2_EVALUATEPARTITION_HPP
113 template <
typename Adapter>
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 globalWeightedByPart <Adapter>(_env, _problemComm, _graph,
177 _partArray, _numGlobalParts, _metricsBase, _globalSums);
196 numGlobalParts_(0), targetGlobalParts_(0), numNonEmpty_(0), metricsBase_()
198 Teuchos::RCP<const Comm<int> > problemComm = Tpetra::getDefaultComm();
215 const RCP<
const Comm<int> > &problemComm,
219 numGlobalParts_(0), targetGlobalParts_(0), numNonEmpty_(0), metricsBase_()
224 #ifdef HAVE_ZOLTAN2_MPI
241 numGlobalParts_(0), targetGlobalParts_(0), numNonEmpty_(0), metricsBase_()
243 RCP<Teuchos::OpaqueWrapper<MPI_Comm> > wrapper =
244 Teuchos::opaqueWrapper(comm);
245 RCP<const Comm<int> > problemComm =
246 rcp<const Comm<int> >(
new Teuchos::MpiComm<int>(wrapper));
259 std::string metricType)
const {
263 int sizeOfArrayView = 0;
264 for(
auto n = 0; n < metricsBase_.size(); ++n) {
265 if( metricsBase_[n]->getMetricType() == metricType ) {
266 if (beginIndex == -1) {
272 if (sizeOfArrayView == 0) {
273 return ArrayView<RCP<base_metric_type> >();
275 return metricsBase_.view(beginIndex, sizeOfArrayView);
282 if( metrics.size() <= 0 ) {
283 throw std::logic_error(
"getObjectCountImbalance() was called "
284 "but no metrics data was generated for " +
287 return metrics[0]->getMetricValue(
"maximum imbalance");
298 if( metrics.size() <= 0 ) {
299 throw std::logic_error(
"getNormedImbalance() was called "
300 "but no metrics data was generated for " +
303 if( metrics.size() <= 1 ) {
304 throw std::logic_error(
"getNormedImbalance() was called "
305 "but the normed data does not exist." );
307 return metrics[1]->getMetricValue(
"maximum imbalance");
329 int weight0IndexStartsAtThisArrayIndex = ( metrics.size() > 2 ) ? 2 : 1;
330 int numberOfWeights = metrics.size() - weight0IndexStartsAtThisArrayIndex;
331 int indexInArray = weight0IndexStartsAtThisArrayIndex + weightIndex;
332 if( metrics.size() <= indexInArray ) {
333 throw std::logic_error(
"getWeightImbalance was called with weight index "+
334 std::to_string(weightIndex) +
335 " but the maximum weight available for " +
337 " is weight " + std::to_string(numberOfWeights-1) +
340 return metrics[indexInArray]->getMetricValue(
"maximum imbalance");
347 if( graphMetrics.size() < 1 ) {
348 throw std::logic_error(
"getMaxEdgeCut() was called "
349 "but no metrics data was generated for " +
352 return graphMetrics[0]->getMetricValue(
"global maximum");
359 int indexInArray = weightIndex + 1;
360 if( graphMetrics.size() <= 1 ) {
361 throw std::logic_error(
"getMaxWeightEdgeCut was called with "
362 "weight index " + std::to_string(weightIndex) +
363 " but no weights were available for " +
366 else if( graphMetrics.size() <= indexInArray ) {
370 throw std::logic_error(
"getMaxWeightEdgeCut was called with "
371 "weight index " + std::to_string(weightIndex) +
372 " but the maximum weight available for " +
375 std::to_string(graphMetrics.size() - 2) +
"." );
377 return graphMetrics[indexInArray]->getMetricValue(
"global maximum");
384 if( graphMetrics.size() < 1 ) {
385 throw std::logic_error(
"getTotalEdgeCut() was called but no metrics "
386 "data was generated for " +
389 return graphMetrics[0]->getMetricValue(
"global sum");
396 int indexInArray = weightIndex + 1;
397 if( graphMetrics.size() <= 1 ) {
401 throw std::logic_error(
"getTotalWeightEdgeCut was called with "
402 "weight index " + std::to_string(weightIndex) +
403 " but no weights were available for " +
406 else if( graphMetrics.size() <= indexInArray ) {
407 throw std::logic_error(
"getTotalWeightEdgeCut was called with "
408 "weight index " + std::to_string(weightIndex) +
409 " but the maximum weight available for " +
412 std::to_string(graphMetrics.size() - 2) +
"." );
414 return graphMetrics[indexInArray]->getMetricValue(
"global sum");
421 if( graphMetrics.size() < 1 ) {
422 throw std::logic_error(
"getTotalMessages() was called but no metrics "
423 "data was generated for " +
427 return graphMetrics[1]->getMetricValue(
"global sum");
435 if( graphMetrics.size() < 1 ) {
436 throw std::logic_error(
"getMaxMessages() was called but no metrics "
437 "data was generated for " +
441 return graphMetrics[1]->getMetricValue(
"global maximum");
450 ArrayView<RCP<base_metric_type>> graphMetrics =
452 if (graphMetrics.size() != 0) {
453 Zoltan2::printGraphMetrics<scalar_t, part_t>(os, targetGlobalParts_,
454 numGlobalParts_, graphMetrics);
459 if (imbalanceMetrics.size() != 0) {
460 Zoltan2::printImbalanceMetrics<scalar_t, part_t>(os, targetGlobalParts_,
467 template <
typename Adapter>
471 const RCP<
const Comm<int> > &comm,
476 RCP<const Comm<int> > problemComm;
477 if (comm == Teuchos::null) {
478 problemComm = Tpetra::getDefaultComm();
483 RCP<Environment> env;
490 env->debug(
DETAILED_STATUS, std::string(
"Entering EvaluatePartition"));
494 size_t numLocalObjects = ia->getLocalNumIDs();
495 ArrayRCP<const part_t> parts;
500 env->localInputAssertion(__FILE__, __LINE__,
"parts not set",
505 const part_t *tmp = NULL;
506 ia->getPartsView(tmp);
508 parts = arcp(tmp, 0, numLocalObjects,
false);
511 part_t *procs =
new part_t[numLocalObjects];
512 for (
size_t i=0;i<numLocalObjects;i++) procs[i]=problemComm->getRank();
513 parts = arcp(procs, 0, numLocalObjects,
true);
516 ArrayView<const part_t> partArray = parts(0, numLocalObjects);
523 const Teuchos::ParameterEntry *pe = p->getEntryPtr(
"partitioning_objective");
525 std::string strChoice = pe->getValue<std::string>(&strChoice);
526 if (strChoice == std::string(
"multicriteria_minimize_total_weight"))
528 else if (strChoice == std::string(
"multicriteria_minimize_maximum_weight"))
532 const RCP<const base_adapter_t> bia =
533 rcp(dynamic_cast<const base_adapter_t *>(ia),
false);
536 imbalanceMetrics<Adapter>(env, problemComm, mcnorm, ia, soln, partArray,
538 numGlobalParts_, numNonEmpty_, metricsBase_);
545 targetGlobalParts_ = problemComm->getSize();
554 env->timerStart(
MACRO_TIMERS,
"Computing graph metrics");
559 std::bitset<NUM_MODEL_FLAGS> modelFlags;
563 RCP<const GraphModel<base_adapter_t> > graph = graphModel;
564 if (graphModel == Teuchos::null) {
570 ArrayRCP<scalar_t> globalSums;
572 this->calculate_graph_metrics(env, problemComm, graph, partArray,
573 numGlobalParts_, metricsBase_, globalSums);
577 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.
void printMetrics(std::ostream &os) const
Print all metrics.
fast typical checks for valid arguments
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
ArrayView< RCP< base_metric_type > > getAllMetricsOfType(std::string metricType) const
Return the metric list for types matching the given metric type.
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 getTotalEdgeCut() const
getTotalEdgeCut
Defines the PartitioningSolution class.
sub-steps, each method's entry and exit
scalar_t getWeightImbalance(int weightIndex) const
Return the imbalance for the requested weight.
scalar_t getMaxEdgeCut() const
Return the max cut for the requested weight.
#define IMBALANCE_METRICS_TYPE_NAME
SparseMatrixAdapter_t::part_t part_t
scalar_t getNormedImbalance() const
Return the object normed weight imbalance. Normed imbalance is only valid if there is at least 2 elem...
A PartitioningSolution is a solution to a partitioning problem.
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
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.
map_t::local_ordinal_type lno_t
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
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.
A class that computes and returns quality metrics.
virtual ~EvaluatePartition()
scalar_t getTotalWeightEdgeCut(int weightIndex) const
getTotalWeightEdgeCut weighted for the specified index
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 getMaxWeightEdgeCut(int weightIndex) const
getMaxWeightEdgeCuts weighted for the specified index
size_t getTargetGlobalNumberOfParts() const
Returns the global number of parts desired in the solution.
scalar_t getObjectCountImbalance() const
Return the object count imbalance.
scalar_t getTotalMessages() const
getTotalMessages
scalar_t getMaxMessages() const
getMaxMessages