10 #ifndef BELOS_BLOCK_GCRODR_ITER_HPP
11 #define BELOS_BLOCK_GCRODR_ITER_HPP
62 template <
class ScalarType,
class MV>
89 U(Teuchos::null),
C(Teuchos::null),
90 H(Teuchos::null),
B(Teuchos::null)
134 template<
class ScalarType,
class MV,
class OP>
317 void setSize(
int recycledBlocks,
int numBlocks ) {
430 template<
class ScalarType,
class MV,
class OP>
436 om_(printer), stest_(tester), ortho_(ortho) {
452 int nb = Teuchos::getParameter<int>(params,
"Num Blocks");
454 TEUCHOS_TEST_FOR_EXCEPTION(!params.isParameter(
"Recycled Blocks"), std::invalid_argument,
"Belos::BlockGCRODRIter::constructor: mandatory parameter \"Recycled Blocks\" is not specified.");
455 int rb = Teuchos::getParameter<int>(params,
"Recycled Blocks");
457 TEUCHOS_TEST_FOR_EXCEPTION(nb <= 0, std::invalid_argument,
"Belos::BlockGCRODRIter() was passed a non-positive argument for \"Num Blocks\".");
458 TEUCHOS_TEST_FOR_EXCEPTION(rb >= nb, std::invalid_argument,
"Belos::BlockGCRODRIter() the number of recycled blocks is larger than the allowable subspace.");
461 int bs = Teuchos::getParameter<int>(params,
"Block Size");
463 TEUCHOS_TEST_FOR_EXCEPTION(bs <= 0, std::invalid_argument,
"Belos::BlockGCRODRIter() the block size was passed a non-postitive argument.");
487 House_[i].shapeUninitialized(2*blockSize_, 2*blockSize_);
493 template <
class ScalarType,
class MV,
class OP>
501 setSize( recycledBlocks_, numBlocks_ );
505 std::vector<int> curind(blockSize_);
511 for(
int i = 0; i<blockSize_; i++){curind[i] = i;};
516 Vnext = MVT::CloneViewNonConst(*V_,curind);
521 int rank = ortho_->normalize(*Vnext,Z0);
529 Z_block->assign(*Z0);
531 std::vector<int> prevind(blockSize_*(numBlocks_ + 1));
538 while( (stest_->checkStatus(
this) !=
Passed) && (curDim_+blockSize_-1) < (numBlocks_*blockSize_)) {
544 int HFirstCol = curDim_-blockSize_;
545 int HLastCol = HFirstCol + blockSize_-1 ;
546 int HLastOrthRow = HLastCol;
547 int HFirstNormRow = HLastOrthRow + 1;
551 for(
int i = 0; i< blockSize_; i++){
552 curind[i] = curDim_ + i;
554 Vnext = MVT::CloneViewNonConst(*V_,curind);
559 for(
int i = 0; i< blockSize_; i++){
560 curind[blockSize_ - 1 - i] = curDim_ - i - 1;
562 Vprev = MVT::CloneView(*V_,curind);
564 lp_->apply(*Vprev,*Vnext);
579 ortho_->project( *Vnext, AsubB, C );
583 prevind.resize(curDim_);
584 for (
int i=0; i<curDim_; i++) { prevind[i] = i; }
585 Vprev = MVT::CloneView(*V_,prevind);
595 int rank = ortho_->projectAndNormalize(*Vnext,AsubH,subR,AVprev);
598 SDM subR2(
Teuchos::View,*R_,(lclIter_+1)*blockSize_,blockSize_,0,HFirstCol);
599 SDM subH2(
Teuchos::View,*H_,(lclIter_+1)*blockSize_,blockSize_,0,HFirstCol);
608 curDim_ = curDim_ + blockSize_;
618 template <
class ScalarType,
class MV,
class OP>
621 curDim_ = newstate.
curDim;
632 SDM Identity(2*blockSize_, 2*blockSize_);
633 for(
int i=0;i<2*blockSize_; i++){
636 for(
int i=0; i<numBlocks_;i++){
637 House_[i].
assign(Identity);
654 template <
class ScalarType,
class MV,
class OP>
662 if (static_cast<int> (norms->size()) < blockSize_) {
663 norms->resize( blockSize_ );
666 for (
int j=0; j<blockSize_; j++) {
667 if(trueRHSIndices_[j]){
668 (*norms)[j] = blas.
NRM2( blockSize_, &Z_(curDim_-blockSize_+j, j), 1);
683 template <
class ScalarType,
class MV,
class OP>
691 if(curDim_<=blockSize_) {
692 return currentUpdate;
698 currentUpdate = MVT::Clone( *V_, blockSize_ );
722 Rtmp->values(), Rtmp->stride(), Y.
values(), Y.
stride() );
729 std::vector<int> index(curDim_-blockSize_);
730 for (
int i=0; i<curDim_-blockSize_; i++ ) index[i] = i;
732 MVT::MvTimesMatAddMv( one, *Vjp1, Y, zero, *currentUpdate );
740 SDM z(recycledBlocks_,blockSize_);
745 MVT::MvTimesMatAddMv( -one, *U_, z, one, *currentUpdate );
751 return currentUpdate;
754 template<
class ScalarType,
class MV,
class OP>
766 int curDim = curDim_;
767 if ( (dim >= curDim_) && (dim < getMaxSubspaceDim()) ){
780 for (i=0; i<curDim-1; i++) {
784 blas.
ROT( 1, &(*R_)(i,curDim-1), 1, &(*R_)(i+1, curDim-1), 1, &cs_[i], &sn_[i] );
789 blas.
ROTG( &(*R_)(curDim-1,curDim-1), &(*R_)(curDim,curDim-1), &cs_[curDim-1], &sn_[curDim-1] );
790 (*R_)(curDim,curDim-1) = zero;
794 blas.
ROT( 1, &Z_(curDim-1,0), 1, &Z_(curDim,0), 1, &cs_[curDim-1], &sn_[curDim-1] );
812 int R_colStart = curDim_-blockSize_;
818 for(i=0; i<lclIter_-1; i++){
819 int R_rowStart = i*blockSize_;
823 blas.
GEMM(
Teuchos::NO_TRANS,
Teuchos::NO_TRANS, 2*blockSize_,blockSize_,2*blockSize_,one,House_[i].values(),House_[i].stride(), RblockCopy->values(),RblockCopy -> stride(), zero, RblockView->values(),RblockView -> stride());
830 Rblock =
rcp(
new SDM (
Teuchos::View, *R_, 2*blockSize_,blockSize_, curDim_-blockSize_, curDim_-blockSize_));
833 for(i=0; i<blockSize_; i++){
837 int curcol = (lclIter_ - 1)*blockSize_ + i;
843 ScalarType nvs = blas.
NRM2(blockSize_+1,&((*R_)[curcol][curcol]),1);
844 ScalarType alpha = -signDiag*nvs;
863 (*v_refl)[0] -= alpha;
864 nvs = blas.
NRM2(blockSize_+1,v_refl -> values(),1);
880 if(i < blockSize_ - 1){
884 blas.
GEMV(
Teuchos::TRANS, workmatrix->numRows(), workmatrix->numCols(), one, workmatrix->values(), workmatrix->stride(), v_refl->values(), 1, zero, workvec->values(), 1);
885 blas.
GER(workmatrix->numRows(),workmatrix->numCols(), -2.0*one/nvs, v_refl->values(),1,workvec->values(),1,workmatrix->values(),workmatrix->stride());
894 blas.
GEMV(
Teuchos::TRANS,workmatrix->numRows(),workmatrix->numCols(),one,workmatrix->values(),workmatrix->stride(), v_refl->values(), 1,zero,workvec->values(),1);
895 blas.
GER(workmatrix->numRows(),workmatrix->numCols(), -2.0*one/nvs, v_refl -> values(),1,workvec->values(),1,workmatrix->values(),(*workmatrix).stride());
902 blas.
GEMV(
Teuchos::TRANS, workmatrix->numRows(), workmatrix->numCols(), one, workmatrix-> values(), workmatrix->stride(), v_refl -> values(), 1, zero, workvec->values(), 1);
903 blas.
GER((*workmatrix).numRows(),(*workmatrix).numCols(), -2.0*one/nvs,v_refl -> values(), 1,&((*workvec)[0]),1,(*workmatrix)[0],(*workmatrix).stride());
908 (*R_)[curcol][curcol] = alpha;
909 for(
int ii=1; ii<= blockSize_; ii++){
910 (*R_)[curcol][curcol+ii] = 0;
ScalarType * values() const
Collection of types and exceptions used within the Belos solvers.
void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const A_type *A, const OrdinalType &lda, ScalarType *B, const OrdinalType &ldb) const
int getNumBlocks() const
Get the maximum number of blocks used by the iterative solver in solving this linear problem...
void GER(const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const x_type *x, const OrdinalType &incx, const y_type *y, const OrdinalType &incy, ScalarType *A, const OrdinalType &lda) const
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
Teuchos::RCP< MV > V_
The Krylov basis vectors.
Array< T > & append(const T &x)
Class which manages the output and verbosity of the Belos solvers.
Structure to contain pointers to BlockGCRODRIter state variables.
void setRecycledBlocks(int recycledBlocks)
Set the maximum number of recycled blocks used by the iterative solver.
int shapeUninitialized(OrdinalType numRows, OrdinalType numCols)
void GEMV(ETransp trans, const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const A_type *A, const OrdinalType &lda, const x_type *x, const OrdinalType &incx, const beta_type beta, ScalarType *y, const OrdinalType &incy) const
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B
The projection of the Krylov subspace against the recycled subspace *.
virtual ~BlockGCRODRIter()
Destructor.
void ROT(const OrdinalType &n, ScalarType *dx, const OrdinalType &incx, ScalarType *dy, const OrdinalType &incy, MagnitudeType *c, ScalarType *s) const
BlockGCRODRIterOrthoFailure is thrown when the BlockGCRODRIter object is unable to compute independen...
void setSize(int recycledBlocks, int numBlocks)
Set the maximum number of blocks used by the iterative solver and the number of recycled vectors...
void iterate()
This method performs block GCRODR iterations until the status test indicates the need to stop or an e...
MultiVecTraits< ScalarType, MV > MVT
Pure virtual base class for defining the status testing capabilities of Belos.
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Declaration of basic traits for the multivector type.
ScalarTraits< ScalarType >::magnitudeType NRM2(const OrdinalType &n, const ScalarType *x, const OrdinalType &incx) const
Teuchos::RCP< SDM > B_
Projected matrix from the recycled subspace.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > stest_
void GEMM(ETransp transa, ETransp transb, const OrdinalType &m, const OrdinalType &n, const OrdinalType &k, const alpha_type alpha, const A_type *A, const OrdinalType &lda, const B_type *B, const OrdinalType &ldb, const beta_type beta, ScalarType *C, const OrdinalType &ldc) const
Teuchos::SerialDenseMatrix< int, ScalarType > SDM
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
A pure virtual class for defining the status tests for the Belos iterative solvers.
void setNumBlocks(int numBlocks)
Set the maximum number of blocks used by the iterative solver.
Class which defines basic traits for the operator type.
BlockGCRODRIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current solution to the linear problem...
Teuchos::RCP< MV > V
The current Krylov basis.
std::vector< SDM > House_
Traits class which defines basic operations on multivectors.
int curDim
The current dimension of the reduction.
Teuchos::RCP< SDM > H_
Projected matrix from the Krylov factorization.
SCT::magnitudeType MagnitudeType
bool isParameter(const std::string &name) const
BlockGCRODRIterOrthoFailure(const std::string &what_arg)
BlockGCRODRIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &tester, const Teuchos::RCP< MatOrthoManager< ScalarType, MV, OP > > &ortho, Teuchos::ParameterList ¶ms)
BlockGCRODRIter constructor with linear problem, solver utilities, and parameter list of solver optio...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setBlockSize(int blockSize)
Set the blocksize.
Teuchos::SerialDenseVector< int, MagnitudeType > cs_
BlockGCRODRIterInitFailure(const std::string &what_arg)
A linear system to solve, and its associated information.
void updateLSQR(int dim=-1)
Class which describes the linear problem to be solved by the iterative solver.
Teuchos::RCP< MV > U_
Recycled subspace vectors.
Teuchos::RCP< MV > U
The recycled subspace and its projection.
void resetNumIters(int iter=0)
Reset the iteration count.
Implementation of the Block GCRO-DR (Block Recycling GMRES) iteration.
void initialize()
Initialize the solver to an iterate, providing a complete state.
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace.
SDM Z_
Q applied to right-hand side of the least squares system.
const Teuchos::RCP< OrthoManager< ScalarType, MV > > ortho_
void ROTG(ScalarType *da, ScalarType *db, rotg_c_type *c, ScalarType *s) const
BlockGCRODRIterInitFailure is thrown when the BlockGCRODRIter object is unable to generate an initial...
int getRecycledBlocks() const
Set the maximum number of recycled blocks used by the iterative solver.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > H
The current Hessenberg matrix.
bool isInitialized()
States whether the solver has been initialized or not.
std::vector< bool > trueRHSIndices_
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
Teuchos::SerialDenseVector< int, ScalarType > SDV
const Teuchos::RCP< OutputManager< ScalarType > > om_
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
Belos header file which uses auto-configuration information to include necessary C++ headers...
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
SerialDenseMatrix< OrdinalType, ScalarType > & assign(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Teuchos::ScalarTraits< ScalarType > SCT
OperatorTraits< ScalarType, MV, OP > OPT
const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > lp_
int getNumIters() const
Get the current iteration count.
OrdinalType stride() const
Teuchos::RCP< SDM > R_
Upper triangular reduction of H_ (see above).
int sizeUninitialized(OrdinalType length_in)
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...