43 #ifndef IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP
44 #define IFPACK2_OVERLAPPINGPARTITIONER_DEF_HPP
45 #include "Ifpack2_ConfigDefs.hpp"
46 #include "Ifpack2_OverlappingPartitioner_decl.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
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
108 std::runtime_error,
"Ifpack2::OverlappingPartitioner::numRowsInPart() invalid partition.");
109 return(Parts_[Part].size());
113 template<
class GraphType>
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>
126 return(Partition_.view(0, Graph_->getNodeNumRows()));
130 template<
class GraphType>
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)
144 std::runtime_error,
"Ifpack2::OverlappingPartitioner::setParameters() invalid NumLocalParts_");
146 std::runtime_error,
"Ifpack2::OverlappingPartitioner::setParameters() invalid OverlappingLevel_");
148 setPartitionParameters(List);
152 template<
class GraphType>
153 void OverlappingPartitioner<GraphType>::compute()
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_);
174 std::runtime_error,
"Ifpack2::OverlappingPartitioner::compute() input graph error");
180 computeOverlappingPartitions();
187 template<
class GraphType>
188 void OverlappingPartitioner<GraphType>::computeOverlappingPartitions()
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) {
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();
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
293 fos.setOutputToRootOnly(0);
299 template<
class GraphType>
300 std::string OverlappingPartitioner<GraphType>::description()
const
302 std::ostringstream oss;
305 oss <<
"{status = computed";
308 oss <<
"{status = is not computed";
315 template<
class GraphType>
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
T & get(const std::string &name, T def_value)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual std::string description() const
void resize(size_type new_size, const value_type &x=value_type())