10#ifndef IFPACK2_CONTAINER_DEF_HPP
11#define IFPACK2_CONTAINER_DEF_HPP
15#include <Teuchos_Time.hpp>
21template <
class MatrixType>
23 const Teuchos::RCP<const row_matrix_type>& matrix,
24 const Teuchos::Array<Teuchos::Array<LO>>& partitions,
26 : inputMatrix_(matrix)
27 , inputCrsMatrix_(Teuchos::rcp_dynamic_cast<const crs_matrix_type>(inputMatrix_))
28 , inputBlockMatrix_(Teuchos::rcp_dynamic_cast<const block_crs_matrix_type>(inputMatrix_))
29 , pointIndexed_(pointIndexed)
30 , IsInitialized_(false)
31 , IsComputed_(false) {
33 using Teuchos::ArrayView;
56 Teuchos::ArrayView<const LO> blockRows =
getBlockRows(i);
58 LO row = blockRows[j];
63 TEUCHOS_TEST_FOR_EXCEPTION(
64 !rowMap.isNodeLocalElement(row),
65 std::invalid_argument,
66 "Ifpack2::Container: "
68 << rowMap.getComm()->getRank() <<
" of "
69 << rowMap.getComm()->getSize() <<
", in the given set of local row "
70 "indices blockRows = "
71 << Teuchos::toString(blockRows) <<
", the following "
72 "entries is not valid local row index on the calling process: "
79template <
class MatrixType>
83template <
class MatrixType>
84Teuchos::ArrayView<const typename MatrixType::local_ordinal_type>
86 return Teuchos::ArrayView<const LO>(&blockRows_[blockOffsets_[blockIndex]], blockSizes_[blockIndex]);
89template <
class MatrixType>
93 LO totalBlockRows = 0;
94 numBlocks_ = partitions.size();
95 blockSizes_.resize(numBlocks_);
96 blockOffsets_.resize(numBlocks_);
98 for (
int i = 0; i < numBlocks_; i++) {
99 LO rowsInBlock = partitions[i].size();
100 blockSizes_[i] = rowsInBlock;
101 blockOffsets_[i] = totalBlockRows;
102 totalBlockRows += rowsInBlock;
103 maxBlockSize_ = std::max(maxBlockSize_, rowsInBlock * scalarsPerRow_);
105 blockRows_.resize(totalBlockRows);
108 for (
int i = 0; i < numBlocks_; i++) {
109 for (
int j = 0; j < blockSizes_[i]; j++) {
110 blockRows_[iter++] = partitions[i][j];
115template <
class MatrixType>
117 if (Diag_.is_null()) {
118 Diag_ = rcp(
new vector_type(inputMatrix_->getDomainMap()));
119 inputMatrix_->getLocalDiagCopy(*Diag_);
123template <
class MatrixType>
125 return IsInitialized_;
128template <
class MatrixType>
133template <
class MatrixType>
135 applyMV(
const mv_type& X, mv_type& Y)
const {
136 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"Not implemented.");
139template <
class MatrixType>
142 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"Not implemented.");
145template <
class MatrixType>
151template <
class MatrixType>
153 SC dampingFactor, LO i)
const {
154 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"Not implemented.");
157template <
class MatrixType>
159 using STS = Teuchos::ScalarTraits<ISC>;
160 const ISC one = STS::one();
162 size_t numVecs = X.extent(1);
164 for (LO i = 0; i < numBlocks_; i++) {
166 if (blockSizes_[i] != 1 || hasBlockCrs_) {
167 if (blockSizes_[i] == 0)
169 apply(X, Y, i, Teuchos::NO_TRANS, dampingFactor, one);
172 LO LRID = blockRows_[blockOffsets_[i]];
174 auto diagView = Diag_->getLocalViewHost(Tpetra::Access::ReadOnly);
175 ISC d = one * (
static_cast<ISC
>(dampingFactor)) / diagView(LRID, 0);
176 for (
size_t nv = 0; nv < numVecs; nv++) {
178 Y(LRID, nv) += x * d;
184template <
class MatrixType>
185void Container<MatrixType>::DoOverlappingJacobi(ConstHostView X, HostView Y, ConstHostView W, SC dampingFactor,
bool nonsymScaling)
const {
186 using STS = Teuchos::ScalarTraits<SC>;
188 for (LO i = 0; i < numBlocks_; i++) {
190 if (blockSizes_[i] == 0)
192 if (blockSizes_[i] != 1) {
194 weightedApply(X, Y, W, i, Teuchos::NO_TRANS, dampingFactor, STS::one());
201 HostView tempo(
"", X.extent(0), X.extent(1));
202 size_t numVecs = X.extent(1);
203 LO bOffset = blockOffsets_[i];
204 for (LO ii = 0; ii < blockSizes_[i]; ii++) {
205 LO LRID = blockRows_[bOffset++];
206 for (
size_t jj = 0; jj < numVecs; jj++) tempo(LRID, jj) = X(LRID, jj) / W(LRID, 0);
208 weightedApply(tempo, Y, W, i, Teuchos::NO_TRANS, dampingFactor, STS::one());
212 const ISC one = STS::one();
213 size_t numVecs = X.extent(1);
214 LO LRID = blockRows_[blockOffsets_[i]];
216 auto diagView = Diag_->getLocalViewHost(Tpetra::Access::ReadOnly);
217 ISC recip = one / diagView(LRID, 0);
218 ISC wval = W(LRID, 0);
219 ISC combo = wval * recip;
220 ISC d = combo * (
static_cast<ISC
>(dampingFactor));
221 for (
size_t nv = 0; nv < numVecs; nv++) {
223 Y(LRID, nv) = x * d + Y(LRID, nv);
231template <
class MatrixType,
typename LocalScalarType>
234 SC dampingFactor, LO i)
const {
235 using Teuchos::ArrayView;
236 using STS = Teuchos::ScalarTraits<ISC>;
237 size_t numVecs = X.extent(1);
238 const ISC one = STS::one();
239 if (this->blockSizes_[i] == 0)
241 if (this->hasBlockCrs_ && !this->pointIndexed_) {
243 ArrayView<const LO> blockRows = this->getBlockRows(i);
244 const size_t localNumRows = this->blockSizes_[i];
245 using inds_type =
typename block_crs_matrix_type::local_inds_host_view_type;
246 using vals_type =
typename block_crs_matrix_type::values_host_view_type;
247 for (
size_t j = 0; j < localNumRows; j++) {
248 LO row = blockRows[j];
251 this->inputBlockMatrix_->getLocalRowView(row, colinds, values);
252 LO numEntries = (LO)colinds.size();
253 for (
size_t m = 0; m < numVecs; m++) {
254 for (
int localR = 0; localR < this->bcrsBlockSize_; localR++)
255 Resid(row * this->bcrsBlockSize_ + localR, m) = X(row * this->bcrsBlockSize_ + localR, m);
256 for (LO k = 0; k < numEntries; ++k) {
257 const LO col = colinds[k];
258 for (
int localR = 0; localR < this->bcrsBlockSize_; localR++) {
259 for (
int localC = 0; localC < this->bcrsBlockSize_; localC++) {
260 Resid(row * this->bcrsBlockSize_ + localR, m) -=
261 values[k * this->bcrsBlockSize_ * this->bcrsBlockSize_ + localR + localC * this->bcrsBlockSize_] * Y2(col * this->bcrsBlockSize_ + localC, m);
273 apply(Resid, Y2, i, Teuchos::NO_TRANS, dampingFactor, one);
274 }
else if (!this->hasBlockCrs_ && this->blockSizes_[i] == 1) {
277 LO LRID = this->blockOffsets_[i];
281 container_exec_space().fence();
282 auto localA = this->inputCrsMatrix_->getLocalMatrixHost();
283 using size_type =
typename crs_matrix_type::local_matrix_host_type::size_type;
284 const auto& rowmap = localA.graph.row_map;
285 const auto& entries = localA.graph.entries;
286 const auto& values = localA.values;
288 auto diagView = this->Diag_->getLocalViewHost(Tpetra::Access::ReadOnly);
289 ISC d = (
static_cast<ISC>(dampingFactor)) / diagView(LRID, 0);
290 for (
size_t m = 0; m < numVecs; m++) {
293 for (size_type k = rowmap(LRID); k < rowmap(LRID + 1); k++) {
294 const LO col = entries(k);
295 r -= values(k) * Y2(col, m);
301 }
else if (!this->inputCrsMatrix_.is_null() &&
302 std::is_same<typename crs_matrix_type::device_type::memory_space, Kokkos::HostSpace>::value) {
306 container_exec_space().fence();
307 auto localA = this->inputCrsMatrix_->getLocalMatrixHost();
308 using size_type =
typename crs_matrix_type::local_matrix_host_type::size_type;
309 const auto& rowmap = localA.graph.row_map;
310 const auto& entries = localA.graph.entries;
311 const auto& values = localA.values;
312 ArrayView<const LO> blockRows = this->getBlockRows(i);
313 for (
size_t j = 0; j < size_t(blockRows.size()); j++) {
314 const LO row = blockRows[j];
315 for (
size_t m = 0; m < numVecs; m++) {
317 for (size_type k = rowmap(row); k < rowmap(row + 1); k++) {
318 const LO col = entries(k);
319 r -= values(k) * Y2(col, m);
330 apply(Resid, Y2, i, Teuchos::NO_TRANS, dampingFactor, one);
334 ArrayView<const LO> blockRows = this->getBlockRows(i);
335 for (
size_t j = 0; j < size_t(blockRows.size()); j++) {
336 const LO row = blockRows[j];
337 auto rowView = getInputRowView(row);
338 for (
size_t m = 0; m < numVecs; m++) {
339 Resid(row, m) = X(row, m);
340 for (
size_t k = 0; k < rowView.size(); ++k) {
341 const LO col = rowView.ind(k);
342 Resid(row, m) -= rowView.val(k) * Y2(col, m);
352 apply(Resid, Y2, i, Teuchos::NO_TRANS, dampingFactor, one);
356template <
class MatrixType>
357void Container<MatrixType>::
358 DoGaussSeidel(ConstHostView X, HostView Y, HostView Y2, SC dampingFactor)
const {
359 using Teuchos::Array;
360 using Teuchos::ArrayRCP;
361 using Teuchos::ArrayView;
365 using Teuchos::rcpFromRef;
368 auto numVecs = X.extent(1);
370 HostView Resid(
"", X.extent(0), X.extent(1));
371 for (LO i = 0; i < numBlocks_; i++) {
372 DoGSBlock(X, Y, Y2, Resid, dampingFactor, i);
375 auto numMyRows = inputMatrix_->getLocalNumRows();
376 for (
size_t m = 0; m < numVecs; ++m) {
377 for (
size_t i = 0; i < numMyRows * bcrsBlockSize_; ++i) {
384template <
class MatrixType>
385void Container<MatrixType>::
386 DoSGS(ConstHostView X, HostView Y, HostView Y2, SC dampingFactor)
const {
388 using Teuchos::Array;
389 using Teuchos::ArrayRCP;
390 using Teuchos::ArrayView;
395 using Teuchos::rcpFromRef;
396 auto numVecs = X.extent(1);
397 HostView Resid(
"", X.extent(0), X.extent(1));
399 for (LO i = 0; i < numBlocks_; i++) {
400 DoGSBlock(X, Y, Y2, Resid, dampingFactor, i);
402 static_assert(std::is_signed<LO>::value,
403 "Local ordinal must be signed (unsigned breaks reverse iteration to 0)");
405 for (LO i = numBlocks_ - 1; i >= 0; --i) {
406 DoGSBlock(X, Y, Y2, Resid, dampingFactor, i);
409 auto numMyRows = inputMatrix_->getLocalNumRows();
410 for (
size_t m = 0; m < numVecs; ++m) {
411 for (
size_t i = 0; i < numMyRows * bcrsBlockSize_; ++i) {
418template <
class MatrixType>
419void Container<MatrixType>::
424 blockOffsets_.clear();
425 Diag_ = Teuchos::null;
430template <
class MatrixType,
class LocalScalarType>
433 const Teuchos::RCP<const row_matrix_type>& matrix,
434 const Teuchos::Array<Teuchos::Array<LO>>& partitions,
436 :
Container<MatrixType>(matrix, partitions, pointIndexed) {}
438template <
class MatrixType,
class LocalScalarType>
442template <
class MatrixType,
class LocalScalarType>
446template <
class MatrixType,
class LocalScalarType>
452 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"Not implemented.");
455template <
class MatrixType,
class LocalScalarType>
457 applyMV(
const mv_type& X, mv_type& Y)
const {
458 ConstHostView XView = X.getLocalViewHost(Tpetra::Access::ReadOnly);
459 HostView YView = Y.getLocalViewHost(Tpetra::Access::ReadWrite);
460 this->apply(XView, YView, 0);
463template <
class MatrixType,
class LocalScalarType>
467 vector_type& W)
const {
468 ConstHostView XView = X.getLocalViewHost(Tpetra::Access::ReadOnly);
469 HostView YView = Y.getLocalViewHost(Tpetra::Access::ReadWrite);
470 ConstHostView WView = W.getLocalViewHost(Tpetra::Access::ReadOnly);
471 weightedApply(XView, YView, WView, 0);
474template <
class MatrixType,
class LocalScalarType>
480template <
class MatrixType,
class LocalScalarType>
485 Teuchos::ETransp mode,
487 const LSC beta)
const {
488 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"Not implemented.");
491template <
class MatrixType,
class LocalScalarType>
492typename ContainerImpl<MatrixType, LocalScalarType>::LO
495 LO LO_INVALID = Teuchos::OrdinalTraits<LO>::invalid();
496 GO GO_INVALID = Teuchos::OrdinalTraits<GO>::invalid();
497 const map_type& globalRowMap = *(this->inputMatrix_->getRowMap());
498 const map_type& globalColMap = *(this->inputMatrix_->getColMap());
501 if (this->pointIndexed_) {
502 rowLID = row / this->bcrsBlockSize_;
503 dofOffset = row % this->bcrsBlockSize_;
505 GO diagGID = globalRowMap.getGlobalElement(rowLID);
506 TEUCHOS_TEST_FOR_EXCEPTION(
507 diagGID == GO_INVALID,
509 "Ifpack2::Container::translateRowToCol: "
511 << this->inputMatrix_->getRowMap()->getComm()->getRank() <<
", at least one row index in the set of local "
512 "row indices given to the constructor is not a valid local row index in "
513 "the input matrix's row Map on this process. This should be impossible "
514 "because the constructor checks for this case. Here is the complete set "
515 "of invalid local row indices: "
517 "Please report this bug to the Ifpack2 developers.");
519 LO colLID = globalColMap.getLocalElement(diagGID);
520 TEUCHOS_TEST_FOR_EXCEPTION(
521 colLID == LO_INVALID,
523 "Ifpack2::Container::translateRowToCol: "
525 << this->inputMatrix_->getRowMap()->getComm()->getRank() <<
", "
526 "at least one row index in the set of row indices given to the constructor "
527 "does not have a corresponding column index in the input matrix's column "
528 "Map. This probably means that the column(s) in question is/are empty on "
529 "this process, which would make the submatrix to extract structurally "
530 "singular. The invalid global column index is "
533 if (this->pointIndexed_)
534 return colLID * this->bcrsBlockSize_ + dofOffset;
538template <
class MatrixType,
class LocalScalarType>
540 apply(ConstHostView X,
543 Teuchos::ETransp mode,
546 using Teuchos::ArrayView;
559 TEUCHOS_TEST_FOR_EXCEPTION(
560 !this->IsComputed_, std::runtime_error,
561 "Ifpack2::Container::apply: "
562 "You must have called the compute() method before you may call apply(). "
563 "You may call the apply() method as many times as you want after calling "
564 "compute() once, but you must have called compute() at least once.");
566 const size_t numVecs = X.extent(1);
597 if (X_localBlocks_.size() == 0 || X.extent(1) != X_local_.extent(1)) {
599 X_localBlocks_.clear();
600 Y_localBlocks_.clear();
601 X_localBlocks_.reserve(this->numBlocks_);
602 Y_localBlocks_.reserve(this->numBlocks_);
604 X_local_ = HostViewLocal(
"X_local", this->blockRows_.size() * this->scalarsPerRow_, numVecs);
605 Y_local_ = HostViewLocal(
"Y_local", this->blockRows_.size() * this->scalarsPerRow_, numVecs);
609 for (
int i = 0; i < this->numBlocks_; i++) {
610 auto blockBounds = std::make_pair(this->blockOffsets_[i] * this->scalarsPerRow_,
611 (this->blockOffsets_[i] + this->blockSizes_[i]) * this->scalarsPerRow_);
612 X_localBlocks_.emplace_back(X_local_, blockBounds, Kokkos::ALL());
613 Y_localBlocks_.emplace_back(Y_local_, blockBounds, Kokkos::ALL());
617 const ArrayView<const LO> blockRows = this->getBlockRows(blockIndex);
619 if (this->scalarsPerRow_ == 1)
620 mvgs.gatherViewToView(X_localBlocks_[blockIndex], X, blockRows);
622 mvgs.gatherViewToViewBlock(X_localBlocks_[blockIndex], X, blockRows, this->scalarsPerRow_);
629 if (this->scalarsPerRow_ == 1)
630 mvgs.gatherViewToView(Y_localBlocks_[blockIndex], Y, blockRows);
632 mvgs.gatherViewToViewBlock(Y_localBlocks_[blockIndex], Y, blockRows, this->scalarsPerRow_);
636 this->solveBlock(X_localBlocks_[blockIndex], Y_localBlocks_[blockIndex], blockIndex, mode,
641 if (this->scalarsPerRow_ == 1)
642 mvgs.scatterViewToView(Y, Y_localBlocks_[blockIndex], blockRows);
644 mvgs.scatterViewToViewBlock(Y, Y_localBlocks_[blockIndex], blockRows, this->scalarsPerRow_);
647template <
class MatrixType,
class LocalScalarType>
653 Teuchos::ETransp mode,
657 using Teuchos::ArrayRCP;
658 using Teuchos::ArrayView;
661 using Teuchos::Range1D;
664 using Teuchos::rcp_const_cast;
665 using STS = Teuchos::ScalarTraits<SC>;
674 const char prefix[] =
"Ifpack2::Container::weightedApply: ";
675 TEUCHOS_TEST_FOR_EXCEPTION(
676 !this->IsComputed_, std::runtime_error, prefix <<
"You must have called the "
677 "compute() method before you may call this method. You may call "
678 "weightedApply() as many times as you want after calling compute() once, "
679 "but you must have called compute() at least once first.");
682 TEUCHOS_TEST_FOR_EXCEPTION(
683 this->scalarsPerRow_ > 1, std::logic_error, prefix <<
"Use of block rows isn't allowed "
684 "in overlapping Jacobi (the only method that uses weightedApply");
686 const size_t numVecs = X.extent(1);
688 TEUCHOS_TEST_FOR_EXCEPTION(
689 X.extent(1) != Y.extent(1), std::runtime_error,
690 prefix <<
"X and Y have different numbers of vectors (columns). X has "
691 << X.extent(1) <<
", but Y has " << Y.extent(1) <<
".");
697 const size_t numRows = this->blockSizes_[blockIndex];
722 if (X_localBlocks_.size() == 0 || X.extent(1) != X_local_.extent(1)) {
724 X_localBlocks_.clear();
725 Y_localBlocks_.clear();
726 X_localBlocks_.reserve(this->numBlocks_);
727 Y_localBlocks_.reserve(this->numBlocks_);
729 X_local_ = HostViewLocal(
"X_local", this->blockRows_.size() * this->scalarsPerRow_, numVecs);
730 Y_local_ = HostViewLocal(
"Y_local", this->blockRows_.size() * this->scalarsPerRow_, numVecs);
734 for (
int i = 0; i < this->numBlocks_; i++) {
735 auto blockBounds = std::make_pair(this->blockOffsets_[i] * this->scalarsPerRow_,
736 (this->blockOffsets_[i] + this->blockSizes_[i]) * this->scalarsPerRow_);
737 X_localBlocks_.emplace_back(X_local_, blockBounds, Kokkos::ALL());
738 Y_localBlocks_.emplace_back(Y_local_, blockBounds, Kokkos::ALL());
741 if (
int(weightedApplyScratch_.extent(0)) != 3 * this->maxBlockSize_ ||
742 weightedApplyScratch_.extent(1) != numVecs) {
743 weightedApplyScratch_ = HostViewLocal(
"weightedApply scratch", 3 * this->maxBlockSize_, numVecs);
746 ArrayView<const LO> blockRows = this->getBlockRows(blockIndex);
751 mvgs.gatherViewToView(X_localBlocks_[blockIndex], X, blockRows);
757 mvgs.gatherViewToView(Y_localBlocks_[blockIndex], Y, blockRows);
768 auto maxBS = this->maxBlockSize_;
769 auto bs = this->blockSizes_[blockIndex] * this->scalarsPerRow_;
771 HostSubviewLocal D_local(weightedApplyScratch_, std::make_pair(0, bs), std::make_pair(0, 1));
772 mvgs.gatherViewToView(D_local, D, blockRows);
773 HostSubviewLocal X_scaled(weightedApplyScratch_, std::make_pair(maxBS, maxBS + bs), Kokkos::ALL());
774 for (
size_t j = 0; j < numVecs; j++)
775 for (
size_t i = 0; i < numRows; i++)
776 X_scaled(i, j) = X_localBlocks_[blockIndex](i, j) * D_local(i, 0);
778 HostSubviewLocal Y_temp(weightedApplyScratch_, std::make_pair(maxBS * 2, maxBS * 2 + bs), Kokkos::ALL());
780 this->solveBlock(X_scaled, Y_temp, blockIndex, mode, STS::one(), STS::zero());
788 for (
size_t j = 0; j < numVecs; j++)
789 for (
size_t i = 0; i < numRows; i++)
790 Y_localBlocks_[blockIndex](i, j) = b * Y_localBlocks_[blockIndex](i, j) + a * Y_temp(i, j) * D_local(i, 0);
794 mvgs.scatterViewToView(Y, Y_localBlocks_[blockIndex], blockRows);
797template <
class MatrixType,
class LocalScalarType>
799 typename ContainerImpl<MatrixType, LocalScalarType>::SC,
800 typename ContainerImpl<MatrixType, LocalScalarType>::LO,
801 typename ContainerImpl<MatrixType, LocalScalarType>::GO,
802 typename ContainerImpl<MatrixType, LocalScalarType>::NO>
805 typedef typename MatrixType::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
806 typedef typename MatrixType::nonconst_values_host_view_type nonconst_values_host_view_type;
808 typedef typename MatrixType::local_inds_host_view_type local_inds_host_view_type;
809 typedef typename MatrixType::values_host_view_type values_host_view_type;
810 using IST =
typename row_matrix_type::impl_scalar_type;
812 if (this->hasBlockCrs_) {
813 using h_inds_type =
typename block_crs_matrix_type::local_inds_host_view_type;
814 using h_vals_type =
typename block_crs_matrix_type::values_host_view_type;
817 this->inputBlockMatrix_->getLocalRowView(row / this->bcrsBlockSize_, colinds, values);
818 size_t numEntries = colinds.size();
821 h_vals_type subvals = Kokkos::subview(values, std::pair<size_t, size_t>(row % this->bcrsBlockSize_, values.size()));
822 return StridedRowView(subvals, colinds, this->bcrsBlockSize_, numEntries * this->bcrsBlockSize_);
823 }
else if (!this->inputMatrix_->supportsRowViews()) {
824 size_t maxEntries = this->inputMatrix_->getLocalMaxNumRowEntries();
825 Teuchos::Array<LO> inds(maxEntries);
826 Teuchos::Array<SC> vals(maxEntries);
827 nonconst_local_inds_host_view_type inds_v(inds.data(), maxEntries);
828 nonconst_values_host_view_type vals_v(
reinterpret_cast<IST*
>(vals.data()), maxEntries);
830 this->inputMatrix_->getLocalRowCopy(row, inds_v, vals_v, numEntries);
831 vals.resize(numEntries);
832 inds.resize(numEntries);
836 local_inds_host_view_type colinds;
837 values_host_view_type values;
838 this->inputMatrix_->getLocalRowView(row, colinds, values);
843template <
class MatrixType,
class LocalScalarType>
846 X_localBlocks_.clear();
847 Y_localBlocks_.clear();
848 X_local_ = HostViewLocal();
849 Y_local_ = HostViewLocal();
856template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
861 , blockSize(blockSize_)
864template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
870 , nnz(
vals_.size()) {
871 valsCopy.swap(
vals_);
872 indsCopy.swap(
inds_);
875template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
877 val(
size_t i)
const {
880 "Out-of-bounds access into Ifpack2::Container::StridedRowView");
882 if (vals.size() > 0) {
886 return vals[i * blockSize];
891template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
892LocalOrdinal StridedRowView<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
893 ind(
size_t i)
const {
895 TEUCHOS_TEST_FOR_EXCEPTION(i >= nnz, std::runtime_error,
896 "Out-of-bounds access into Ifpack2::Container::StridedRowView");
899 if (inds.size() > 0) {
903 return inds[i / blockSize] * blockSize + i % blockSize;
908template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
909size_t StridedRowView<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
917template <
class MatrixType>
919 return obj.
print(os);
922#define IFPACK2_CONTAINER_INSTANT(S, LO, GO, N) \
923 template class Ifpack2::Container<Tpetra::RowMatrix<S, LO, GO, N>>; \
924 template class Ifpack2::ContainerImpl<Tpetra::RowMatrix<S, LO, GO, N>, S>; \
925 template class Ifpack2::Details::StridedRowView<S, LO, GO, N>; \
926 template std::ostream& operator<< <Tpetra::RowMatrix<S, LO, GO, N>>( \
927 std::ostream& os, const Ifpack2::Container<Tpetra::RowMatrix<S, LO, GO, N>>& obj);
Declaration of Ifpack2::Details::Behavior, a class that describes Ifpack2's run-time behavior.
Declaration and definition of the Ifpack2::Details::MultiVectorLocalGatherScatter class.
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:81
bool hasBlockCrs_
Whether the input matrix is a BlockCRS matrix.
Definition Ifpack2_Container_decl.hpp:275
bool IsParallel_
Whether the problem is distributed across multiple MPI processes.
Definition Ifpack2_Container_decl.hpp:267
int numBlocks_
The number of blocks (partitions) in the container.
Definition Ifpack2_Container_decl.hpp:257
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:85
static std::string getName()
Definition Ifpack2_Container_def.hpp:147
int bcrsBlockSize_
If hasBlockCrs_, the number of DOFs per vertex. Otherwise 1.
Definition Ifpack2_Container_decl.hpp:277
Teuchos::RCP< const block_crs_matrix_type > inputBlockMatrix_
The input matrix, dynamic cast to BlockCrsMatrix. May be null.
Definition Ifpack2_Container_decl.hpp:254
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:152
virtual void applyMV(const mv_type &X, mv_type &Y) const
Wrapper for apply with MultiVector.
Definition Ifpack2_Container_def.hpp:135
LO NumLocalRows_
Number of local rows in input matrix.
Definition Ifpack2_Container_decl.hpp:269
bool isInitialized() const
Whether the container has been successfully initialized.
Definition Ifpack2_Container_def.hpp:124
void setBlockSizes(const Teuchos::Array< Teuchos::Array< LO > > &partitions)
Initialize arrays with information about block sizes.
Definition Ifpack2_Container_def.hpp:90
LO scalarsPerRow_
Definition Ifpack2_Container_decl.hpp:282
Teuchos::Array< LO > blockSizes_
Number of rows in each block.
Definition Ifpack2_Container_decl.hpp:261
GO NumGlobalNonzeros_
Number of nonzeros in input matrix.
Definition Ifpack2_Container_decl.hpp:273
Container(const Teuchos::RCP< const row_matrix_type > &matrix, const Teuchos::Array< Teuchos::Array< LO > > &partitions, bool pointIndexed)
Constructor.
Definition Ifpack2_Container_def.hpp:22
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:141
Teuchos::RCP< const row_matrix_type > inputMatrix_
The input matrix to the constructor.
Definition Ifpack2_Container_decl.hpp:248
bool pointIndexed_
(If hasBlockCrs_) Whether the blocks are described using sub-block row indices instead of full block ...
Definition Ifpack2_Container_decl.hpp:279
typename KokkosKernels::ArithTraits< SC >::val_type ISC
Internal representation of Scalar in Kokkos::View.
Definition Ifpack2_Container_decl.hpp:101
GO NumGlobalRows_
Number of global rows in input matrix.
Definition Ifpack2_Container_decl.hpp:271
bool isComputed() const
Whether the container has been successfully computed.
Definition Ifpack2_Container_def.hpp:129
typename mv_type::dual_view_type::t_host HostView
Definition Ifpack2_Container_decl.hpp:105
The implementation of the numerical features of Container (Jacobi, Gauss-Seidel, SGS)....
Definition Ifpack2_Container_decl.hpp:307
LocalScalarType LSC
The internal representation of LocalScalarType in Kokkos::View.
Definition Ifpack2_Container_decl.hpp:326
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:232
static bool debug()
Whether Ifpack2 is in debug mode.
Definition Ifpack2_Details_Behavior.cpp:31
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:498
StridedRowView(h_vals_type vals_, h_inds_type inds_, int blockSize_, size_t nnz_)
Constructor for row views (preferred)
Definition Ifpack2_Container_def.hpp:858