10#ifndef IFPACK2_CONTAINER_DEF_HPP
11#define IFPACK2_CONTAINER_DEF_HPP
14#include <Teuchos_Time.hpp>
20template <
class MatrixType>
22 const Teuchos::RCP<const row_matrix_type>& matrix,
23 const Teuchos::Array<Teuchos::Array<LO>>& partitions,
25 : inputMatrix_(matrix)
26 , inputCrsMatrix_(Teuchos::rcp_dynamic_cast<const crs_matrix_type>(inputMatrix_))
27 , inputBlockMatrix_(Teuchos::rcp_dynamic_cast<const block_crs_matrix_type>(inputMatrix_))
28 , pointIndexed_(pointIndexed)
29 , IsInitialized_(false)
30 , IsComputed_(false) {
32 using Teuchos::ArrayView;
51#ifdef HAVE_IFPACK2_DEBUG
55 Teuchos::ArrayView<const LO> blockRows =
getBlockRows(i);
57 LO row = blockRows[j];
62 TEUCHOS_TEST_FOR_EXCEPTION(
63 !rowMap.isNodeLocalElement(row),
64 std::invalid_argument,
65 "Ifpack2::Container: "
67 << rowMap.getComm()->getRank() <<
" of "
68 << rowMap.getComm()->getSize() <<
", in the given set of local row "
69 "indices blockRows = "
70 << Teuchos::toString(blockRows) <<
", the following "
71 "entries is not valid local row index on the calling process: "
78template <
class MatrixType>
82template <
class MatrixType>
83Teuchos::ArrayView<const typename MatrixType::local_ordinal_type>
85 return Teuchos::ArrayView<const LO>(&blockRows_[blockOffsets_[blockIndex]], blockSizes_[blockIndex]);
88template <
class MatrixType>
92 LO totalBlockRows = 0;
93 numBlocks_ = partitions.size();
94 blockSizes_.resize(numBlocks_);
95 blockOffsets_.resize(numBlocks_);
97 for (
int i = 0; i < numBlocks_; i++) {
98 LO rowsInBlock = partitions[i].size();
99 blockSizes_[i] = rowsInBlock;
100 blockOffsets_[i] = totalBlockRows;
101 totalBlockRows += rowsInBlock;
102 maxBlockSize_ = std::max(maxBlockSize_, rowsInBlock * scalarsPerRow_);
104 blockRows_.resize(totalBlockRows);
107 for (
int i = 0; i < numBlocks_; i++) {
108 for (
int j = 0; j < blockSizes_[i]; j++) {
109 blockRows_[iter++] = partitions[i][j];
114template <
class MatrixType>
116 if (Diag_.is_null()) {
117 Diag_ = rcp(
new vector_type(inputMatrix_->getDomainMap()));
118 inputMatrix_->getLocalDiagCopy(*Diag_);
122template <
class MatrixType>
124 return IsInitialized_;
127template <
class MatrixType>
132template <
class MatrixType>
134 applyMV(
const mv_type& X, mv_type& Y)
const {
135 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"Not implemented.");
138template <
class MatrixType>
141 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"Not implemented.");
144template <
class MatrixType>
150template <
class MatrixType>
152 SC dampingFactor, LO i)
const {
153 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"Not implemented.");
156template <
class MatrixType>
158 using STS = Teuchos::ScalarTraits<ISC>;
159 const ISC one = STS::one();
161 size_t numVecs = X.extent(1);
163 for (LO i = 0; i < numBlocks_; i++) {
165 if (blockSizes_[i] != 1 || hasBlockCrs_) {
166 if (blockSizes_[i] == 0)
168 apply(X, Y, i, Teuchos::NO_TRANS, dampingFactor, one);
171 LO LRID = blockRows_[blockOffsets_[i]];
173 auto diagView = Diag_->getLocalViewHost(Tpetra::Access::ReadOnly);
174 ISC d = one * (
static_cast<ISC
>(dampingFactor)) / diagView(LRID, 0);
175 for (
size_t nv = 0; nv < numVecs; nv++) {
177 Y(LRID, nv) += x * d;
183template <
class MatrixType>
184void Container<MatrixType>::DoOverlappingJacobi(ConstHostView X, HostView Y, ConstHostView W, SC dampingFactor,
bool nonsymScaling)
const {
185 using STS = Teuchos::ScalarTraits<SC>;
187 for (LO i = 0; i < numBlocks_; i++) {
189 if (blockSizes_[i] == 0)
191 if (blockSizes_[i] != 1) {
193 weightedApply(X, Y, W, i, Teuchos::NO_TRANS, dampingFactor, STS::one());
200 HostView tempo(
"", X.extent(0), X.extent(1));
201 size_t numVecs = X.extent(1);
202 LO bOffset = blockOffsets_[i];
203 for (LO ii = 0; ii < blockSizes_[i]; ii++) {
204 LO LRID = blockRows_[bOffset++];
205 for (
size_t jj = 0; jj < numVecs; jj++) tempo(LRID, jj) = X(LRID, jj) / W(LRID, 0);
207 weightedApply(tempo, Y, W, i, Teuchos::NO_TRANS, dampingFactor, STS::one());
211 const ISC one = STS::one();
212 size_t numVecs = X.extent(1);
213 LO LRID = blockRows_[blockOffsets_[i]];
215 auto diagView = Diag_->getLocalViewHost(Tpetra::Access::ReadOnly);
216 ISC recip = one / diagView(LRID, 0);
217 ISC wval = W(LRID, 0);
218 ISC combo = wval * recip;
219 ISC d = combo * (
static_cast<ISC
>(dampingFactor));
220 for (
size_t nv = 0; nv < numVecs; nv++) {
222 Y(LRID, nv) = x * d + Y(LRID, nv);
230template <
class MatrixType,
typename LocalScalarType>
233 SC dampingFactor, LO i)
const {
234 using Teuchos::ArrayView;
235 using STS = Teuchos::ScalarTraits<ISC>;
236 size_t numVecs = X.extent(1);
237 const ISC one = STS::one();
238 if (this->blockSizes_[i] == 0)
240 if (this->hasBlockCrs_ && !this->pointIndexed_) {
242 ArrayView<const LO> blockRows = this->getBlockRows(i);
243 const size_t localNumRows = this->blockSizes_[i];
244 using inds_type =
typename block_crs_matrix_type::local_inds_host_view_type;
245 using vals_type =
typename block_crs_matrix_type::values_host_view_type;
246 for (
size_t j = 0; j < localNumRows; j++) {
247 LO row = blockRows[j];
250 this->inputBlockMatrix_->getLocalRowView(row, colinds, values);
251 LO numEntries = (LO)colinds.size();
252 for (
size_t m = 0; m < numVecs; m++) {
253 for (
int localR = 0; localR < this->bcrsBlockSize_; localR++)
254 Resid(row * this->bcrsBlockSize_ + localR, m) = X(row * this->bcrsBlockSize_ + localR, m);
255 for (LO k = 0; k < numEntries; ++k) {
256 const LO col = colinds[k];
257 for (
int localR = 0; localR < this->bcrsBlockSize_; localR++) {
258 for (
int localC = 0; localC < this->bcrsBlockSize_; localC++) {
259 Resid(row * this->bcrsBlockSize_ + localR, m) -=
260 values[k * this->bcrsBlockSize_ * this->bcrsBlockSize_ + localR + localC * this->bcrsBlockSize_] * Y2(col * this->bcrsBlockSize_ + localC, m);
272 apply(Resid, Y2, i, Teuchos::NO_TRANS, dampingFactor, one);
273 }
else if (!this->hasBlockCrs_ && this->blockSizes_[i] == 1) {
276 LO LRID = this->blockOffsets_[i];
280 container_exec_space().fence();
281 auto localA = this->inputCrsMatrix_->getLocalMatrixHost();
282 using size_type =
typename crs_matrix_type::local_matrix_host_type::size_type;
283 const auto& rowmap = localA.graph.row_map;
284 const auto& entries = localA.graph.entries;
285 const auto& values = localA.values;
287 auto diagView = this->Diag_->getLocalViewHost(Tpetra::Access::ReadOnly);
288 ISC d = (
static_cast<ISC>(dampingFactor)) / diagView(LRID, 0);
289 for (
size_t m = 0; m < numVecs; m++) {
292 for (size_type k = rowmap(LRID); k < rowmap(LRID + 1); k++) {
293 const LO col = entries(k);
294 r -= values(k) * Y2(col, m);
300 }
else if (!this->inputCrsMatrix_.is_null() &&
301 std::is_same<typename crs_matrix_type::device_type::memory_space, Kokkos::HostSpace>::value) {
305 container_exec_space().fence();
306 auto localA = this->inputCrsMatrix_->getLocalMatrixHost();
307 using size_type =
typename crs_matrix_type::local_matrix_host_type::size_type;
308 const auto& rowmap = localA.graph.row_map;
309 const auto& entries = localA.graph.entries;
310 const auto& values = localA.values;
311 ArrayView<const LO> blockRows = this->getBlockRows(i);
312 for (
size_t j = 0; j < size_t(blockRows.size()); j++) {
313 const LO row = blockRows[j];
314 for (
size_t m = 0; m < numVecs; m++) {
316 for (size_type k = rowmap(row); k < rowmap(row + 1); k++) {
317 const LO col = entries(k);
318 r -= values(k) * Y2(col, m);
329 apply(Resid, Y2, i, Teuchos::NO_TRANS, dampingFactor, one);
333 ArrayView<const LO> blockRows = this->getBlockRows(i);
334 for (
size_t j = 0; j < size_t(blockRows.size()); j++) {
335 const LO row = blockRows[j];
336 auto rowView = getInputRowView(row);
337 for (
size_t m = 0; m < numVecs; m++) {
338 Resid(row, m) = X(row, m);
339 for (
size_t k = 0; k < rowView.size(); ++k) {
340 const LO col = rowView.ind(k);
341 Resid(row, m) -= rowView.val(k) * Y2(col, m);
351 apply(Resid, Y2, i, Teuchos::NO_TRANS, dampingFactor, one);
355template <
class MatrixType>
358 using Teuchos::Array;
359 using Teuchos::ArrayRCP;
360 using Teuchos::ArrayView;
364 using Teuchos::rcpFromRef;
367 auto numVecs = X.extent(1);
369 HostView Resid(
"", X.extent(0), X.extent(1));
370 for (LO i = 0; i < numBlocks_; i++) {
371 DoGSBlock(X, Y, Y2, Resid, dampingFactor, i);
374 auto numMyRows = inputMatrix_->getLocalNumRows();
375 for (
size_t m = 0; m < numVecs; ++m) {
376 for (
size_t i = 0; i < numMyRows * bcrsBlockSize_; ++i) {
383template <
class MatrixType>
384void Container<MatrixType>::
385 DoSGS(ConstHostView X, HostView Y, HostView Y2, SC dampingFactor)
const {
387 using Teuchos::Array;
388 using Teuchos::ArrayRCP;
389 using Teuchos::ArrayView;
394 using Teuchos::rcpFromRef;
395 auto numVecs = X.extent(1);
398 for (LO i = 0; i < numBlocks_; i++) {
399 DoGSBlock(X, Y, Y2, Resid, dampingFactor, i);
401 static_assert(std::is_signed<LO>::value,
402 "Local ordinal must be signed (unsigned breaks reverse iteration to 0)");
404 for (LO i = numBlocks_ - 1; i >= 0; --i) {
405 DoGSBlock(X, Y, Y2, Resid, dampingFactor, i);
408 auto numMyRows = inputMatrix_->getLocalNumRows();
409 for (
size_t m = 0; m < numVecs; ++m) {
410 for (
size_t i = 0; i < numMyRows * bcrsBlockSize_; ++i) {
417template <
class MatrixType>
418void Container<MatrixType>::
423 blockOffsets_.clear();
424 Diag_ = Teuchos::null;
429template <
class MatrixType,
class LocalScalarType>
432 const Teuchos::RCP<const row_matrix_type>& matrix,
433 const Teuchos::Array<Teuchos::Array<LO>>& partitions,
435 :
Container<MatrixType>(matrix, partitions, pointIndexed) {}
437template <
class MatrixType,
class LocalScalarType>
441template <
class MatrixType,
class LocalScalarType>
445template <
class MatrixType,
class LocalScalarType>
451 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"Not implemented.");
454template <
class MatrixType,
class LocalScalarType>
457 ConstHostView XView = X.getLocalViewHost(Tpetra::Access::ReadOnly);
458 HostView YView = Y.getLocalViewHost(Tpetra::Access::ReadWrite);
459 this->apply(XView, YView, 0);
462template <
class MatrixType,
class LocalScalarType>
466 vector_type& W)
const {
467 ConstHostView XView = X.getLocalViewHost(Tpetra::Access::ReadOnly);
468 HostView YView = Y.getLocalViewHost(Tpetra::Access::ReadWrite);
469 ConstHostView WView = W.getLocalViewHost(Tpetra::Access::ReadOnly);
470 weightedApply(XView, YView, WView, 0);
473template <
class MatrixType,
class LocalScalarType>
479template <
class MatrixType,
class LocalScalarType>
484 Teuchos::ETransp mode,
486 const LSC beta)
const {
487 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"Not implemented.");
490template <
class MatrixType,
class LocalScalarType>
491typename ContainerImpl<MatrixType, LocalScalarType>::LO
494 LO LO_INVALID = Teuchos::OrdinalTraits<LO>::invalid();
495 GO GO_INVALID = Teuchos::OrdinalTraits<GO>::invalid();
496 const map_type& globalRowMap = *(this->inputMatrix_->getRowMap());
497 const map_type& globalColMap = *(this->inputMatrix_->getColMap());
500 if (this->pointIndexed_) {
501 rowLID = row / this->bcrsBlockSize_;
502 dofOffset = row % this->bcrsBlockSize_;
504 GO diagGID = globalRowMap.getGlobalElement(rowLID);
505 TEUCHOS_TEST_FOR_EXCEPTION(
506 diagGID == GO_INVALID,
508 "Ifpack2::Container::translateRowToCol: "
510 << this->inputMatrix_->getRowMap()->getComm()->getRank() <<
", at least one row index in the set of local "
511 "row indices given to the constructor is not a valid local row index in "
512 "the input matrix's row Map on this process. This should be impossible "
513 "because the constructor checks for this case. Here is the complete set "
514 "of invalid local row indices: "
516 "Please report this bug to the Ifpack2 developers.");
518 LO colLID = globalColMap.getLocalElement(diagGID);
519 TEUCHOS_TEST_FOR_EXCEPTION(
520 colLID == LO_INVALID,
522 "Ifpack2::Container::translateRowToCol: "
524 << this->inputMatrix_->getRowMap()->getComm()->getRank() <<
", "
525 "at least one row index in the set of row indices given to the constructor "
526 "does not have a corresponding column index in the input matrix's column "
527 "Map. This probably means that the column(s) in question is/are empty on "
528 "this process, which would make the submatrix to extract structurally "
529 "singular. The invalid global column index is "
532 if (this->pointIndexed_)
533 return colLID * this->bcrsBlockSize_ + dofOffset;
537template <
class MatrixType,
class LocalScalarType>
539 apply(ConstHostView X,
542 Teuchos::ETransp mode,
545 using Teuchos::ArrayView;
558 TEUCHOS_TEST_FOR_EXCEPTION(
559 !this->IsComputed_, std::runtime_error,
560 "Ifpack2::Container::apply: "
561 "You must have called the compute() method before you may call apply(). "
562 "You may call the apply() method as many times as you want after calling "
563 "compute() once, but you must have called compute() at least once.");
565 const size_t numVecs = X.extent(1);
596 if (X_localBlocks_.size() == 0 || X.extent(1) != X_local_.extent(1)) {
598 X_localBlocks_.clear();
599 Y_localBlocks_.clear();
600 X_localBlocks_.reserve(this->numBlocks_);
601 Y_localBlocks_.reserve(this->numBlocks_);
603 X_local_ = HostViewLocal(
"X_local", this->blockRows_.size() * this->scalarsPerRow_, numVecs);
604 Y_local_ = HostViewLocal(
"Y_local", this->blockRows_.size() * this->scalarsPerRow_, numVecs);
608 for (
int i = 0; i < this->numBlocks_; i++) {
609 auto blockBounds = std::make_pair(this->blockOffsets_[i] * this->scalarsPerRow_,
610 (this->blockOffsets_[i] + this->blockSizes_[i]) * this->scalarsPerRow_);
611 X_localBlocks_.emplace_back(X_local_, blockBounds, Kokkos::ALL());
612 Y_localBlocks_.emplace_back(Y_local_, blockBounds, Kokkos::ALL());
616 const ArrayView<const LO> blockRows = this->getBlockRows(blockIndex);
618 if (this->scalarsPerRow_ == 1)
619 mvgs.gatherViewToView(X_localBlocks_[blockIndex], X, blockRows);
621 mvgs.gatherViewToViewBlock(X_localBlocks_[blockIndex], X, blockRows, this->scalarsPerRow_);
628 if (this->scalarsPerRow_ == 1)
629 mvgs.gatherViewToView(Y_localBlocks_[blockIndex], Y, blockRows);
631 mvgs.gatherViewToViewBlock(Y_localBlocks_[blockIndex], Y, blockRows, this->scalarsPerRow_);
635 this->solveBlock(X_localBlocks_[blockIndex], Y_localBlocks_[blockIndex], blockIndex, mode,
640 if (this->scalarsPerRow_ == 1)
641 mvgs.scatterViewToView(Y, Y_localBlocks_[blockIndex], blockRows);
643 mvgs.scatterViewToViewBlock(Y, Y_localBlocks_[blockIndex], blockRows, this->scalarsPerRow_);
646template <
class MatrixType,
class LocalScalarType>
652 Teuchos::ETransp mode,
656 using Teuchos::ArrayRCP;
657 using Teuchos::ArrayView;
660 using Teuchos::Range1D;
663 using Teuchos::rcp_const_cast;
664 using STS = Teuchos::ScalarTraits<SC>;
673 const char prefix[] =
"Ifpack2::Container::weightedApply: ";
674 TEUCHOS_TEST_FOR_EXCEPTION(
675 !this->IsComputed_, std::runtime_error, prefix <<
"You must have called the "
676 "compute() method before you may call this method. You may call "
677 "weightedApply() as many times as you want after calling compute() once, "
678 "but you must have called compute() at least once first.");
681 TEUCHOS_TEST_FOR_EXCEPTION(
682 this->scalarsPerRow_ > 1, std::logic_error, prefix <<
"Use of block rows isn't allowed "
683 "in overlapping Jacobi (the only method that uses weightedApply");
685 const size_t numVecs = X.extent(1);
687 TEUCHOS_TEST_FOR_EXCEPTION(
688 X.extent(1) != Y.extent(1), std::runtime_error,
689 prefix <<
"X and Y have different numbers of vectors (columns). X has "
690 << X.extent(1) <<
", but Y has " << Y.extent(1) <<
".");
696 const size_t numRows = this->blockSizes_[blockIndex];
721 if (X_localBlocks_.size() == 0 || X.extent(1) != X_local_.extent(1)) {
723 X_localBlocks_.clear();
724 Y_localBlocks_.clear();
725 X_localBlocks_.reserve(this->numBlocks_);
726 Y_localBlocks_.reserve(this->numBlocks_);
728 X_local_ = HostViewLocal(
"X_local", this->blockRows_.size() * this->scalarsPerRow_, numVecs);
729 Y_local_ = HostViewLocal(
"Y_local", this->blockRows_.size() * this->scalarsPerRow_, numVecs);
733 for (
int i = 0; i < this->numBlocks_; i++) {
734 auto blockBounds = std::make_pair(this->blockOffsets_[i] * this->scalarsPerRow_,
735 (this->blockOffsets_[i] + this->blockSizes_[i]) * this->scalarsPerRow_);
736 X_localBlocks_.emplace_back(X_local_, blockBounds, Kokkos::ALL());
737 Y_localBlocks_.emplace_back(Y_local_, blockBounds, Kokkos::ALL());
740 if (
int(weightedApplyScratch_.extent(0)) != 3 * this->maxBlockSize_ ||
741 weightedApplyScratch_.extent(1) != numVecs) {
742 weightedApplyScratch_ = HostViewLocal(
"weightedApply scratch", 3 * this->maxBlockSize_, numVecs);
745 ArrayView<const LO> blockRows = this->getBlockRows(blockIndex);
750 mvgs.gatherViewToView(X_localBlocks_[blockIndex], X, blockRows);
756 mvgs.gatherViewToView(Y_localBlocks_[blockIndex], Y, blockRows);
767 auto maxBS = this->maxBlockSize_;
768 auto bs = this->blockSizes_[blockIndex] * this->scalarsPerRow_;
770 HostSubviewLocal D_local(weightedApplyScratch_, std::make_pair(0, bs), std::make_pair(0, 1));
771 mvgs.gatherViewToView(D_local, D, blockRows);
772 HostSubviewLocal X_scaled(weightedApplyScratch_, std::make_pair(maxBS, maxBS + bs), Kokkos::ALL());
773 for (
size_t j = 0; j < numVecs; j++)
774 for (
size_t i = 0; i < numRows; i++)
775 X_scaled(i, j) = X_localBlocks_[blockIndex](i, j) * D_local(i, 0);
777 HostSubviewLocal Y_temp(weightedApplyScratch_, std::make_pair(maxBS * 2, maxBS * 2 + bs), Kokkos::ALL());
779 this->solveBlock(X_scaled, Y_temp, blockIndex, mode, STS::one(), STS::zero());
787 for (
size_t j = 0; j < numVecs; j++)
788 for (
size_t i = 0; i < numRows; i++)
789 Y_localBlocks_[blockIndex](i, j) = b * Y_localBlocks_[blockIndex](i, j) + a * Y_temp(i, j) * D_local(i, 0);
793 mvgs.scatterViewToView(Y, Y_localBlocks_[blockIndex], blockRows);
796template <
class MatrixType,
class LocalScalarType>
798 typename ContainerImpl<MatrixType, LocalScalarType>::SC,
799 typename ContainerImpl<MatrixType, LocalScalarType>::LO,
800 typename ContainerImpl<MatrixType, LocalScalarType>::GO,
801 typename ContainerImpl<MatrixType, LocalScalarType>::NO>
804 typedef typename MatrixType::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
805 typedef typename MatrixType::nonconst_values_host_view_type nonconst_values_host_view_type;
807 typedef typename MatrixType::local_inds_host_view_type local_inds_host_view_type;
808 typedef typename MatrixType::values_host_view_type values_host_view_type;
809 using IST =
typename row_matrix_type::impl_scalar_type;
811 if (this->hasBlockCrs_) {
812 using h_inds_type =
typename block_crs_matrix_type::local_inds_host_view_type;
813 using h_vals_type =
typename block_crs_matrix_type::values_host_view_type;
816 this->inputBlockMatrix_->getLocalRowView(row / this->bcrsBlockSize_, colinds, values);
817 size_t numEntries = colinds.size();
820 h_vals_type subvals = Kokkos::subview(values, std::pair<size_t, size_t>(row % this->bcrsBlockSize_, values.size()));
821 return StridedRowView(subvals, colinds, this->bcrsBlockSize_, numEntries * this->bcrsBlockSize_);
822 }
else if (!this->inputMatrix_->supportsRowViews()) {
823 size_t maxEntries = this->inputMatrix_->getLocalMaxNumRowEntries();
824 Teuchos::Array<LO> inds(maxEntries);
825 Teuchos::Array<SC> vals(maxEntries);
826 nonconst_local_inds_host_view_type inds_v(inds.data(), maxEntries);
827 nonconst_values_host_view_type vals_v(
reinterpret_cast<IST*
>(vals.data()), maxEntries);
829 this->inputMatrix_->getLocalRowCopy(row, inds_v, vals_v, numEntries);
830 vals.resize(numEntries);
831 inds.resize(numEntries);
835 local_inds_host_view_type colinds;
836 values_host_view_type values;
837 this->inputMatrix_->getLocalRowView(row, colinds, values);
842template <
class MatrixType,
class LocalScalarType>
845 X_localBlocks_.clear();
846 Y_localBlocks_.clear();
847 X_local_ = HostViewLocal();
848 Y_local_ = HostViewLocal();
855template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
860 , blockSize(blockSize_)
863template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
869 , nnz(
vals_.size()) {
870 valsCopy.swap(
vals_);
871 indsCopy.swap(
inds_);
874template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
876 val(
size_t i)
const {
877#ifdef HAVE_IFPACK2_DEBUG
879 "Out-of-bounds access into Ifpack2::Container::StridedRowView");
881 if (vals.size() > 0) {
885 return vals[
i * blockSize];
890template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
891LocalOrdinal StridedRowView<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
892 ind(
size_t i)
const {
893#ifdef HAVE_IFPACK2_DEBUG
894 TEUCHOS_TEST_FOR_EXCEPTION(i >= nnz, std::runtime_error,
895 "Out-of-bounds access into Ifpack2::Container::StridedRowView");
898 if (inds.size() > 0) {
902 return inds[i / blockSize] * blockSize + i % blockSize;
907template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
908size_t StridedRowView<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
916template <
class MatrixType>
918 return obj.
print(os);
921#define IFPACK2_CONTAINER_INSTANT(S, LO, GO, N) \
922 template class Ifpack2::Container<Tpetra::RowMatrix<S, LO, GO, N>>; \
923 template class Ifpack2::ContainerImpl<Tpetra::RowMatrix<S, LO, GO, N>, S>; \
924 template class Ifpack2::Details::StridedRowView<S, LO, GO, N>; \
925 template std::ostream& operator<< <Tpetra::RowMatrix<S, LO, GO, N>>( \
926 std::ostream& os, const Ifpack2::Container<Tpetra::RowMatrix<S, LO, GO, N>>& obj);
Declaration and definition of the Ifpack2::Details::MultiVectorLocalGatherScatter class.
The implementation of the numerical features of Container (Jacobi, Gauss-Seidel, SGS)....
Definition Ifpack2_Container_decl.hpp:311
LocalScalarType LSC
The internal representation of LocalScalarType in Kokkos::View.
Definition Ifpack2_Container_decl.hpp:330
void DoGSBlock(ConstHostView X, HostView Y, HostView Y2, HostView Resid, SC dampingFactor, LO i) const
Do one step of Gauss-Seidel on block i (used by DoGaussSeidel and DoSGS)
Definition Ifpack2_Container_def.hpp:231
Interface for creating and solving a set of local linear problems.
Definition Ifpack2_Container_decl.hpp:79
virtual ~Container()
Destructor.
Definition Ifpack2_Container_def.hpp:80
bool hasBlockCrs_
Whether the input matrix is a BlockCRS matrix.
Definition Ifpack2_Container_decl.hpp:279
bool IsParallel_
Whether the problem is distributed across multiple MPI processes.
Definition Ifpack2_Container_decl.hpp:271
int numBlocks_
The number of blocks (partitions) in the container.
Definition Ifpack2_Container_decl.hpp:261
Teuchos::ArrayView< const LO > getBlockRows(int blockIndex) const
Local indices of the rows of the input matrix that belong to this block.
Definition Ifpack2_Container_def.hpp:84
static std::string getName()
Definition Ifpack2_Container_def.hpp:146
typename Kokkos::ArithTraits< SC >::val_type ISC
Internal representation of Scalar in Kokkos::View.
Definition Ifpack2_Container_decl.hpp:104
int bcrsBlockSize_
If hasBlockCrs_, the number of DOFs per vertex. Otherwise 1.
Definition Ifpack2_Container_decl.hpp:281
Teuchos::RCP< const block_crs_matrix_type > inputBlockMatrix_
The input matrix, dynamic cast to BlockCrsMatrix. May be null.
Definition Ifpack2_Container_decl.hpp:258
virtual void DoGSBlock(ConstHostView X, HostView Y, HostView Y2, HostView Resid, SC dampingFactor, LO i) const
Do one step of Gauss-Seidel on block i (used by DoGaussSeidel and DoSGS)
Definition Ifpack2_Container_def.hpp:151
virtual void applyMV(const mv_type &X, mv_type &Y) const
Wrapper for apply with MultiVector.
Definition Ifpack2_Container_def.hpp:134
LO NumLocalRows_
Number of local rows in input matrix.
Definition Ifpack2_Container_decl.hpp:273
bool isInitialized() const
Whether the container has been successfully initialized.
Definition Ifpack2_Container_def.hpp:123
void setBlockSizes(const Teuchos::Array< Teuchos::Array< LO > > &partitions)
Initialize arrays with information about block sizes.
Definition Ifpack2_Container_def.hpp:89
LO scalarsPerRow_
Definition Ifpack2_Container_decl.hpp:286
Teuchos::Array< LO > blockSizes_
Number of rows in each block.
Definition Ifpack2_Container_decl.hpp:265
GO NumGlobalNonzeros_
Number of nonzeros in input matrix.
Definition Ifpack2_Container_decl.hpp:277
Container(const Teuchos::RCP< const row_matrix_type > &matrix, const Teuchos::Array< Teuchos::Array< LO > > &partitions, bool pointIndexed)
Constructor.
Definition Ifpack2_Container_def.hpp:21
virtual std::ostream & print(std::ostream &os) const =0
Print basic information about the container to os.
virtual void weightedApplyMV(const mv_type &X, mv_type &Y, vector_type &W) const
Wrapper for weightedApply with MultiVector.
Definition Ifpack2_Container_def.hpp:140
Teuchos::RCP< const row_matrix_type > inputMatrix_
The input matrix to the constructor.
Definition Ifpack2_Container_decl.hpp:252
bool pointIndexed_
(If hasBlockCrs_) Whether the blocks are described using sub-block row indices instead of full block ...
Definition Ifpack2_Container_decl.hpp:283
GO NumGlobalRows_
Number of global rows in input matrix.
Definition Ifpack2_Container_decl.hpp:275
bool isComputed() const
Whether the container has been successfully computed.
Definition Ifpack2_Container_def.hpp:128
typename mv_type::dual_view_type::t_host HostView
Definition Ifpack2_Container_decl.hpp:109
Ifpack2's implementation of Trilinos::Details::LinearSolver interface.
Definition Ifpack2_Details_LinearSolver_decl.hpp:75
Ifpack2 implementation details.
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40
Structure for read-only views of general matrix rows.
Definition Ifpack2_Container_decl.hpp:506
StridedRowView(h_vals_type vals_, h_inds_type inds_, int blockSize_, size_t nnz_)
Constructor for row views (preferred)
Definition Ifpack2_Container_def.hpp:857