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>
55 OverlappingPartitioner<GraphType>::OverlappingPartitioner(
const Teuchos::RCP<
const Tpetra::RowGraph<LocalOrdinal,GlobalOrdinal,Node> >& Graph) :
65 template<
class GraphType>
66 OverlappingPartitioner<GraphType>::~OverlappingPartitioner()
71 template<
class GraphType>
72 typename GraphType::local_ordinal_type OverlappingPartitioner<GraphType>::numLocalParts()
const 74 return( NumLocalParts_);
78 template<
class GraphType>
79 size_t OverlappingPartitioner<GraphType>::overlappingLevel()
const 81 return(OverlappingLevel_);
85 template<
class GraphType>
86 typename GraphType::local_ordinal_type OverlappingPartitioner<GraphType>::operator() (LocalOrdinal MyRow)
const 88 TEUCHOS_TEST_FOR_EXCEPTION(((MyRow < 0) || ((
size_t)MyRow > Graph_->getNodeNumRows())), std::runtime_error,
"Ifpack2::OverlappingPartitioner::operator() invalid row.");
90 return(Partition_[MyRow]);
95 template<
class GraphType>
96 typename GraphType::local_ordinal_type OverlappingPartitioner<GraphType>::operator() (LocalOrdinal i, LocalOrdinal j)
const 98 TEUCHOS_TEST_FOR_EXCEPTION( ((i < 0) || ((i > NumLocalParts_) || (j < 0) || (j > Parts_[i].size()))),
99 std::runtime_error,
"Ifpack2::OverlappingPartitioner::operator() invalid row or node.");
100 return(Parts_[i][j]);
104 template<
class GraphType>
105 size_t OverlappingPartitioner<GraphType>::numRowsInPart(
const LocalOrdinal Part)
const 107 TEUCHOS_TEST_FOR_EXCEPTION( ((Part < 0) || (Part > NumLocalParts_)),
108 std::runtime_error,
"Ifpack2::OverlappingPartitioner::numRowsInPart() invalid partition.");
109 return(Parts_[Part].size());
113 template<
class GraphType>
114 void OverlappingPartitioner<GraphType>::rowsInPart(
const LocalOrdinal Part, Teuchos::ArrayRCP<LocalOrdinal> & List)
const 117 size_t numrows= numRowsInPart(Part);
118 for (
size_t i = 0 ; i < numrows; i++)
119 List[i] = Parts_[Part][i];
123 template<
class GraphType>
124 Teuchos::ArrayView<const typename GraphType::local_ordinal_type> OverlappingPartitioner<GraphType>::nonOverlappingPartition()
const 126 return(Partition_.view(0, Graph_->getNodeNumRows()));
130 template<
class GraphType>
131 void OverlappingPartitioner<GraphType>::setParameters(Teuchos::ParameterList& List)
133 NumLocalParts_ = List.get(
"partitioner: local parts", NumLocalParts_);
134 OverlappingLevel_ = List.get(
"partitioner: overlap", OverlappingLevel_);
135 verbose_ = List.get(
"partitioner: print level", verbose_);
137 if (NumLocalParts_ < 0)
138 NumLocalParts_ = Graph_->getNodeNumRows() / (-NumLocalParts_);
139 if (NumLocalParts_ == 0)
143 TEUCHOS_TEST_FOR_EXCEPTION( ((NumLocalParts_ < 0) || (
size_t)NumLocalParts_ > Graph_->getNodeNumRows()),
144 std::runtime_error,
"Ifpack2::OverlappingPartitioner::setParameters() invalid NumLocalParts_");
145 TEUCHOS_TEST_FOR_EXCEPTION( (OverlappingLevel_ < 0),
146 std::runtime_error,
"Ifpack2::OverlappingPartitioner::setParameters() invalid OverlappingLevel_");
148 setPartitionParameters(List);
152 template<
class GraphType>
153 void OverlappingPartitioner<GraphType>::compute()
155 TEUCHOS_TEST_FOR_EXCEPTION( ((NumLocalParts_ < 1) || (OverlappingLevel_ < 0)),
156 std::runtime_error,
"Ifpack2::OverlappingPartitioner::compute() invalid NumLocalParts_ or OverlappingLevel_");
158 std::string PrintMsg_(
"OverlappingPartitioner: ");
161 if (verbose_ && (Graph_->getComm()->getRank() == 0)) {
162 std::cout << PrintMsg_ <<
"Number of local parts = " << NumLocalParts_ << std::endl;
163 std::cout << PrintMsg_ <<
"Approx. Number of global parts = " 164 << NumLocalParts_ * Graph_->getComm()->getSize() << std::endl;
165 std::cout << PrintMsg_ <<
"Amount of overlap = " << OverlappingLevel_ << std::endl;
169 Partition_.resize(Graph_->getNodeNumRows());
170 Parts_.resize(NumLocalParts_);
173 TEUCHOS_TEST_FOR_EXCEPTION( (!Graph_->isFillComplete() || Graph_->getGlobalNumRows() != Graph_->getGlobalNumCols()),
174 std::runtime_error,
"Ifpack2::OverlappingPartitioner::compute() input graph error");
180 computeOverlappingPartitions();
187 template<
class GraphType>
188 void OverlappingPartitioner<GraphType>::computeOverlappingPartitions()
192 LocalOrdinal invalid = Teuchos::OrdinalTraits<LocalOrdinal>::invalid();
198 vector<size_t> sizes;
199 sizes.resize(NumLocalParts_);
202 for (
int i = 0 ; i < NumLocalParts_ ; ++i)
205 for (
size_t i = 0 ; i < Graph_->getNodeNumRows() ; ++i) {
206 TEUCHOS_TEST_FOR_EXCEPTION( (Partition_[i] >= NumLocalParts_),
207 std::runtime_error,
"Ifpack2::OverlappingPartitioner::computeOverlappingPartitions() Partition_[i] > NumLocalParts_");
210 if (Partition_[i] != invalid)
211 sizes[Partition_[i]]++;
215 for (
int i = 0 ; i < NumLocalParts_ ; ++i)
216 Parts_[i].resize(sizes[i]);
219 for (
int i = 0 ; i < NumLocalParts_ ; ++i)
222 for (
size_t i = 0 ; i < Graph_->getNodeNumRows() ; ++i) {
223 LocalOrdinal part = Partition_[i];
224 if (part != invalid){
225 size_t count = sizes[part];
226 Parts_[part][count] = i;
232 if (OverlappingLevel_ == 0)
return;
235 for (
size_t level = 1 ; level <= OverlappingLevel_ ; ++level) {
236 vector<vector<size_t> > tmp;
237 tmp.resize(NumLocalParts_);
243 int MaxNumEntries_tmp = Graph_->getNodeMaxNumRowEntries();
244 Teuchos::Array<LocalOrdinal> Indices;
245 Indices.resize(MaxNumEntries_tmp);
247 for (
int part = 0 ; part < NumLocalParts_ ; ++part) {
248 for (
size_t i = 0; i < (size_t)Parts_[part].size() ; ++i) {
249 LocalOrdinal LRID = Parts_[part][i];
250 tmp[part].push_back(LRID);
253 Graph_->getLocalRowCopy(LRID,Indices(),NumIndices);
255 for (
size_t j = 0 ; j < NumIndices ; ++j) {
257 LocalOrdinal col = Indices[j];
258 if ((
size_t)col >= Graph_->getNodeNumRows())
262 vector<size_t>::iterator
263 where = std::find(tmp[part].begin(), tmp[part].end(), (
size_t) col);
265 if (where == tmp[part].end()) {
266 tmp[part].push_back(col);
273 for (
int i = 0 ; i < NumLocalParts_ ; ++i) {
274 Parts_[i].resize(tmp[i].size());
275 for (
size_t j = 0 ; j < tmp[i].size() ; ++j)
276 Parts_[i][j] = tmp[i][j];
282 template<
class GraphType>
283 bool OverlappingPartitioner<GraphType>::isComputed()
const 289 template<
class GraphType>
290 std::ostream& OverlappingPartitioner<GraphType>::print(std::ostream& os)
const 292 Teuchos::FancyOStream fos(Teuchos::rcp(&os,
false));
293 fos.setOutputToRootOnly(0);
299 template<
class GraphType>
300 std::string OverlappingPartitioner<GraphType>::description()
const 302 std::ostringstream oss;
303 oss << Teuchos::Describable::description();
305 oss <<
"{status = computed";
308 oss <<
"{status = is not computed";
315 template<
class GraphType>
316 void OverlappingPartitioner<GraphType>::describe(Teuchos::FancyOStream &os,
const Teuchos::EVerbosityLevel verbLevel)
const 319 if(verbLevel==Teuchos::VERB_NONE)
return;
321 os <<
"================================================================================" << endl;
322 os <<
"Ifpack2::OverlappingPartitioner" << endl;
323 os <<
"Number of local rows = " << Graph_->getNodeNumRows() << endl;
324 os <<
"Number of global rows = " << Graph_->getGlobalNumRows() << endl;
325 os <<
"Number of local parts = " << NumLocalParts_ << endl;
326 os <<
"Overlapping level = " << OverlappingLevel_ << endl;
327 os <<
"Is computed = " << IsComputed_ << endl;
328 os <<
"================================================================================" << endl;
334 #endif // IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67