43#ifndef IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP
44#define IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP
48#include "Ifpack2_ConfigDefs.hpp"
49#include "Ifpack2_OverlappingPartitioner_decl.hpp"
50#include "Teuchos_Array.hpp"
51#include "Teuchos_ArrayRCP.hpp"
55template<
class GraphType>
67template<
class GraphType>
71template<
class GraphType>
79template<
class GraphType>
86template<
class GraphType>
87typename GraphType::local_ordinal_type
91 TEUCHOS_TEST_FOR_EXCEPTION(
92 MyRow < 0 || Teuchos::as<size_t> (MyRow) >
Graph_->getLocalNumRows (),
94 "Ifpack2::OverlappingPartitioner::operator(): "
95 "Invalid local row index " << MyRow <<
".");
102template<
class GraphType>
103typename GraphType::local_ordinal_type
105operator() (
const local_ordinal_type i,
const local_ordinal_type j)
const
107 TEUCHOS_TEST_FOR_EXCEPTION(
110 "Ifpack2::OverlappingPartitioner::operator(): "
111 "Invalid local row index i=" << i <<
".");
112 TEUCHOS_TEST_FOR_EXCEPTION(
113 j < 0 || j > Teuchos::as<local_ordinal_type> (
Parts_[i].size ()),
115 "Ifpack2::OverlappingPartitioner::operator(): "
116 "Invalid node index j=" << j <<
".");
121template<
class GraphType>
126 TEUCHOS_TEST_FOR_EXCEPTION(
127 Part < 0 || Part > Teuchos::as<local_ordinal_type> (
NumLocalParts_),
129 "Ifpack2::OverlappingPartitioner::numRowsInPart: "
130 "Invalid partition index Part=" << Part <<
".");
131 return Parts_[Part].size ();
135template<
class GraphType>
139 Teuchos::ArrayRCP<local_ordinal_type>& List)
const
143 for (
size_t i = 0; i < numRows; ++i) {
144 List[i] =
Parts_[Part][i];
149template<
class GraphType>
150Teuchos::ArrayView<const typename GraphType::local_ordinal_type>
157template<
class GraphType>
166 typedef Teuchos::RCP< Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type>
const >
map_type;
167 typedef Teuchos::RCP<Tpetra::Import<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type>
const >
import_type;
173 if (theImport != Teuchos::null) List.set<
import_type >(
"theImport",theImport);
184 TEUCHOS_TEST_FOR_EXCEPTION(
188 "Ifpack2::OverlappingPartitioner::setParameters: "
190 TEUCHOS_TEST_FOR_EXCEPTION(
192 "Ifpack2::OverlappingPartitioner::setParameters: "
199template<
class GraphType>
205 TEUCHOS_TEST_FOR_EXCEPTION(
208 "Ifpack2::OverlappingPartitioner::compute: "
209 "Invalid NumLocalParts_ or OverlappingLevel_.");
213 const char printMsg[] =
"OverlappingPartitioner: ";
216 cout << printMsg <<
"Number of local parts = "
218 cout << printMsg <<
"Approx. Number of global parts = "
220 cout << printMsg <<
"Amount of overlap = "
229 TEUCHOS_TEST_FOR_EXCEPTION(
230 !
Graph_->isFillComplete (), std::runtime_error,
231 "Ifpack2::OverlappingPartitioner::compute: "
232 "The input graph must be fill complete.");
234 TEUCHOS_TEST_FOR_EXCEPTION(
235 Graph_->getGlobalNumRows () !=
Graph_->getGlobalNumCols (),
237 "Ifpack2::OverlappingPartitioner::compute: "
238 "The input graph must be (globally) square.");
251template<
class GraphType>
259 const local_ordinal_type invalid =
260 Teuchos::OrdinalTraits<local_ordinal_type>::invalid();
266 std::vector<size_t> sizes;
274 for (
size_t i = 0; i <
Graph_->getLocalNumRows (); ++i) {
275 TEUCHOS_TEST_FOR_EXCEPTION(
277 "Ifpack2::OverlappingPartitioner::computeOverlappingPartitions: "
278 "Partition_[i] > NumLocalParts_.");
289 Parts_[i].resize (sizes[i]);
297 for (
size_t i = 0; i <
Graph_->getLocalNumRows (); ++i) {
298 const local_ordinal_type part =
Partition_[i];
299 if (part != invalid) {
300 const size_t count = sizes[part];
313 std::vector<std::vector<size_t> > tmp;
320 int MaxNumEntries_tmp =
Graph_->getLocalMaxNumRowEntries();
321 nonconst_local_inds_host_view_type Indices(
"Indices",MaxNumEntries_tmp);
322 nonconst_local_inds_host_view_type newIndices(
"newIndices",MaxNumEntries_tmp);
326 local_ordinal_type numLocalRows =
Graph_->getLocalNumRows();
328 for (
size_t i = 0; i < Teuchos::as<size_t> (
Parts_[part].size ()); ++i) {
329 const local_ordinal_type LRID =
Parts_[part][i];
332 Graph_->getLocalRowCopy (LRID, Indices, numIndices);
334 for (
size_t j = 0; j < numIndices; ++j) {
336 const local_ordinal_type col = Indices[j];
337 if (col >= numLocalRows) {
342 std::vector<size_t>::iterator where =
343 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (col));
346 if (where == tmp[part].end()) {
347 tmp[part].push_back (col);
357 std::vector<size_t>::iterator where =
358 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (LRID));
362 if (where == tmp[part].end ()) {
363 tmp[part].push_back (LRID);
372 for (
size_t i = 0; i < Teuchos::as<size_t> (
Parts_[part].size ()); ++i) {
373 const local_ordinal_type LRID =
Parts_[part][i];
376 Graph_->getLocalRowCopy (LRID, Indices, numIndices);
381 Tpetra::sort(Indices,numIndices);
383 for (
size_t j = 0; j < numIndices; ++j) {
385 const local_ordinal_type col = Indices[j];
386 if (Teuchos::as<size_t> (col) >=
Graph_->getLocalNumRows ()) {
391 std::vector<size_t>::iterator where =
392 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (col));
395 if (where == tmp[part].end()) {
398 size_t numNewIndices;
399 Graph_->getLocalRowCopy(col, newIndices, numNewIndices);
400 Tpetra::sort(newIndices,numNewIndices);
401 auto Indices_rcp = Kokkos::Compat::persistingView<nonconst_local_inds_host_view_type>(Indices, 0, numIndices);
402 auto newIndices_rcp = Kokkos::Compat::persistingView<nonconst_local_inds_host_view_type>(newIndices, 0, numNewIndices);
403 bool isSubset = std::includes(Indices_rcp.begin(),Indices_rcp.begin()+numIndices,
404 newIndices_rcp.begin(),newIndices_rcp.begin()+numNewIndices);
406 tmp[part].push_back (col);
412 std::vector<size_t>::iterator where =
413 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (LRID));
417 if (where == tmp[part].end ()) {
418 tmp[part].push_back (LRID);
431 Parts_[i].resize (tmp[i].size ());
432 for (
size_t j = 0; j < tmp[i].size (); ++j) {
440template<
class GraphType>
447template<
class GraphType>
451 Teuchos::FancyOStream fos (Teuchos::rcpFromRef (os));
452 fos.setOutputToRootOnly (0);
458template<
class GraphType>
461 std::ostringstream oss;
462 oss << Teuchos::Describable::description();
464 oss <<
"{status = computed";
467 oss <<
"{status = is not computed";
474template<
class GraphType>
478 if (verbLevel == Teuchos::VERB_NONE) {
482 os <<
"================================================================================" << endl;
483 os <<
"Ifpack2::OverlappingPartitioner" << endl;
484 os <<
"Number of local rows = " <<
Graph_->getLocalNumRows() << endl;
485 os <<
"Number of global rows = " <<
Graph_->getGlobalNumRows() << endl;
489 os <<
"================================================================================" << endl;
494#define IFPACK2_OVERLAPPINGPARTITIONER_INSTANT(LO,GO,N) \
495 template class Ifpack2::OverlappingPartitioner<Tpetra::CrsGraph< LO, GO, N > >; \
496 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:178
size_t numRowsInPart(const local_ordinal_type Part) const
the number of rows contained in the given partition.
Definition Ifpack2_OverlappingPartitioner_def.hpp:124
OverlappingPartitioner(const Teuchos::RCP< const row_graph_type > &graph)
Constructor.
Definition Ifpack2_OverlappingPartitioner_def.hpp:57
bool verbose_
If true, information are reported to stdout.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:197
virtual std::ostream & print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
Definition Ifpack2_OverlappingPartitioner_def.hpp:449
virtual void compute()
Computes the partitions. Returns 0 if successful.
Definition Ifpack2_OverlappingPartitioner_def.hpp:200
virtual void setParameters(Teuchos::ParameterList &List)
Set all the parameters for the partitioner.
Definition Ifpack2_OverlappingPartitioner_def.hpp:160
virtual bool isComputed() const
Returns true if partitions have been computed successfully.
Definition Ifpack2_OverlappingPartitioner_def.hpp:441
int OverlappingLevel_
Level of overlap.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:191
virtual void computeOverlappingPartitions()
Computes the partitions. Returns 0 if successful.
Definition Ifpack2_OverlappingPartitioner_def.hpp:252
int numLocalParts() const
Number of computed local partitions.
Definition Ifpack2_OverlappingPartitioner_def.hpp:73
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:475
Teuchos::RCP< const row_graph_type > Graph_
The graph to be partitioned.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:188
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:194
Teuchos::Array< Teuchos::ArrayRCP< local_ordinal_type > > Parts_
Mapping from partition to all rows it contains.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:185
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:138
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:80
int NumLocalParts_
Number of local subgraphs.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:171
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:203
virtual ~OverlappingPartitioner()
Destructor.
Definition Ifpack2_OverlappingPartitioner_def.hpp:68
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:151
std::string description() const
Return a simple one-line description of this object.
Definition Ifpack2_OverlappingPartitioner_def.hpp:459
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:89
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:74