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>
73 return NumLocalParts_;
77 template<
class GraphType>
80 return OverlappingLevel_;
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 <<
".");
95 return Partition_[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(
106 i < 0 || i > Teuchos::as<local_ordinal_type> (NumLocalParts_),
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 140 const size_t numRows = numRowsInPart (Part);
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>
151 return Partition_.view (0, Graph_->getNodeNumRows ());
155 template<
class GraphType>
160 NumLocalParts_ = List.get(
"partitioner: local parts", NumLocalParts_);
161 OverlappingLevel_ = List.get(
"partitioner: overlap", OverlappingLevel_);
162 verbose_ = List.get(
"partitioner: print level", verbose_);
164 if (NumLocalParts_ < 0) {
165 NumLocalParts_ = Graph_->getNodeNumRows() / (-NumLocalParts_);
167 if (NumLocalParts_ == 0) {
172 TEUCHOS_TEST_FOR_EXCEPTION(
173 NumLocalParts_ < 0 ||
174 Teuchos::as<size_t> (NumLocalParts_) > Graph_->getNodeNumRows(),
176 "Ifpack2::OverlappingPartitioner::setParameters: " 177 "Invalid NumLocalParts_ = " << NumLocalParts_ <<
".");
178 TEUCHOS_TEST_FOR_EXCEPTION(
179 OverlappingLevel_ < 0, std::runtime_error,
180 "Ifpack2::OverlappingPartitioner::setParameters: " 181 "Invalid OverlappingLevel_ = " << OverlappingLevel_ <<
".");
183 setPartitionParameters(List);
187 template<
class GraphType>
193 TEUCHOS_TEST_FOR_EXCEPTION(
194 NumLocalParts_ < 1 || OverlappingLevel_ < 0,
196 "Ifpack2::OverlappingPartitioner::compute: " 197 "Invalid NumLocalParts_ or OverlappingLevel_.");
201 const char printMsg[] =
"OverlappingPartitioner: ";
203 if (verbose_ && (Graph_->getComm()->getRank() == 0)) {
204 cout << printMsg <<
"Number of local parts = " 205 << NumLocalParts_ << endl;
206 cout << printMsg <<
"Approx. Number of global parts = " 207 << NumLocalParts_ * Graph_->getComm ()->getSize () << endl;
208 cout << printMsg <<
"Amount of overlap = " 209 << OverlappingLevel_ << endl;
213 Partition_.resize (Graph_->getNodeNumRows ());
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.");
229 computePartitions ();
232 computeOverlappingPartitions ();
239 template<
class GraphType>
244 if (Partition_.size() == 0)
247 const local_ordinal_type invalid =
248 Teuchos::OrdinalTraits<local_ordinal_type>::invalid();
254 std::vector<size_t> sizes;
255 sizes.resize (NumLocalParts_);
258 for (
int i = 0; i < NumLocalParts_; ++i) {
262 for (
size_t i = 0; i < Graph_->getNodeNumRows (); ++i) {
263 TEUCHOS_TEST_FOR_EXCEPTION(
264 Partition_[i] >= NumLocalParts_, std::runtime_error,
265 "Ifpack2::OverlappingPartitioner::computeOverlappingPartitions: " 266 "Partition_[i] > NumLocalParts_.");
269 if (Partition_[i] != invalid) {
270 sizes[Partition_[i]]++;
275 Parts_.resize (NumLocalParts_);
276 for (
int i = 0; i < NumLocalParts_; ++i) {
277 Parts_[i].resize (sizes[i]);
281 for (
int i = 0; i < NumLocalParts_; ++i) {
285 for (
size_t i = 0; i < Graph_->getNodeNumRows (); ++i) {
286 const local_ordinal_type part = Partition_[i];
287 if (part != invalid) {
288 const size_t count = sizes[part];
289 Parts_[part][count] = i;
295 if (OverlappingLevel_ == 0) {
300 for (
int level = 1; level <= OverlappingLevel_; ++level) {
301 std::vector<std::vector<size_t> > tmp;
302 tmp.resize (NumLocalParts_);
308 int MaxNumEntries_tmp = Graph_->getNodeMaxNumRowEntries();
309 Teuchos::Array<local_ordinal_type> Indices;
310 Indices.resize (MaxNumEntries_tmp);
312 for (
int part = 0; part < NumLocalParts_ ; ++part) {
313 for (
size_t i = 0; i < Teuchos::as<size_t> (Parts_[part].size ()); ++i) {
314 const local_ordinal_type LRID = Parts_[part][i];
317 Graph_->getLocalRowCopy (LRID, Indices (), NumIndices);
319 for (
size_t j = 0; j < NumIndices; ++j) {
321 const local_ordinal_type col = Indices[j];
322 if (Teuchos::as<size_t> (col) >= Graph_->getNodeNumRows ()) {
327 std::vector<size_t>::iterator where =
328 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (col));
330 if (where == tmp[part].end()) {
331 tmp[part].push_back (col);
336 std::vector<size_t>::iterator where =
337 std::find (tmp[part].begin (), tmp[part].end (), Teuchos::as<size_t> (LRID));
341 if (where == tmp[part].end ()) {
342 tmp[part].push_back (LRID);
352 for (
int i = 0; i < NumLocalParts_; ++i) {
353 Parts_[i].resize (tmp[i].size ());
354 for (
size_t j = 0; j < tmp[i].size (); ++j) {
355 Parts_[i][j] = tmp[i][j];
362 template<
class GraphType>
369 template<
class GraphType>
373 Teuchos::FancyOStream fos (Teuchos::rcpFromRef (os));
374 fos.setOutputToRootOnly (0);
380 template<
class GraphType>
383 std::ostringstream oss;
384 oss << Teuchos::Describable::description();
386 oss <<
"{status = computed";
389 oss <<
"{status = is not computed";
396 template<
class GraphType>
400 if (verbLevel == Teuchos::VERB_NONE) {
404 os <<
"================================================================================" << endl;
405 os <<
"Ifpack2::OverlappingPartitioner" << endl;
406 os <<
"Number of local rows = " << Graph_->getNodeNumRows() << endl;
407 os <<
"Number of global rows = " << Graph_->getGlobalNumRows() << endl;
408 os <<
"Number of local parts = " << NumLocalParts_ << endl;
409 os <<
"Overlapping level = " << OverlappingLevel_ << endl;
410 os <<
"Is computed = " << IsComputed_ << endl;
411 os <<
"================================================================================" << endl;
417 #define IFPACK2_OVERLAPPINGPARTITIONER_INSTANT(LO,GO,N) \ 418 template class Ifpack2::OverlappingPartitioner<Tpetra::CrsGraph< LO, GO, N > >; \ 419 template class Ifpack2::OverlappingPartitioner<Tpetra::RowGraph< LO, GO, N > >; 421 #endif // IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP virtual std::ostream & print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:371
size_t numRowsInPart(const local_ordinal_type Part) const
the number of rows contained in the given partition.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:122
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:381
OverlappingPartitioner(const Teuchos::RCP< const row_graph_type > &graph)
Constructor.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:56
virtual void computeOverlappingPartitions()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:240
int overlappingLevel() const
The number of levels of overlap.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:78
virtual ~OverlappingPartitioner()
Destructor.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:66
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
virtual void compute()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:188
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 bool isComputed() const
Returns true if partitions have been computed successfully.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:363
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:397
int numLocalParts() const
Number of computed local partitions.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:71
virtual void setParameters(Teuchos::ParameterList &List)
Set all the parameters for the partitioner.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:158
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
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72