10 #ifndef IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP
11 #define IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP
15 #include "Ifpack2_ConfigDefs.hpp"
16 #include "Ifpack2_OverlappingPartitioner_decl.hpp"
18 #include "Teuchos_ArrayRCP.hpp"
22 template<
class GraphType>
27 OverlappingLevel_ (0),
30 maintainSparsity_(false)
34 template<
class GraphType>
38 template<
class GraphType>
42 return NumLocalParts_;
46 template<
class GraphType>
49 return OverlappingLevel_;
53 template<
class GraphType>
54 typename GraphType::local_ordinal_type
59 MyRow < 0 || Teuchos::as<size_t> (MyRow) > Graph_->getLocalNumRows (),
61 "Ifpack2::OverlappingPartitioner::operator(): "
62 "Invalid local row index " << MyRow <<
".");
64 return Partition_[MyRow];
69 template<
class GraphType>
70 typename GraphType::local_ordinal_type
72 operator() (
const local_ordinal_type i,
const local_ordinal_type j)
const
75 i < 0 || i > Teuchos::as<local_ordinal_type> (NumLocalParts_),
77 "Ifpack2::OverlappingPartitioner::operator(): "
78 "Invalid local row index i=" << i <<
".");
80 j < 0 || j > Teuchos::as<local_ordinal_type> (Parts_[i].size ()),
82 "Ifpack2::OverlappingPartitioner::operator(): "
83 "Invalid node index j=" << j <<
".");
88 template<
class GraphType>
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 ();
102 template<
class GraphType>
109 const size_t numRows = numRowsInPart (Part);
110 for (
size_t i = 0; i < numRows; ++i) {
111 List[i] = Parts_[Part][i];
116 template<
class GraphType>
120 return Partition_.view (0, Graph_->getLocalNumRows ());
124 template<
class GraphType>
129 NumLocalParts_ = List.
get(
"partitioner: local parts", NumLocalParts_);
130 OverlappingLevel_ = List.
get(
"partitioner: overlap", OverlappingLevel_);
131 verbose_ = List.
get(
"partitioner: print level", verbose_);
132 maintainSparsity_ = List.
get(
"partitioner: maintain sparsity",
false);
139 import_type theImport = Graph_->getImporter();
140 if (theImport != Teuchos::null) List.
set< import_type >(
"theImport",theImport);
141 List.
set< map_type >(
"OverlapRowMap",Graph_->getRowMap());
143 if (NumLocalParts_ < 0) {
144 NumLocalParts_ = Graph_->getLocalNumRows() / (-NumLocalParts_);
146 if (NumLocalParts_ == 0) {
152 NumLocalParts_ < 0 ||
153 Teuchos::as<size_t> (NumLocalParts_) > Graph_->getLocalNumRows(),
155 "Ifpack2::OverlappingPartitioner::setParameters: "
156 "Invalid NumLocalParts_ = " << NumLocalParts_ <<
".");
158 OverlappingLevel_ < 0, std::runtime_error,
159 "Ifpack2::OverlappingPartitioner::setParameters: "
160 "Invalid OverlappingLevel_ = " << OverlappingLevel_ <<
".");
162 setPartitionParameters(List);
166 template<
class GraphType>
173 NumLocalParts_ < 1 || OverlappingLevel_ < 0,
175 "Ifpack2::OverlappingPartitioner::compute: "
176 "Invalid NumLocalParts_ or OverlappingLevel_.");
180 const char printMsg[] =
"OverlappingPartitioner: ";
182 if (verbose_ && (Graph_->getComm()->getRank() == 0)) {
183 cout << printMsg <<
"Number of local parts = "
184 << NumLocalParts_ << endl;
185 cout << printMsg <<
"Approx. Number of global parts = "
186 << NumLocalParts_ * Graph_->getComm ()->getSize () << endl;
187 cout << printMsg <<
"Amount of overlap = "
188 << OverlappingLevel_ << endl;
192 Partition_.resize (Graph_->getLocalNumRows ());
197 ! Graph_->isFillComplete (), std::runtime_error,
198 "Ifpack2::OverlappingPartitioner::compute: "
199 "The input graph must be fill complete.");
202 Graph_->getGlobalNumRows () != Graph_->getGlobalNumCols (),
204 "Ifpack2::OverlappingPartitioner::compute: "
205 "The input graph must be (globally) square.");
208 computePartitions ();
211 computeOverlappingPartitions ();
218 template<
class GraphType>
223 if (Partition_.size() == 0)
226 const local_ordinal_type invalid =
233 std::vector<size_t> sizes;
234 sizes.resize (NumLocalParts_);
237 for (
int i = 0; i < NumLocalParts_; ++i) {
241 for (
size_t i = 0; i < Graph_->getLocalNumRows (); ++i) {
243 Partition_[i] >= NumLocalParts_, std::runtime_error,
244 "Ifpack2::OverlappingPartitioner::computeOverlappingPartitions: "
245 "Partition_[i] > NumLocalParts_.");
248 if (Partition_[i] != invalid) {
249 sizes[Partition_[i]]++;
254 Parts_.resize (NumLocalParts_);
255 for (
int i = 0; i < NumLocalParts_; ++i) {
256 Parts_[i].resize (sizes[i]);
260 for (
int i = 0; i < NumLocalParts_; ++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];
268 Parts_[part][count] = i;
274 if (OverlappingLevel_ == 0) {
279 for (
int level = 1; level <= OverlappingLevel_; ++level) {
280 std::vector<std::vector<size_t> > tmp;
281 tmp.resize (NumLocalParts_);
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);
291 if (!maintainSparsity_) {
293 local_ordinal_type numLocalRows = Graph_->getLocalNumRows();
294 for (
int part = 0; part < NumLocalParts_ ; ++part) {
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);
338 for (
int part = 0; part < NumLocalParts_ ; ++part) {
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);
397 for (
int i = 0; i < NumLocalParts_; ++i) {
398 Parts_[i].resize (tmp[i].size ());
399 for (
size_t j = 0; j < tmp[i].size (); ++j) {
400 Parts_[i][j] = tmp[i][j];
407 template<
class GraphType>
414 template<
class GraphType>
425 template<
class GraphType>
428 std::ostringstream oss;
431 oss <<
"{status = computed";
434 oss <<
"{status = is not computed";
441 template<
class GraphType>
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;
453 os <<
"Number of local parts = " << NumLocalParts_ << endl;
454 os <<
"Overlapping level = " << OverlappingLevel_ << endl;
455 os <<
"Is computed = " << IsComputed_ << 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 > >;
465 #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:105
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
T & get(const std::string &name, T def_value)
OverlappingPartitioner(const Teuchos::RCP< const row_graph_type > &graph)
Constructor.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:24
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
int overlappingLevel() const
The number of levels of overlap.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:47
int numLocalParts() const
Number of computed local partitions.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:40
virtual void computeOverlappingPartitions()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:219
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
virtual ~OverlappingPartitioner()
Destructor.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:35
virtual bool isComputed() const
Returns true if partitions have been computed successfully.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:408
virtual std::string description() const
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:426
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
virtual void compute()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:167
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
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
virtual void setParameters(Teuchos::ParameterList &List)
Set all the parameters for the partitioner.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:127
size_t numRowsInPart(const local_ordinal_type Part) const
the number of rows contained in the given partition.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:91