43 #ifndef IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP
44 #define IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP
48 #include "Ifpack2_ConfigDefs.hpp"
49 #include "Ifpack2_OverlappingPartitioner_decl.hpp"
51 #include "Teuchos_ArrayRCP.hpp"
55 template<
class GraphType>
60 OverlappingLevel_ (0),
63 maintainSparsity_(false)
67 template<
class GraphType>
71 template<
class GraphType>
75 return NumLocalParts_;
79 template<
class GraphType>
82 return OverlappingLevel_;
86 template<
class GraphType>
87 typename GraphType::local_ordinal_type
92 MyRow < 0 || Teuchos::as<size_t> (MyRow) > Graph_->getLocalNumRows (),
94 "Ifpack2::OverlappingPartitioner::operator(): "
95 "Invalid local row index " << MyRow <<
".");
97 return Partition_[MyRow];
102 template<
class GraphType>
103 typename GraphType::local_ordinal_type
105 operator() (
const local_ordinal_type i,
const local_ordinal_type j)
const
108 i < 0 || i > Teuchos::as<local_ordinal_type> (NumLocalParts_),
110 "Ifpack2::OverlappingPartitioner::operator(): "
111 "Invalid local row index i=" << i <<
".");
113 j < 0 || j > Teuchos::as<local_ordinal_type> (Parts_[i].size ()),
115 "Ifpack2::OverlappingPartitioner::operator(): "
116 "Invalid node index j=" << j <<
".");
121 template<
class GraphType>
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 ();
135 template<
class GraphType>
142 const size_t numRows = numRowsInPart (Part);
143 for (
size_t i = 0; i < numRows; ++i) {
144 List[i] = Parts_[Part][i];
149 template<
class GraphType>
153 return Partition_.view (0, Graph_->getLocalNumRows ());
157 template<
class GraphType>
162 NumLocalParts_ = List.
get(
"partitioner: local parts", NumLocalParts_);
163 OverlappingLevel_ = List.
get(
"partitioner: overlap", OverlappingLevel_);
164 verbose_ = List.
get(
"partitioner: print level", verbose_);
165 maintainSparsity_ = List.
get(
"partitioner: maintain sparsity",
false);
172 import_type theImport = Graph_->getImporter();
173 if (theImport != Teuchos::null) List.
set< import_type >(
"theImport",theImport);
174 List.
set< map_type >(
"OverlapRowMap",Graph_->getRowMap());
176 if (NumLocalParts_ < 0) {
177 NumLocalParts_ = Graph_->getLocalNumRows() / (-NumLocalParts_);
179 if (NumLocalParts_ == 0) {
185 NumLocalParts_ < 0 ||
186 Teuchos::as<size_t> (NumLocalParts_) > Graph_->getLocalNumRows(),
188 "Ifpack2::OverlappingPartitioner::setParameters: "
189 "Invalid NumLocalParts_ = " << NumLocalParts_ <<
".");
191 OverlappingLevel_ < 0, std::runtime_error,
192 "Ifpack2::OverlappingPartitioner::setParameters: "
193 "Invalid OverlappingLevel_ = " << OverlappingLevel_ <<
".");
195 setPartitionParameters(List);
199 template<
class GraphType>
206 NumLocalParts_ < 1 || OverlappingLevel_ < 0,
208 "Ifpack2::OverlappingPartitioner::compute: "
209 "Invalid NumLocalParts_ or OverlappingLevel_.");
213 const char printMsg[] =
"OverlappingPartitioner: ";
215 if (verbose_ && (Graph_->getComm()->getRank() == 0)) {
216 cout << printMsg <<
"Number of local parts = "
217 << NumLocalParts_ << endl;
218 cout << printMsg <<
"Approx. Number of global parts = "
219 << NumLocalParts_ * Graph_->getComm ()->getSize () << endl;
220 cout << printMsg <<
"Amount of overlap = "
221 << OverlappingLevel_ << endl;
225 Partition_.resize (Graph_->getLocalNumRows ());
230 ! Graph_->isFillComplete (), std::runtime_error,
231 "Ifpack2::OverlappingPartitioner::compute: "
232 "The input graph must be fill complete.");
235 Graph_->getGlobalNumRows () != Graph_->getGlobalNumCols (),
237 "Ifpack2::OverlappingPartitioner::compute: "
238 "The input graph must be (globally) square.");
241 computePartitions ();
244 computeOverlappingPartitions ();
251 template<
class GraphType>
256 if (Partition_.size() == 0)
259 const local_ordinal_type invalid =
266 std::vector<size_t> sizes;
267 sizes.resize (NumLocalParts_);
270 for (
int i = 0; i < NumLocalParts_; ++i) {
274 for (
size_t i = 0; i < Graph_->getLocalNumRows (); ++i) {
276 Partition_[i] >= NumLocalParts_, std::runtime_error,
277 "Ifpack2::OverlappingPartitioner::computeOverlappingPartitions: "
278 "Partition_[i] > NumLocalParts_.");
281 if (Partition_[i] != invalid) {
282 sizes[Partition_[i]]++;
287 Parts_.resize (NumLocalParts_);
288 for (
int i = 0; i < NumLocalParts_; ++i) {
289 Parts_[i].resize (sizes[i]);
293 for (
int i = 0; i < NumLocalParts_; ++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];
301 Parts_[part][count] = i;
307 if (OverlappingLevel_ == 0) {
312 for (
int level = 1; level <= OverlappingLevel_; ++level) {
313 std::vector<std::vector<size_t> > tmp;
314 tmp.resize (NumLocalParts_);
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);
324 if (!maintainSparsity_) {
326 local_ordinal_type numLocalRows = Graph_->getLocalNumRows();
327 for (
int part = 0; part < NumLocalParts_ ; ++part) {
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);
371 for (
int part = 0; part < NumLocalParts_ ; ++part) {
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);
430 for (
int i = 0; i < NumLocalParts_; ++i) {
431 Parts_[i].resize (tmp[i].size ());
432 for (
size_t j = 0; j < tmp[i].size (); ++j) {
433 Parts_[i][j] = tmp[i][j];
440 template<
class GraphType>
447 template<
class GraphType>
458 template<
class GraphType>
461 std::ostringstream oss;
464 oss <<
"{status = computed";
467 oss <<
"{status = is not computed";
474 template<
class GraphType>
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;
486 os <<
"Number of local parts = " << NumLocalParts_ << endl;
487 os <<
"Overlapping level = " << OverlappingLevel_ << endl;
488 os <<
"Is computed = " << IsComputed_ << 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 > >;
498 #endif // IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP
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 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
T & get(const std::string &name, T def_value)
OverlappingPartitioner(const Teuchos::RCP< const row_graph_type > &graph)
Constructor.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:57
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
int overlappingLevel() const
The number of levels of overlap.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:80
int numLocalParts() const
Number of computed local partitions.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:73
virtual void computeOverlappingPartitions()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:252
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
virtual ~OverlappingPartitioner()
Destructor.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:68
virtual bool isComputed() const
Returns true if partitions have been computed successfully.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:441
virtual std::string description() const
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:459
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
virtual void compute()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:200
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
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
virtual void setParameters(Teuchos::ParameterList &List)
Set all the parameters for the partitioner.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:160
size_t numRowsInPart(const local_ordinal_type Part) const
the number of rows contained in the given partition.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:124