43 #ifndef IFPACK2_TRIDICONTAINER_DEF_HPP
44 #define IFPACK2_TRIDICONTAINER_DEF_HPP
52 # include "Teuchos_DefaultSerialComm.hpp"
58 template<
class MatrixType,
class LocalScalarType>
64 ContainerImpl<MatrixType, LocalScalarType>(matrix, partitions, pointIndexed),
65 ipiv_(this->blockRows_.size() * this->scalarsPerRow_),
66 scalarOffsets_ (this->numBlocks_)
69 ! matrix->hasColMap (), std::invalid_argument,
"Ifpack2::TriDiContainer: "
70 "The constructor's input matrix must have a column Map.");
77 scalarOffsets_[i] = scalarTotal;
80 if(actualBlockRows == 1)
88 scalarTotal += 4 * (actualBlockRows - 1);
92 scalars_.
resize(scalarTotal);
93 diagBlocks_.reserve(this->numBlocks_);
100 template<
class MatrixType,
class LocalScalarType>
104 template<
class MatrixType,
class LocalScalarType>
107 for(
int i = 0; i < this->numBlocks_; i++)
109 this->IsInitialized_ =
true;
112 this->IsComputed_ =
false;
115 template<
class MatrixType,
class LocalScalarType>
118 #ifdef HAVE_IFPACK2_DEBUG
120 ipiv_.size () != this->blockRows_.size( * scalarsPerRow_), std::logic_error,
121 "Ifpack2::TriDiContainer::compute: ipiv_ array has the wrong size. "
122 "Please report this bug to the Ifpack2 developers.");
125 this->IsComputed_ =
false;
126 if (! this->isInitialized ()) {
131 this->IsComputed_ =
true;
134 template<
class MatrixType,
class LocalScalarType>
147 if(this->scalarsPerRow_ > 1)
149 Array<LO> colToBlockOffset(this->inputBlockMatrix_->getNodeNumCols(), INVALID);
150 for(
int i = 0; i < this->numBlocks_; i++)
153 LO blockStart = this->blockOffsets_[i];
154 LO blockEnd = blockStart + this->blockSizes_[i];
155 ArrayView<const LO> blockRows = this->getBlockRows(i);
159 for(
size_t j = 0; j < size_t(blockRows.size()); j++)
161 LO localCol = this->translateRowToCol(blockRows[j]);
162 colToBlockOffset[localCol] = blockStart + j;
164 for(LO blockRow = 0; blockRow < LO(blockRows.size()); blockRow++)
170 LO inputRow = this->blockRows_[blockStart + blockRow];
171 this->inputBlockMatrix_->getLocalRowView(inputRow, indices, values, numEntries);
172 for(LO k = 0; k < numEntries; k++)
174 LO colOffset = colToBlockOffset[indices[k]];
175 if(blockStart <= colOffset && colOffset < blockEnd)
180 LO blockCol = colOffset - blockStart;
181 for(LO bc = 0; bc < this->bcrsBlockSize_; bc++)
183 for(LO br = 0; br < this->bcrsBlockSize_; br++)
185 LO r = this->bcrsBlockSize_ * blockRow + br;
186 LO c = this->bcrsBlockSize_ * blockCol + bc;
187 auto val = values[k * (this->bcrsBlockSize_ * this->bcrsBlockSize_) + (br + this->bcrsBlockSize_ * bc)];
189 diagBlocks_[i](r, c) = val;
201 Array<LO> colToBlockOffset(this->inputMatrix_->getNodeNumCols() * this->bcrsBlockSize_, INVALID);
202 for(
int i = 0; i < this->numBlocks_; i++)
205 LO blockStart = this->blockOffsets_[i];
206 LO blockEnd = blockStart + this->blockSizes_[i];
207 ArrayView<const LO> blockRows = this->getBlockRows(i);
211 for(
size_t j = 0; j < size_t(blockRows.size()); j++)
214 LO localCol = this->translateRowToCol(blockRows[j]);
215 colToBlockOffset[localCol] = blockStart + j;
217 for(
size_t blockRow = 0; blockRow < size_t(blockRows.size()); blockRow++)
220 LO inputPointRow = this->blockRows_[blockStart + blockRow];
221 auto rowView = this->getInputRowView(inputPointRow);
222 for(
size_t k = 0; k < rowView.size(); k++)
224 LO colOffset = colToBlockOffset[rowView.ind(k)];
225 if(blockStart <= colOffset && colOffset < blockEnd)
227 LO blockCol = colOffset - blockStart;
228 auto val = rowView.val(k);
230 diagBlocks_[i](blockRow, blockCol) = rowView.val(k);
238 template<
class MatrixType,
class LocalScalarType>
239 void TriDiContainer<MatrixType, LocalScalarType>::clearBlocks ()
243 ContainerImpl<MatrixType, LocalScalarType>::clearBlocks();
246 template<
class MatrixType,
class LocalScalarType>
247 void TriDiContainer<MatrixType, LocalScalarType>::factor ()
249 for(
int i = 0; i < this->numBlocks_; i++)
253 int* blockIpiv = &ipiv_[this->blockOffsets_[i] * this->scalarsPerRow_];
254 lapack.
GTTRF (diagBlocks_[i].numRowsCols (),
258 diagBlocks_[i].DU2(),
262 INFO < 0, std::logic_error,
"Ifpack2::TriDiContainer::factor: "
263 "LAPACK's _GTTRF (LU factorization with partial pivoting) was called "
264 "incorrectly. INFO = " << INFO <<
" < 0. "
265 "Please report this bug to the Ifpack2 developers.");
270 INFO > 0, std::runtime_error,
"Ifpack2::TriDiContainer::factor: "
271 "LAPACK's _GTTRF (LU factorization with partial pivoting) reports that the "
272 "computed U factor is exactly singular. U(" << INFO <<
"," << INFO <<
") "
273 "(one-based index i) is exactly zero. This probably means that the input "
274 "matrix has a singular diagonal block.");
278 template<
class MatrixType,
class LocalScalarType>
288 size_t numVecs = X.extent(1);
289 size_t numRows = X.extent(0);
291 #ifdef HAVE_IFPACK2_DEBUG
293 X.extent (0) != Y.extent (0),
294 std::logic_error,
"Ifpack2::TriDiContainer::solveBlock: X and Y have "
295 "incompatible dimensions (" << X.extent (0) <<
" resp. "
296 << Y.extent (0) <<
"). Please report this bug to "
297 "the Ifpack2 developers.");
299 X.extent (0) !=
static_cast<size_t> (diagBlocks_[blockIndex].numRowsCols()),
300 std::logic_error,
"Ifpack2::TriDiContainer::solveBlock: The input "
301 "multivector X has incompatible dimensions from those of the "
302 "inverse operator (" << X.extent (0) <<
" vs. "
303 << (mode ==
Teuchos::NO_TRANS ? diagBlocks_[blockIndex].numRowsCols () : diagBlocks_[blockIndex].numRowsCols())
304 <<
"). Please report this bug to the Ifpack2 developers.");
305 TEUCHOS_TEST_FOR_EXCEPTION(
306 Y.extent (0) !=
static_cast<size_t> (diagBlocks_[blockIndex].numRowsCols()),
307 std::logic_error,
"Ifpack2::TriDiContainer::solveBlock: The output "
308 "multivector Y has incompatible dimensions from those of the "
309 "inverse operator (" << Y.extent (0) <<
" vs. "
310 << (mode ==
Teuchos::NO_TRANS ? diagBlocks_[blockIndex].numRowsCols() : diagBlocks_[blockIndex].numRowsCols ())
311 <<
"). Please report this bug to the Ifpack2 developers.");
319 for(
size_t j = 0; j < numVecs; j++)
320 for(
size_t i = 0; i < numRows; i++)
324 for(
size_t j = 0; j < numVecs; j++)
325 for(
size_t i = 0; i < numRows; i++)
326 Y(i, j) *=
ISC(beta);
335 std::vector<LSC> yTemp(numVecs * numRows);
336 for(
size_t j = 0; j < numVecs; j++)
338 for(
size_t i = 0; i < numRows; i++)
339 yTemp[j * numRows + i] = X(i, j);
345 int* blockIpiv = &ipiv_[this->blockOffsets_[blockIndex] * this->scalarsPerRow_];
347 diagBlocks_[blockIndex].numRowsCols(),
349 diagBlocks_[blockIndex].DL(),
350 diagBlocks_[blockIndex].D(),
351 diagBlocks_[blockIndex].DU(),
352 diagBlocks_[blockIndex].DU2(),
359 for(
size_t j = 0; j < numVecs; j++)
361 for(
size_t i = 0; i < numRows; i++)
363 Y(i, j) *=
ISC(beta);
364 Y(i, j) +=
ISC(alpha * yTemp[j * numRows + i]);
369 for(
size_t j = 0; j < numVecs; j++)
371 for(
size_t i = 0; i < numRows; i++)
372 Y(i, j) =
ISC(yTemp[j * numRows + i]);
376 TEUCHOS_TEST_FOR_EXCEPTION(
377 INFO != 0, std::runtime_error,
"Ifpack2::TriDiContainer::solveBlock: "
378 "LAPACK's _GETRS (solve using LU factorization with partial pivoting) "
379 "failed with INFO = " << INFO <<
" != 0.");
383 template<
class MatrixType,
class LocalScalarType>
392 template<
class MatrixType,
class LocalScalarType>
395 std::ostringstream oss;
397 if (this->isInitialized()) {
398 if (this->isComputed()) {
399 oss <<
"{status = initialized, computed";
402 oss <<
"{status = initialized, not computed";
406 oss <<
"{status = not initialized, not computed";
413 template<
class MatrixType,
class LocalScalarType>
421 os <<
"================================================================================" << endl;
422 os <<
"Ifpack2::TriDiContainer" << endl;
423 os <<
"Number of blocks = " << this->numBlocks_ << endl;
424 os <<
"isInitialized() = " << this->IsInitialized_ << endl;
425 os <<
"isComputed() = " << this->IsComputed_ << endl;
426 os <<
"================================================================================" << endl;
430 template<
class MatrixType,
class LocalScalarType>
436 #define IFPACK2_TRIDICONTAINER_INSTANT(S,LO,GO,N) \
437 template class Ifpack2::TriDiContainer< Tpetra::RowMatrix<S, LO, GO, N>, S >;
Store and solve a local TriDi linear problem.
Definition: Ifpack2_TriDiContainer_decl.hpp:105
virtual std::string description() const
A one-line description of this object.
Definition: Ifpack2_TriDiContainer_def.hpp:393
static std::string getName()
Get the name of this container type for Details::constructContainer()
Definition: Ifpack2_TriDiContainer_def.hpp:431
Teuchos::Array< LO > blockSizes_
Number of rows in each block.
Definition: Ifpack2_Container_decl.hpp:295
virtual void compute()
Extract the local diagonal block and prepare the solver.
Definition: Ifpack2_TriDiContainer_def.hpp:116
int numBlocks_
The number of blocks (partitions) in the container.
Definition: Ifpack2_Container_decl.hpp:291
void GTTRS(const char &TRANS, const OrdinalType &n, const OrdinalType &nrhs, const ScalarType *dl, const ScalarType *d, const ScalarType *du, const ScalarType *du2, const OrdinalType *IPIV, ScalarType *B, const OrdinalType &ldb, OrdinalType *info) const
void GTTRF(const OrdinalType &n, ScalarType *dl, ScalarType *d, ScalarType *du, ScalarType *du2, OrdinalType *IPIV, OrdinalType *info) const
The implementation of the numerical features of Container (Jacobi, Gauss-Seidel, SGS). This class allows a custom scalar type (LocalScalarType) to be used for storing blocks and solving the block systems. Hiding this template parameter from the Container interface simplifies the BlockRelaxation and ContainerFactory classes.
Definition: Ifpack2_Container_decl.hpp:342
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
LO scalarsPerRow_
Definition: Ifpack2_Container_decl.hpp:316
virtual ~TriDiContainer()
Destructor (declared virtual for memory safety of derived classes).
Definition: Ifpack2_TriDiContainer_def.hpp:102
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to the given FancyOStream.
Definition: Ifpack2_TriDiContainer_def.hpp:416
typename Kokkos::Details::ArithTraits< SC >::val_type ISC
Internal representation of Scalar in Kokkos::View.
Definition: Ifpack2_Container_decl.hpp:135
virtual std::ostream & print(std::ostream &os) const
Print information about this object to the given output stream.
Definition: Ifpack2_TriDiContainer_def.hpp:384
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual std::string description() const
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
void resize(size_type new_size, const value_type &x=value_type())
TriDiContainer(const Teuchos::RCP< const row_matrix_type > &matrix, const Teuchos::Array< Teuchos::Array< LO > > &partitions, const Teuchos::RCP< const import_type > &importer, bool pointIndexed)
Constructor.
Definition: Ifpack2_TriDiContainer_def.hpp:60
void solveBlock(HostSubviewLocal X, HostSubviewLocal Y, int blockIndex, Teuchos::ETransp mode, LSC alpha, LSC beta) const
Definition: Ifpack2_TriDiContainer_def.hpp:280
virtual void initialize()
Do all set-up operations that only require matrix structure.
Definition: Ifpack2_TriDiContainer_def.hpp:105