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);
120 typedef Teuchos::RCP<Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type>
const> map_type;
121 typedef Teuchos::RCP<Tpetra::Import<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type>
const> import_type;
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) {
138 TEUCHOS_TEST_FOR_EXCEPTION(
139 NumLocalParts_ < 0 ||
140 Teuchos::as<size_t>(NumLocalParts_) > Graph_->getLocalNumRows(),
142 "Ifpack2::OverlappingPartitioner::setParameters: "
143 "Invalid NumLocalParts_ = "
144 << NumLocalParts_ <<
".");
145 TEUCHOS_TEST_FOR_EXCEPTION(
146 OverlappingLevel_ < 0, std::runtime_error,
147 "Ifpack2::OverlappingPartitioner::setParameters: "
148 "Invalid OverlappingLevel_ = "
149 << OverlappingLevel_ <<
".");
151 setPartitionParameters(List);
160 TEUCHOS_TEST_FOR_EXCEPTION(
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());
184 TEUCHOS_TEST_FOR_EXCEPTION(
185 !Graph_->isFillComplete(), std::runtime_error,
186 "Ifpack2::OverlappingPartitioner::compute: "
187 "The input graph must be fill complete.");
189 TEUCHOS_TEST_FOR_EXCEPTION(
190 Graph_->getGlobalNumRows() != Graph_->getGlobalNumCols(),
192 "Ifpack2::OverlappingPartitioner::compute: "
193 "The input graph must be (globally) square.");
199 computeOverlappingPartitions();
210 if (Partition_.size() == 0)
213 const local_ordinal_type invalid =
214 Teuchos::OrdinalTraits<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) {
229 TEUCHOS_TEST_FOR_EXCEPTION(
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];