43 #ifndef IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP 44 #define IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP 45 #include "Ifpack2_ConfigDefs.hpp" 46 #include "Ifpack2_OverlappingPartitioner_decl.hpp" 47 #include "Teuchos_Array.hpp" 48 #include "Teuchos_ArrayRCP.hpp" 54 template<
class GraphType>
59 OverlappingLevel_ (0),
65 template<
class GraphType>
69 template<
class GraphType>
77 template<
class GraphType>
84 template<
class GraphType>
85 typename GraphType::local_ordinal_type
89 TEUCHOS_TEST_FOR_EXCEPTION(
90 MyRow < 0 || Teuchos::as<size_t> (MyRow) >
Graph_->getNodeNumRows (),
92 "Ifpack2::OverlappingPartitioner::operator(): " 93 "Invalid local row index " << MyRow <<
".");
100 template<
class GraphType>
101 typename GraphType::local_ordinal_type
103 operator() (
const local_ordinal_type i,
const local_ordinal_type j)
const 105 TEUCHOS_TEST_FOR_EXCEPTION(
108 "Ifpack2::OverlappingPartitioner::operator(): " 109 "Invalid local row index i=" << i <<
".");
110 TEUCHOS_TEST_FOR_EXCEPTION(
111 j < 0 || j > Teuchos::as<local_ordinal_type> (
Parts_[i].size ()),
113 "Ifpack2::OverlappingPartitioner::operator(): " 114 "Invalid node index j=" << j <<
".");
119 template<
class GraphType>
124 TEUCHOS_TEST_FOR_EXCEPTION(
125 Part < 0 || Part > Teuchos::as<local_ordinal_type> (
NumLocalParts_),
127 "Ifpack2::OverlappingPartitioner::numRowsInPart: " 128 "Invalid partition index Part=" << Part <<
".");
129 return Parts_[Part].size ();
133 template<
class GraphType>
137 Teuchos::ArrayRCP<local_ordinal_type>& List)
const 141 for (
size_t i = 0; i < numRows; ++i) {
142 List[i] =
Parts_[Part][i];
147 template<
class GraphType>
148 Teuchos::ArrayView<const typename GraphType::local_ordinal_type>
155 template<
class GraphType>
172 TEUCHOS_TEST_FOR_EXCEPTION(
176 "Ifpack2::OverlappingPartitioner::setParameters: " 178 TEUCHOS_TEST_FOR_EXCEPTION(
180 "Ifpack2::OverlappingPartitioner::setParameters: " 187 template<
class GraphType>
193 TEUCHOS_TEST_FOR_EXCEPTION(
196 "Ifpack2::OverlappingPartitioner::compute: " 197 "Invalid NumLocalParts_ or OverlappingLevel_.");
201 const char printMsg[] =
"OverlappingPartitioner: ";
204 cout << printMsg <<
"Number of local parts = " 206 cout << printMsg <<
"Approx. Number of global parts = " 208 cout << printMsg <<
"Amount of overlap = " 217 TEUCHOS_TEST_FOR_EXCEPTION(
218 !
Graph_->isFillComplete (), std::runtime_error,
219 "Ifpack2::OverlappingPartitioner::compute: " 220 "The input graph must be fill complete.");
222 TEUCHOS_TEST_FOR_EXCEPTION(
223 Graph_->getGlobalNumRows () !=
Graph_->getGlobalNumCols (),
225 "Ifpack2::OverlappingPartitioner::compute: " 226 "The input graph must be (globally) square.");
239 template<
class GraphType>
242 const local_ordinal_type invalid =
243 Teuchos::OrdinalTraits<local_ordinal_type>::invalid();
249 std::vector<size_t> sizes;
257 for (
size_t i = 0; i <
Graph_->getNodeNumRows (); ++i) {
258 TEUCHOS_TEST_FOR_EXCEPTION(
259 Partition_[i] >= NumLocalParts_, std::runtime_error,
260 "Ifpack2::OverlappingPartitioner::computeOverlappingPartitions: " 261 "Partition_[i] > NumLocalParts_.");
271 Parts_[i].resize (sizes[i]);
279 for (
size_t i = 0; i <
Graph_->getNodeNumRows (); ++i) {
280 const local_ordinal_type part =
Partition_[i];
281 if (part != invalid) {
282 const size_t count = sizes[part];
295 std::vector<std::vector<size_t> > tmp;
296 tmp.resize (NumLocalParts_);
302 int MaxNumEntries_tmp =
Graph_->getNodeMaxNumRowEntries();
303 Teuchos::Array<local_ordinal_type> Indices;
304 Indices.resize (MaxNumEntries_tmp);
307 for (
size_t i = 0; i < Teuchos::as<size_t> (
Parts_[part].size ()); ++i) {
308 const local_ordinal_type LRID =
Parts_[part][i];
311 Graph_->getLocalRowCopy (LRID, Indices (), NumIndices);
313 for (
size_t j = 0; j < NumIndices; ++j) {
315 const local_ordinal_type col = Indices[j];
316 if (Teuchos::as<size_t> (col) >=
Graph_->getNodeNumRows ()) {
321 std::vector<size_t>::iterator where =
322 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (col));
324 if (where == tmp[part].end()) {
325 tmp[part].push_back (col);
330 std::vector<size_t>::iterator where =
331 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (LRID));
335 if (where == tmp[part].end ()) {
336 tmp[part].push_back (LRID);
347 Parts_[i].resize (tmp[i].size ());
348 for (
size_t j = 0; j < tmp[i].size (); ++j) {
356 template<
class GraphType>
363 template<
class GraphType>
367 Teuchos::FancyOStream fos (Teuchos::rcpFromRef (os));
368 fos.setOutputToRootOnly (0);
374 template<
class GraphType>
377 std::ostringstream oss;
378 oss << Teuchos::Describable::description();
380 oss <<
"{status = computed";
383 oss <<
"{status = is not computed";
390 template<
class GraphType>
394 if (verbLevel == Teuchos::VERB_NONE) {
398 os <<
"================================================================================" << endl;
399 os <<
"Ifpack2::OverlappingPartitioner" << endl;
400 os <<
"Number of local rows = " <<
Graph_->getNodeNumRows() << endl;
401 os <<
"Number of global rows = " <<
Graph_->getGlobalNumRows() << endl;
405 os <<
"================================================================================" << endl;
411 #define IFPACK2_OVERLAPPINGPARTITIONER_INSTANT(LO,GO,N) \ 412 template class Ifpack2::OverlappingPartitioner<Tpetra::CrsGraph< LO, GO, N > >; \ 413 template class Ifpack2::OverlappingPartitioner<Tpetra::RowGraph< LO, GO, N > >; 415 #endif // IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP Teuchos::Array< local_ordinal_type > Partition_
Definition: Ifpack2_OverlappingPartitioner_decl.hpp:171
Teuchos::Array< Teuchos::ArrayRCP< local_ordinal_type > > Parts_
Definition: Ifpack2_OverlappingPartitioner_decl.hpp:175
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:136
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:149
OverlappingPartitioner(const Teuchos::RCP< const row_graph_type > &graph)
Constructor.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:56
int OverlappingLevel_
Level of overlap.
Definition: Ifpack2_OverlappingPartitioner_decl.hpp:181
int overlappingLevel() const
The number of levels of overlap.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:78
int numLocalParts() const
Number of computed local partitions.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:71
Teuchos::RCP< const row_graph_type > Graph_
The graph to be partitioned.
Definition: Ifpack2_OverlappingPartitioner_decl.hpp:178
virtual void computeOverlappingPartitions()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:240
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:391
virtual ~OverlappingPartitioner()
Destructor.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:66
virtual bool isComputed() const
Returns true if partitions have been computed successfully.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:357
int NumLocalParts_
Number of local subgraphs.
Definition: Ifpack2_OverlappingPartitioner_decl.hpp:167
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:375
virtual void computePartitions()=0
Computes the partitions. Returns 0 if successful.
virtual void compute()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:188
virtual std::ostream & print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:365
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:87
bool verbose_
If true, information are reported to stdout.
Definition: Ifpack2_OverlappingPartitioner_decl.hpp:187
virtual void setParameters(Teuchos::ParameterList &List)
Set all the parameters for the partitioner.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:158
size_t numRowsInPart(const local_ordinal_type Part) const
the number of rows contained in the given partition.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:122
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
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:184