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) {}
32 template <
class GraphType>
35 template <
class GraphType>
37 return NumLocalParts_;
40 template <
class GraphType>
42 return OverlappingLevel_;
45 template <
class GraphType>
46 typename GraphType::local_ordinal_type
50 MyRow < 0 || Teuchos::as<size_t>(MyRow) > Graph_->getLocalNumRows(),
52 "Ifpack2::OverlappingPartitioner::operator(): "
53 "Invalid local row index "
56 return Partition_[MyRow];
60 template <
class GraphType>
61 typename GraphType::local_ordinal_type
63 operator()(
const local_ordinal_type i,
const local_ordinal_type j)
const {
65 i < 0 || i > Teuchos::as<local_ordinal_type>(NumLocalParts_),
67 "Ifpack2::OverlappingPartitioner::operator(): "
68 "Invalid local row index i="
71 j < 0 || j > Teuchos::as<local_ordinal_type>(Parts_[i].size()),
73 "Ifpack2::OverlappingPartitioner::operator(): "
74 "Invalid node index j="
80 template <
class GraphType>
85 Part < 0 || Part > Teuchos::as<local_ordinal_type>(NumLocalParts_),
87 "Ifpack2::OverlappingPartitioner::numRowsInPart: "
88 "Invalid partition index Part="
90 return Parts_[Part].size();
94 template <
class GraphType>
99 const size_t numRows = numRowsInPart(Part);
100 for (
size_t i = 0; i < numRows; ++i) {
101 List[i] = Parts_[Part][i];
106 template <
class GraphType>
109 return Partition_.view(0, Graph_->getLocalNumRows());
113 template <
class GraphType>
116 NumLocalParts_ = List.
get(
"partitioner: local parts", NumLocalParts_);
117 OverlappingLevel_ = List.
get(
"partitioner: overlap", OverlappingLevel_);
118 verbose_ = List.
get(
"partitioner: print level", verbose_);
119 maintainSparsity_ = List.
get(
"partitioner: maintain sparsity",
false);
126 import_type theImport = Graph_->getImporter();
127 if (theImport != Teuchos::null) List.
set<import_type>(
"theImport", theImport);
128 List.
set<map_type>(
"OverlapRowMap", Graph_->getRowMap());
130 if (NumLocalParts_ < 0) {
131 NumLocalParts_ = Graph_->getLocalNumRows() / (-NumLocalParts_);
133 if (NumLocalParts_ == 0) {
139 NumLocalParts_ < 0 ||
140 Teuchos::as<size_t>(NumLocalParts_) > Graph_->getLocalNumRows(),
142 "Ifpack2::OverlappingPartitioner::setParameters: "
143 "Invalid NumLocalParts_ = "
144 << NumLocalParts_ <<
".");
146 OverlappingLevel_ < 0, std::runtime_error,
147 "Ifpack2::OverlappingPartitioner::setParameters: "
148 "Invalid OverlappingLevel_ = "
149 << OverlappingLevel_ <<
".");
151 setPartitionParameters(List);
155 template <
class GraphType>
161 NumLocalParts_ < 1 || OverlappingLevel_ < 0,
163 "Ifpack2::OverlappingPartitioner::compute: "
164 "Invalid NumLocalParts_ or OverlappingLevel_.");
168 const char printMsg[] =
"OverlappingPartitioner: ";
170 if (verbose_ && (Graph_->getComm()->getRank() == 0)) {
171 cout << printMsg <<
"Number of local parts = "
172 << NumLocalParts_ << endl;
173 cout << printMsg <<
"Approx. Number of global parts = "
174 << NumLocalParts_ * Graph_->getComm()->getSize() << endl;
175 cout << printMsg <<
"Amount of overlap = "
176 << OverlappingLevel_ << endl;
180 Partition_.resize(Graph_->getLocalNumRows());
185 !Graph_->isFillComplete(), std::runtime_error,
186 "Ifpack2::OverlappingPartitioner::compute: "
187 "The input graph must be fill complete.");
190 Graph_->getGlobalNumRows() != Graph_->getGlobalNumCols(),
192 "Ifpack2::OverlappingPartitioner::compute: "
193 "The input graph must be (globally) square.");
199 computeOverlappingPartitions();
206 template <
class GraphType>
210 if (Partition_.size() == 0)
213 const local_ordinal_type invalid =
220 std::vector<size_t> sizes;
221 sizes.resize(NumLocalParts_);
224 for (
int i = 0; i < NumLocalParts_; ++i) {
228 for (
size_t i = 0; i < Graph_->getLocalNumRows(); ++i) {
230 Partition_[i] >= NumLocalParts_, std::runtime_error,
231 "Ifpack2::OverlappingPartitioner::computeOverlappingPartitions: "
232 "Partition_[i] > NumLocalParts_.");
235 if (Partition_[i] != invalid) {
236 sizes[Partition_[i]]++;
241 Parts_.resize(NumLocalParts_);
242 for (
int i = 0; i < NumLocalParts_; ++i) {
243 Parts_[i].resize(sizes[i]);
247 for (
int i = 0; i < NumLocalParts_; ++i) {
251 for (
size_t i = 0; i < Graph_->getLocalNumRows(); ++i) {
252 const local_ordinal_type part = Partition_[i];
253 if (part != invalid) {
254 const size_t count = sizes[part];
255 Parts_[part][count] = i;
261 if (OverlappingLevel_ == 0) {
266 for (
int level = 1; level <= OverlappingLevel_; ++level) {
267 std::vector<std::vector<size_t> > tmp;
268 tmp.resize(NumLocalParts_);
274 int MaxNumEntries_tmp = Graph_->getLocalMaxNumRowEntries();
275 nonconst_local_inds_host_view_type Indices(
"Indices", MaxNumEntries_tmp);
276 nonconst_local_inds_host_view_type newIndices(
"newIndices", MaxNumEntries_tmp);
278 if (!maintainSparsity_) {
279 local_ordinal_type numLocalRows = Graph_->getLocalNumRows();
280 for (
int part = 0; part < NumLocalParts_; ++part) {
281 for (
size_t i = 0; i < Teuchos::as<size_t>(Parts_[part].size()); ++i) {
282 const local_ordinal_type LRID = Parts_[part][i];
285 Graph_->getLocalRowCopy(LRID, Indices, numIndices);
287 for (
size_t j = 0; j < numIndices; ++j) {
289 const local_ordinal_type col = Indices[j];
290 if (col >= numLocalRows) {
295 std::vector<size_t>::iterator where =
296 std::find(tmp[part].begin(), tmp[part].end(), Teuchos::as<size_t>(col));
298 if (where == tmp[part].end()) {
299 tmp[part].push_back(col);
309 std::vector<size_t>::iterator where =
310 std::find(tmp[part].begin(), tmp[part].end(), Teuchos::as<size_t>(LRID));
314 if (where == tmp[part].end()) {
315 tmp[part].push_back(LRID);
323 for (
int part = 0; part < NumLocalParts_; ++part) {
324 for (
size_t i = 0; i < Teuchos::as<size_t>(Parts_[part].size()); ++i) {
325 const local_ordinal_type LRID = Parts_[part][i];
328 Graph_->getLocalRowCopy(LRID, Indices, numIndices);
333 Tpetra::sort(Indices, numIndices);
335 for (
size_t j = 0; j < numIndices; ++j) {
337 const local_ordinal_type col = Indices[j];
338 if (Teuchos::as<size_t>(col) >= Graph_->getLocalNumRows()) {
343 std::vector<size_t>::iterator where =
344 std::find(tmp[part].begin(), tmp[part].end(), Teuchos::as<size_t>(col));
346 if (where == tmp[part].end()) {
349 size_t numNewIndices;
350 Graph_->getLocalRowCopy(col, newIndices, numNewIndices);
351 Tpetra::sort(newIndices, numNewIndices);
352 auto Indices_rcp = Kokkos::Compat::persistingView<nonconst_local_inds_host_view_type>(Indices, 0, numIndices);
353 auto newIndices_rcp = Kokkos::Compat::persistingView<nonconst_local_inds_host_view_type>(newIndices, 0, numNewIndices);
354 bool isSubset = std::includes(Indices_rcp.begin(), Indices_rcp.begin() + numIndices,
355 newIndices_rcp.begin(), newIndices_rcp.begin() + numNewIndices);
357 tmp[part].push_back(col);
363 std::vector<size_t>::iterator where =
364 std::find(tmp[part].begin(), tmp[part].end(), Teuchos::as<size_t>(LRID));
368 if (where == tmp[part].end()) {
369 tmp[part].push_back(LRID);
381 for (
int i = 0; i < NumLocalParts_; ++i) {
382 Parts_[i].resize(tmp[i].size());
383 for (
size_t j = 0; j < tmp[i].size(); ++j) {
384 Parts_[i][j] = tmp[i][j];
391 template <
class GraphType>
397 template <
class GraphType>
407 template <
class GraphType>
409 std::ostringstream oss;
412 oss <<
"{status = computed";
414 oss <<
"{status = is not computed";
421 template <
class GraphType>
428 os <<
"================================================================================" << endl;
429 os <<
"Ifpack2::OverlappingPartitioner" << endl;
430 os <<
"Number of local rows = " << Graph_->getLocalNumRows() << endl;
431 os <<
"Number of global rows = " << Graph_->getGlobalNumRows() << endl;
432 os <<
"Number of local parts = " << NumLocalParts_ << endl;
433 os <<
"Overlapping level = " << OverlappingLevel_ << endl;
434 os <<
"Is computed = " << IsComputed_ << endl;
435 os <<
"================================================================================" << endl;
440 #define IFPACK2_OVERLAPPINGPARTITIONER_INSTANT(LO, GO, N) \
441 template class Ifpack2::OverlappingPartitioner<Tpetra::CrsGraph<LO, GO, N> >; \
442 template class Ifpack2::OverlappingPartitioner<Tpetra::RowGraph<LO, GO, N> >;
444 #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:96
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:108
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:41
int numLocalParts() const
Number of computed local partitions.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:36
virtual void computeOverlappingPartitions()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:207
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:422
virtual ~OverlappingPartitioner()
Destructor.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:33
virtual bool isComputed() const
Returns true if partitions have been computed successfully.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:392
virtual std::string description() const
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:408
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
virtual void compute()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:156
virtual std::ostream & print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:399
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:48
virtual void setParameters(Teuchos::ParameterList &List)
Set all the parameters for the partitioner.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:115
size_t numRowsInPart(const local_ordinal_type Part) const
the number of rows contained in the given partition.
Definition: Ifpack2_OverlappingPartitioner_def.hpp:83