Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Zoltan2Partitioner_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4 //
5 // Copyright 2009 NTESS and the Ifpack2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef IFPACK2_ZOLTAN2_PARTITIONER_DEF_HPP
11 #define IFPACK2_ZOLTAN2_PARTITIONER_DEF_HPP
12 
13 #if defined(HAVE_IFPACK2_ZOLTAN2)
14 #include "Ifpack2_ConfigDefs.hpp"
15 #include "Ifpack2_Zoltan2Partitioner_decl.hpp"
16 
17 namespace Ifpack2 {
18 
19 //==============================================================================
20 // Constructor
21 template<class GraphType>
22 Zoltan2Partitioner<GraphType>::
23 Zoltan2Partitioner (const Teuchos::RCP<const row_graph_type>& graph) :
24  OverlappingPartitioner<GraphType> (graph), zoltan2AlgoName_ ("phg")
25 {}
26 
27 
28 template<class GraphType>
29 Zoltan2Partitioner<GraphType>::~Zoltan2Partitioner() {}
30 
31 
32 template<class GraphType>
33 void
34 Zoltan2Partitioner<GraphType>::
35 setPartitionParameters (Teuchos::ParameterList& List) {
36  // Default is Parallel Hypergraph
37  zoltan2AlgoName_ = List.get<std::string>("zoltan2: algorithm", zoltan2AlgoName_);
38 }
39 
40 template<class GraphType>
41 void Zoltan2Partitioner<GraphType>::computePartitions()
42 {
43  // Create an input adapter for the Tpetra matrix.
44  Zoltan2GraphAdapterType zoltan2_graph(this->Graph_);
45 
46  // Specify partitioning parameters
47  Teuchos::ParameterList zoltan2_params;
48  zoltan2_params.set("partitioning_approach", "partition");
49  zoltan2_params.set("num_local_parts", this->NumLocalParts_);
50  if (zoltan2AlgoName_ == "parmetis") {
51  zoltan2_params.set("algorithm", "parmetis");
52  zoltan2_params.set("symmetrize_input", "transpose"); // not sure if this does anything, and may fail with non-symm graph
53  zoltan2_params.set("partitioning_objective", "minimize_cut_edge_weight");
54  } else {
55  zoltan2_params.set("algorithm", zoltan2AlgoName_);
56  }
57 
58  // Create and solve partitioning problem
59  Zoltan2::PartitioningProblem<Zoltan2GraphAdapterType>
60  problem(&zoltan2_graph, &zoltan2_params, this->Graph_->getComm());
61  problem.solve();
62 
63  // Save partition
64  auto parts = problem.getSolution().getPartListView();
65  for (size_t i = 0; i < this->Graph_->getLocalNumRows (); ++i) {
66  this->Partition_[i] = parts[i];
67  }
68 }
69 
70 
71 }// namespace Ifpack2
72 
73 #define IFPACK2_ZOLTAN2PARTITIONER_INSTANT(LO,GO,N) \
74  template class Ifpack2::Zoltan2Partitioner<Tpetra::CrsGraph< LO, GO, N > >; \
75  template class Ifpack2::Zoltan2Partitioner<Tpetra::RowGraph< LO, GO, N > >;
76 
77 #endif // HAVE_IFPACK2_ZOLTAN2
78 #endif // IFPACK2_ZOLTAN2PARTITIONER_DEF_HPP
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)