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"
22template<
class GraphType>
34template<
class GraphType>
38template<
class GraphType>
46template<
class GraphType>
53template<
class GraphType>
54typename GraphType::local_ordinal_type
58 TEUCHOS_TEST_FOR_EXCEPTION(
59 MyRow < 0 || Teuchos::as<size_t> (MyRow) >
Graph_->getLocalNumRows (),
61 "Ifpack2::OverlappingPartitioner::operator(): "
62 "Invalid local row index " << MyRow <<
".");
69template<
class GraphType>
70typename GraphType::local_ordinal_type
72operator() (
const local_ordinal_type i,
const local_ordinal_type j)
const
74 TEUCHOS_TEST_FOR_EXCEPTION(
77 "Ifpack2::OverlappingPartitioner::operator(): "
78 "Invalid local row index i=" << i <<
".");
79 TEUCHOS_TEST_FOR_EXCEPTION(
80 j < 0 || j > Teuchos::as<local_ordinal_type> (
Parts_[i].size ()),
82 "Ifpack2::OverlappingPartitioner::operator(): "
83 "Invalid node index j=" << j <<
".");
88template<
class GraphType>
93 TEUCHOS_TEST_FOR_EXCEPTION(
94 Part < 0 || Part > Teuchos::as<local_ordinal_type> (
NumLocalParts_),
96 "Ifpack2::OverlappingPartitioner::numRowsInPart: "
97 "Invalid partition index Part=" << Part <<
".");
98 return Parts_[Part].size ();
102template<
class GraphType>
106 Teuchos::ArrayRCP<local_ordinal_type>& List)
const
110 for (
size_t i = 0; i < numRows; ++i) {
111 List[i] =
Parts_[Part][i];
116template<
class GraphType>
117Teuchos::ArrayView<const typename GraphType::local_ordinal_type>
124template<
class GraphType>
133 typedef Teuchos::RCP< Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type>
const >
map_type;
134 typedef Teuchos::RCP<Tpetra::Import<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type>
const >
import_type;
140 if (theImport != Teuchos::null) List.set<
import_type >(
"theImport",theImport);
151 TEUCHOS_TEST_FOR_EXCEPTION(
155 "Ifpack2::OverlappingPartitioner::setParameters: "
157 TEUCHOS_TEST_FOR_EXCEPTION(
159 "Ifpack2::OverlappingPartitioner::setParameters: "
166template<
class GraphType>
172 TEUCHOS_TEST_FOR_EXCEPTION(
175 "Ifpack2::OverlappingPartitioner::compute: "
176 "Invalid NumLocalParts_ or OverlappingLevel_.");
180 const char printMsg[] =
"OverlappingPartitioner: ";
183 cout << printMsg <<
"Number of local parts = "
185 cout << printMsg <<
"Approx. Number of global parts = "
187 cout << printMsg <<
"Amount of overlap = "
196 TEUCHOS_TEST_FOR_EXCEPTION(
197 !
Graph_->isFillComplete (), std::runtime_error,
198 "Ifpack2::OverlappingPartitioner::compute: "
199 "The input graph must be fill complete.");
201 TEUCHOS_TEST_FOR_EXCEPTION(
202 Graph_->getGlobalNumRows () !=
Graph_->getGlobalNumCols (),
204 "Ifpack2::OverlappingPartitioner::compute: "
205 "The input graph must be (globally) square.");
218template<
class GraphType>
226 const local_ordinal_type invalid =
227 Teuchos::OrdinalTraits<local_ordinal_type>::invalid();
233 std::vector<size_t> sizes;
241 for (
size_t i = 0; i <
Graph_->getLocalNumRows (); ++i) {
242 TEUCHOS_TEST_FOR_EXCEPTION(
244 "Ifpack2::OverlappingPartitioner::computeOverlappingPartitions: "
245 "Partition_[i] > NumLocalParts_.");
256 Parts_[i].resize (sizes[i]);
264 for (
size_t i = 0; i <
Graph_->getLocalNumRows (); ++i) {
265 const local_ordinal_type part =
Partition_[i];
266 if (part != invalid) {
267 const size_t count = sizes[part];
280 std::vector<std::vector<size_t> > tmp;
287 int MaxNumEntries_tmp =
Graph_->getLocalMaxNumRowEntries();
288 nonconst_local_inds_host_view_type Indices(
"Indices",MaxNumEntries_tmp);
289 nonconst_local_inds_host_view_type newIndices(
"newIndices",MaxNumEntries_tmp);
293 local_ordinal_type numLocalRows =
Graph_->getLocalNumRows();
295 for (
size_t i = 0; i < Teuchos::as<size_t> (
Parts_[part].size ()); ++i) {
296 const local_ordinal_type LRID =
Parts_[part][i];
299 Graph_->getLocalRowCopy (LRID, Indices, numIndices);
301 for (
size_t j = 0; j < numIndices; ++j) {
303 const local_ordinal_type col = Indices[j];
304 if (col >= numLocalRows) {
309 std::vector<size_t>::iterator where =
310 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (col));
313 if (where == tmp[part].end()) {
314 tmp[part].push_back (col);
324 std::vector<size_t>::iterator where =
325 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (LRID));
329 if (where == tmp[part].end ()) {
330 tmp[part].push_back (LRID);
339 for (
size_t i = 0; i < Teuchos::as<size_t> (
Parts_[part].size ()); ++i) {
340 const local_ordinal_type LRID =
Parts_[part][i];
343 Graph_->getLocalRowCopy (LRID, Indices, numIndices);
348 Tpetra::sort(Indices,numIndices);
350 for (
size_t j = 0; j < numIndices; ++j) {
352 const local_ordinal_type col = Indices[j];
353 if (Teuchos::as<size_t> (col) >=
Graph_->getLocalNumRows ()) {
358 std::vector<size_t>::iterator where =
359 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (col));
362 if (where == tmp[part].end()) {
365 size_t numNewIndices;
366 Graph_->getLocalRowCopy(col, newIndices, numNewIndices);
367 Tpetra::sort(newIndices,numNewIndices);
368 auto Indices_rcp = Kokkos::Compat::persistingView<nonconst_local_inds_host_view_type>(Indices, 0, numIndices);
369 auto newIndices_rcp = Kokkos::Compat::persistingView<nonconst_local_inds_host_view_type>(newIndices, 0, numNewIndices);
370 bool isSubset = std::includes(Indices_rcp.begin(),Indices_rcp.begin()+numIndices,
371 newIndices_rcp.begin(),newIndices_rcp.begin()+numNewIndices);
373 tmp[part].push_back (col);
379 std::vector<size_t>::iterator where =
380 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (LRID));
384 if (where == tmp[part].end ()) {
385 tmp[part].push_back (LRID);
398 Parts_[i].resize (tmp[i].size ());
399 for (
size_t j = 0; j < tmp[i].size (); ++j) {
407template<
class GraphType>
414template<
class GraphType>
418 Teuchos::FancyOStream fos (Teuchos::rcpFromRef (os));
419 fos.setOutputToRootOnly (0);
425template<
class GraphType>
428 std::ostringstream oss;
429 oss << Teuchos::Describable::description();
431 oss <<
"{status = computed";
434 oss <<
"{status = is not computed";
441template<
class GraphType>
445 if (verbLevel == Teuchos::VERB_NONE) {
449 os <<
"================================================================================" << endl;
450 os <<
"Ifpack2::OverlappingPartitioner" << endl;
451 os <<
"Number of local rows = " <<
Graph_->getLocalNumRows() << endl;
452 os <<
"Number of global rows = " <<
Graph_->getGlobalNumRows() << endl;
456 os <<
"================================================================================" << endl;
461#define IFPACK2_OVERLAPPINGPARTITIONER_INSTANT(LO,GO,N) \
462 template class Ifpack2::OverlappingPartitioner<Tpetra::CrsGraph< LO, GO, N > >; \
463 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:145
size_t numRowsInPart(const local_ordinal_type Part) const
the number of rows contained in the given partition.
Definition Ifpack2_OverlappingPartitioner_def.hpp:91
OverlappingPartitioner(const Teuchos::RCP< const row_graph_type > &graph)
Constructor.
Definition Ifpack2_OverlappingPartitioner_def.hpp:24
bool verbose_
If true, information are reported to stdout.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:164
virtual std::ostream & print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
Definition Ifpack2_OverlappingPartitioner_def.hpp:416
virtual void compute()
Computes the partitions. Returns 0 if successful.
Definition Ifpack2_OverlappingPartitioner_def.hpp:167
virtual void setParameters(Teuchos::ParameterList &List)
Set all the parameters for the partitioner.
Definition Ifpack2_OverlappingPartitioner_def.hpp:127
virtual bool isComputed() const
Returns true if partitions have been computed successfully.
Definition Ifpack2_OverlappingPartitioner_def.hpp:408
int OverlappingLevel_
Level of overlap.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:158
virtual void computeOverlappingPartitions()
Computes the partitions. Returns 0 if successful.
Definition Ifpack2_OverlappingPartitioner_def.hpp:219
int numLocalParts() const
Number of computed local partitions.
Definition Ifpack2_OverlappingPartitioner_def.hpp:40
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:442
Teuchos::RCP< const row_graph_type > Graph_
The graph to be partitioned.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:155
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:161
Teuchos::Array< Teuchos::ArrayRCP< local_ordinal_type > > Parts_
Mapping from partition to all rows it contains.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:152
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:105
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:47
int NumLocalParts_
Number of local subgraphs.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:138
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:170
virtual ~OverlappingPartitioner()
Destructor.
Definition Ifpack2_OverlappingPartitioner_def.hpp:35
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:118
std::string description() const
Return a simple one-line description of this object.
Definition Ifpack2_OverlappingPartitioner_def.hpp:426
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:56
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:41