10#ifndef IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP
11#define IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP
15#include "Ifpack2_ConfigDefs.hpp"
16#include "Ifpack2_OverlappingPartitioner_decl.hpp"
17#include "Teuchos_Array.hpp"
18#include "Teuchos_ArrayRCP.hpp"
19#include "Tpetra_Util.hpp"
23template <
class GraphType>
33template <
class GraphType>
36template <
class GraphType>
41template <
class GraphType>
46template <
class GraphType>
47typename GraphType::local_ordinal_type
49operator()(
const local_ordinal_type MyRow)
const {
50 TEUCHOS_TEST_FOR_EXCEPTION(
51 MyRow < 0 || Teuchos::as<size_t>(MyRow) >
Graph_->getLocalNumRows(),
53 "Ifpack2::OverlappingPartitioner::operator(): "
54 "Invalid local row index "
61template <
class GraphType>
62typename GraphType::local_ordinal_type
64operator()(
const local_ordinal_type i,
const local_ordinal_type j)
const {
65 TEUCHOS_TEST_FOR_EXCEPTION(
68 "Ifpack2::OverlappingPartitioner::operator(): "
69 "Invalid local row index i="
71 TEUCHOS_TEST_FOR_EXCEPTION(
72 j < 0 || j > Teuchos::as<local_ordinal_type>(
Parts_[i].size()),
74 "Ifpack2::OverlappingPartitioner::operator(): "
75 "Invalid node index j="
81template <
class GraphType>
85 TEUCHOS_TEST_FOR_EXCEPTION(
86 Part < 0 || Part > Teuchos::as<local_ordinal_type>(
NumLocalParts_),
88 "Ifpack2::OverlappingPartitioner::numRowsInPart: "
89 "Invalid partition index Part="
91 return Parts_[Part].size();
95template <
class GraphType>
98 Teuchos::ArrayRCP<local_ordinal_type>& List)
const {
101 for (
size_t i = 0; i < numRows; ++i) {
102 List[i] =
Parts_[Part][i];
107template <
class GraphType>
108Teuchos::ArrayView<const typename GraphType::local_ordinal_type>
114template <
class GraphType>
121 typedef Teuchos::RCP<Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type>
const>
map_type;
122 typedef Teuchos::RCP<Tpetra::Import<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type>
const>
import_type;
128 if (theImport != Teuchos::null) List.set<
import_type>(
"theImport", theImport);
139 TEUCHOS_TEST_FOR_EXCEPTION(
143 "Ifpack2::OverlappingPartitioner::setParameters: "
144 "Invalid NumLocalParts_ = "
146 TEUCHOS_TEST_FOR_EXCEPTION(
148 "Ifpack2::OverlappingPartitioner::setParameters: "
149 "Invalid OverlappingLevel_ = "
156template <
class GraphType>
161 TEUCHOS_TEST_FOR_EXCEPTION(
164 "Ifpack2::OverlappingPartitioner::compute: "
165 "Invalid NumLocalParts_ or OverlappingLevel_.");
169 const char printMsg[] =
"OverlappingPartitioner: ";
172 cout << printMsg <<
"Number of local parts = "
174 cout << printMsg <<
"Approx. Number of global parts = "
176 cout << printMsg <<
"Amount of overlap = "
185 TEUCHOS_TEST_FOR_EXCEPTION(
186 !
Graph_->isFillComplete(), std::runtime_error,
187 "Ifpack2::OverlappingPartitioner::compute: "
188 "The input graph must be fill complete.");
190 TEUCHOS_TEST_FOR_EXCEPTION(
191 Graph_->getGlobalNumRows() !=
Graph_->getGlobalNumCols(),
193 "Ifpack2::OverlappingPartitioner::compute: "
194 "The input graph must be (globally) square.");
207template <
class GraphType>
214 const local_ordinal_type invalid =
215 Teuchos::OrdinalTraits<local_ordinal_type>::invalid();
221 std::vector<size_t> sizes;
229 for (
size_t i = 0; i <
Graph_->getLocalNumRows(); ++i) {
230 TEUCHOS_TEST_FOR_EXCEPTION(
232 "Ifpack2::OverlappingPartitioner::computeOverlappingPartitions: "
233 "Partition_[i] > NumLocalParts_.");
244 Parts_[i].resize(sizes[i]);
252 for (
size_t i = 0; i <
Graph_->getLocalNumRows(); ++i) {
253 const local_ordinal_type part =
Partition_[i];
254 if (part != invalid) {
255 const size_t count = sizes[part];
268 std::vector<std::vector<size_t> > tmp;
275 int MaxNumEntries_tmp =
Graph_->getLocalMaxNumRowEntries();
276 nonconst_local_inds_host_view_type Indices(
"Indices", MaxNumEntries_tmp);
277 nonconst_local_inds_host_view_type newIndices(
"newIndices", MaxNumEntries_tmp);
280 local_ordinal_type numLocalRows =
Graph_->getLocalNumRows();
282 for (
size_t i = 0; i < Teuchos::as<size_t>(
Parts_[part].size()); ++i) {
283 const local_ordinal_type LRID =
Parts_[part][i];
286 Graph_->getLocalRowCopy(LRID, Indices, numIndices);
288 for (
size_t j = 0; j < numIndices; ++j) {
290 const local_ordinal_type col = Indices[j];
291 if (col >= numLocalRows) {
296 std::vector<size_t>::iterator where =
297 std::find(tmp[part].begin(), tmp[part].end(), Teuchos::as<size_t>(col));
299 if (where == tmp[part].end()) {
300 tmp[part].push_back(col);
310 std::vector<size_t>::iterator where =
311 std::find(tmp[part].begin(), tmp[part].end(), Teuchos::as<size_t>(LRID));
315 if (where == tmp[part].end()) {
316 tmp[part].push_back(LRID);
325 for (
size_t i = 0; i < Teuchos::as<size_t>(
Parts_[part].size()); ++i) {
326 const local_ordinal_type LRID =
Parts_[part][i];
329 Graph_->getLocalRowCopy(LRID, Indices, numIndices);
334 Tpetra::sort(Indices, numIndices);
336 for (
size_t j = 0; j < numIndices; ++j) {
338 const local_ordinal_type col = Indices[j];
339 if (Teuchos::as<size_t>(col) >=
Graph_->getLocalNumRows()) {
344 std::vector<size_t>::iterator where =
345 std::find(tmp[part].begin(), tmp[part].end(), Teuchos::as<size_t>(col));
347 if (where == tmp[part].end()) {
350 size_t numNewIndices;
351 Graph_->getLocalRowCopy(col, newIndices, numNewIndices);
352 Tpetra::sort(newIndices, numNewIndices);
353 auto Indices_rcp = Kokkos::Compat::persistingView<nonconst_local_inds_host_view_type>(Indices, 0, numIndices);
354 auto newIndices_rcp = Kokkos::Compat::persistingView<nonconst_local_inds_host_view_type>(newIndices, 0, numNewIndices);
355 bool isSubset = std::includes(Indices_rcp.begin(), Indices_rcp.begin() + numIndices,
356 newIndices_rcp.begin(), newIndices_rcp.begin() + numNewIndices);
358 tmp[part].push_back(col);
364 std::vector<size_t>::iterator where =
365 std::find(tmp[part].begin(), tmp[part].end(), Teuchos::as<size_t>(LRID));
369 if (where == tmp[part].end()) {
370 tmp[part].push_back(LRID);
383 Parts_[i].resize(tmp[i].size());
384 for (
size_t j = 0; j < tmp[i].size(); ++j) {
392template <
class GraphType>
398template <
class GraphType>
401 Teuchos::FancyOStream fos(Teuchos::rcpFromRef(os));
402 fos.setOutputToRootOnly(0);
408template <
class GraphType>
410 std::ostringstream oss;
411 oss << Teuchos::Describable::description();
413 oss <<
"{status = computed";
415 oss <<
"{status = is not computed";
422template <
class GraphType>
425 if (verbLevel == Teuchos::VERB_NONE) {
429 os <<
"================================================================================" << endl;
430 os <<
"Ifpack2::OverlappingPartitioner" << endl;
431 os <<
"Number of local rows = " <<
Graph_->getLocalNumRows() << endl;
432 os <<
"Number of global rows = " <<
Graph_->getGlobalNumRows() << endl;
436 os <<
"================================================================================" << endl;
441#define IFPACK2_OVERLAPPINGPARTITIONER_INSTANT(LO, GO, N) \
442 template class Ifpack2::OverlappingPartitioner<Tpetra::CrsGraph<LO, GO, N> >; \
443 template class Ifpack2::OverlappingPartitioner<Tpetra::RowGraph<LO, GO, N> >;
Teuchos::Array< local_ordinal_type > Partition_
Mapping from local row to partition number.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:144
size_t numRowsInPart(const local_ordinal_type Part) const
the number of rows contained in the given partition.
Definition Ifpack2_OverlappingPartitioner_def.hpp:84
OverlappingPartitioner(const Teuchos::RCP< const row_graph_type > &graph)
Constructor.
Definition Ifpack2_OverlappingPartitioner_def.hpp:25
bool verbose_
If true, information are reported to stdout.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:163
virtual std::ostream & print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
Definition Ifpack2_OverlappingPartitioner_def.hpp:400
virtual void compute()
Computes the partitions. Returns 0 if successful.
Definition Ifpack2_OverlappingPartitioner_def.hpp:157
virtual void setParameters(Teuchos::ParameterList &List)
Set all the parameters for the partitioner.
Definition Ifpack2_OverlappingPartitioner_def.hpp:116
virtual bool isComputed() const
Returns true if partitions have been computed successfully.
Definition Ifpack2_OverlappingPartitioner_def.hpp:393
int OverlappingLevel_
Level of overlap.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:157
virtual void computeOverlappingPartitions()
Computes the partitions. Returns 0 if successful.
Definition Ifpack2_OverlappingPartitioner_def.hpp:208
int numLocalParts() const
Number of computed local partitions.
Definition Ifpack2_OverlappingPartitioner_def.hpp:37
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
Definition Ifpack2_OverlappingPartitioner_def.hpp:423
Teuchos::RCP< const row_graph_type > Graph_
The graph to be partitioned.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:154
virtual void setPartitionParameters(Teuchos::ParameterList &List)=0
Set all the parameters for the partitioner.
bool IsComputed_
If true, the graph has been successfully partitioned.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:160
Teuchos::Array< Teuchos::ArrayRCP< local_ordinal_type > > Parts_
Mapping from partition to all rows it contains.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:151
void rowsInPart(const local_ordinal_type Part, Teuchos::ArrayRCP< local_ordinal_type > &List) const
Fill List with the local indices of the rows in the (overlapping) partition Part.
Definition Ifpack2_OverlappingPartitioner_def.hpp:97
virtual void computePartitions()=0
Computes the partitions. Returns 0 if successful.
int overlappingLevel() const
The number of levels of overlap.
Definition Ifpack2_OverlappingPartitioner_def.hpp:42
int NumLocalParts_
Number of local subgraphs.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:137
bool maintainSparsity_
If true, only add row to partition (block) if doing so won't add new columns to the column map.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:169
virtual ~OverlappingPartitioner()
Destructor.
Definition Ifpack2_OverlappingPartitioner_def.hpp:34
virtual Teuchos::ArrayView< const local_ordinal_type > nonOverlappingPartition() const
A view of the local indices of the nonoverlapping partitions of each local row.
Definition Ifpack2_OverlappingPartitioner_def.hpp:109
std::string description() const
Return a simple one-line description of this object.
Definition Ifpack2_OverlappingPartitioner_def.hpp:409
local_ordinal_type operator()(const local_ordinal_type MyRow) const
Local index of the nonoverlapping partition of the given row.
Definition Ifpack2_OverlappingPartitioner_def.hpp:49
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40