10#ifndef BELOS_GCRODR_ITER_HPP
11#define BELOS_GCRODR_ITER_HPP
29#include "Teuchos_BLAS.hpp"
30#include "Teuchos_ScalarTraits.hpp"
31#include "Teuchos_ParameterList.hpp"
32#include "Teuchos_TimeMonitor.hpp"
55 template <
class ScalarType,
class MV,
class DM>
70 Teuchos::RCP<MV>
U,
C;
129 template<
class ScalarType,
class MV,
class OP,
class DM>
140 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
158 Teuchos::ParameterList &
params );
231 state.curDim = curDim_;
233 state.Z = Teuchos::null;
275 if (!initialized_)
return 0;
312 cs_.resize( numBlocks_+1 );
313 sn_.resize( numBlocks_+1 );
314 z_ = DMT::Create( numBlocks_+1, 1,
false );
315 R_ = DMT::Create( numBlocks_+1,
numBlocks,
false );
333 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > lp_;
334 const Teuchos::RCP<OutputManager<ScalarType> > om_;
335 const Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > stest_;
336 const Teuchos::RCP<OrthoManager<ScalarType,MV,DM> > ortho_;
348 std::vector<ScalarType> sn_;
349 std::vector<MagnitudeType> cs_;
371 Teuchos::RCP<MV> U_, C_;
374 Teuchos::RCP<DM> H2_;
392 template<
class ScalarType,
class MV,
class OP,
class DM>
397 Teuchos::ParameterList &
params ):
401 initialized_ =
false;
413 TEUCHOS_TEST_FOR_EXCEPTION(!
params.isParameter(
"Num Blocks"), std::invalid_argument,
"Belos::GCRODRIter::constructor: mandatory parameter \"Num Blocks\" is not specified.");
414 int nb = Teuchos::getParameter<int>(
params,
"Num Blocks");
416 TEUCHOS_TEST_FOR_EXCEPTION(!
params.isParameter(
"Recycled Blocks"), std::invalid_argument,
"Belos::GCRODRIter::constructor: mandatory parameter \"Recycled Blocks\" is not specified.");
417 int rb = Teuchos::getParameter<int>(
params,
"Recycled Blocks");
419 TEUCHOS_TEST_FOR_EXCEPTION(
nb <= 0, std::invalid_argument,
"Belos::GCRODRIter() was passed a non-positive argument for \"Num Blocks\".");
420 TEUCHOS_TEST_FOR_EXCEPTION(
rb >=
nb, std::invalid_argument,
"Belos::GCRODRIter() the number of recycled blocks is larger than the allowable subspace.");
423 recycledBlocks_ =
rb;
424 cs_.resize( numBlocks_+1 );
425 sn_.resize( numBlocks_+1 );
426 z_ = DMT::Create( numBlocks_+1, 1,
false );
427 R_ = DMT::Create( numBlocks_+1, numBlocks_,
false );
433 template<
class ScalarType,
class MV,
class OP,
class DM>
443 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
444 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
445 Teuchos::BLAS<int,ScalarType>
blas;
450 Teuchos::RCP<DM> y = DMT::SubviewCopy(*z_, curDim_, 1);
451 DMT::SyncDeviceToHost( *y );
452 DMT::SyncDeviceToHost( *R_ );
456 blas.TRSM( Teuchos::LEFT_SIDE, Teuchos::UPPER_TRI, Teuchos::NO_TRANS,
457 Teuchos::NON_UNIT_DIAG, curDim_, 1,
one,
458 DMT::GetConstRawHostPtr(*R_), DMT::GetStride(*R_),
459 DMT::GetRawHostPtr(*y), DMT::GetStride(*y) );
463 std::vector<int> index(curDim_);
464 for (
int i=0;
i<curDim_;
i++ ) index[
i] =
i;
465 Teuchos::RCP<const MV>
Vjp1 = MVT::CloneView( *V_, index );
470 if (U_ != Teuchos::null) {
471 Teuchos::RCP<DM> z = DMT::Create( recycledBlocks_, 1 );
472 DMT::SyncDeviceToHost( *H2_ );
473 blas.GEMM( Teuchos::NO_TRANS, Teuchos::NO_TRANS, recycledBlocks_, 1, curDim_,
one,
474 DMT::GetConstRawHostPtr(*B_), DMT::GetStride(*B_),
475 DMT::GetConstRawHostPtr(*y), DMT::GetStride(*y),
476 zero, DMT::GetRawHostPtr(*z), DMT::GetStride(*z));
477 DMT::SyncHostToDevice( *z );
491 template<
class ScalarType,
class MV,
class OP,
class DM>
500 DMT::SyncDeviceToHost( *z_ );
504 return Teuchos::null;
511 template<
class ScalarType,
class MV,
class OP,
class DM>
522 ptrH00_ = recycledBlocks_+1;
523 H_ = DMT::Subview( *H2_, numBlocks_+1, numBlocks_, ptrH00_, ptrH00_ );
527 ptrH00_ = recycledBlocks_;
528 H_ = DMT::Subview( *H2_, numBlocks_+1, numBlocks_, ptrH00_, ptrH00_ );
529 B_ = DMT::Subview( *H2_, recycledBlocks_, numBlocks_, 0, ptrH00_ );
545 template<
class ScalarType,
class MV,
class OP,
class DM>
551 setSize( recycledBlocks_, numBlocks_ );
553 Teuchos::RCP<MV>
Vnext;
554 Teuchos::RCP<const MV>
Vprev;
555 std::vector<int>
curind(1);
565 Teuchos::RCP<DM>
z0 = DMT::Subview( *z_, 1, 1 );
569 std::vector<int>
prevind(numBlocks_+1);
576 if (U_ == Teuchos::null) {
577 while (stest_->checkStatus(
this) !=
Passed && curDim_+1 <= numBlocks_) {
598 Teuchos::Array<Teuchos::RCP<const MV> >
AVprev(1,
Vprev);
601 Teuchos::RCP<DM>
subH = DMT::Subview(*H2_,
lclDim, 1, ptrH00_, ptrH00_+curDim_);
602 Teuchos::Array<Teuchos::RCP<DM> >
AsubH( 1,
subH );
605 Teuchos::RCP<DM>
subR = DMT::Subview(*H2_, 1, 1, ptrH00_+
lclDim, ptrH00_+curDim_);
611 Teuchos::RCP<DM>
subR2 = DMT::Subview(*R_,
lclDim+1, 1, 0, curDim_);
612 Teuchos::RCP<const DM>
subH2 = DMT::SubviewConst(*H2_,
lclDim+1, 1, ptrH00_, ptrH00_+curDim_);
614 subR2 = Teuchos::null;
626 while (stest_->checkStatus(
this) !=
Passed && curDim_+1 <= numBlocks_) {
641 Vprev = Teuchos::null;
643 DMT::SyncHostToDevice(*H2_);
646 Teuchos::Array<Teuchos::RCP<const MV> > C(1, C_);
647 Teuchos::RCP<DM>
subB = DMT::Subview(*H2_, recycledBlocks_, 1, 0, ptrH00_+curDim_);
648 Teuchos::RCP<DM>
tmpB = DMT::Create(recycledBlocks_, 1);
649 Teuchos::Array<Teuchos::RCP<DM> >
AsubB( 1,
subB );
659 Teuchos::Array<Teuchos::RCP<const MV> >
AVprev(1,
Vprev);
662 Teuchos::RCP<DM>
subH = DMT::Subview(*H2_,
lclDim, 1, ptrH00_, ptrH00_+curDim_);
663 Teuchos::Array<Teuchos::RCP<DM> >
AsubH(1,
subH);
666 Teuchos::RCP<DM>
subR = DMT::Subview(*H2_, 1, 1, ptrH00_+
lclDim, ptrH00_+curDim_);
672 Teuchos::RCP<DM>
subR2 = DMT::Subview(*R_,
lclDim+1, 1, 0, curDim_);
673 Teuchos::RCP<const DM>
subH2 = DMT::SubviewConst(*H2_,
lclDim+1, 1, ptrH00_, ptrH00_+curDim_);
675 subR2 = Teuchos::null;
691 template<
class ScalarType,
class MV,
class OP,
class DM>
695 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
700 int curDim = curDim_;
701 if ( (
dim >= curDim_) && (
dim < getMaxSubspaceDim()) )
704 Teuchos::BLAS<int, ScalarType>
blas;
711 DMT::SyncDeviceToHost(*R_);
712 DMT::SyncDeviceToHost(*z_);
714 for (
i=0;
i<curDim;
i++) {
718 blas.ROT( 1, &(DMT::Value(*R_,
i,curDim)), 1, &(DMT::Value(*R_,
i+1, curDim)), 1, &cs_[
i], &sn_[
i] );
724 blas.ROTG( &(DMT::Value(*R_,curDim,curDim)), &(DMT::Value(*R_,curDim+1,curDim)), &cs_[curDim], &sn_[curDim] );
725 DMT::Value(*R_,curDim+1,curDim) =
zero;
729 blas.ROT( 1, &(DMT::Value(*z_,curDim,0)), 1, &(DMT::Value(*z_,curDim+1,0)), 1, &cs_[curDim], &sn_[curDim] );
731 DMT::SyncHostToDevice(*R_);
732 DMT::SyncHostToDevice(*z_);
Belos header file which uses auto-configuration information to include necessary C++ headers.
Common interface for GCRODR-like iteration classes.
Class which describes the linear problem to be solved by the iterative solver.
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
Declaration of basic traits for the multivector type.
Class which defines basic traits for the operator type.
Class which manages the output and verbosity of the Belos solvers.
Pure virtual base class for defining the status testing capabilities of Belos.
Collection of types and exceptions used within the Belos solvers.
Parent class to all Belos exceptions.
This class implements the GCRODR iteration, where a single-vector Krylov subspace is constructed....
Teuchos::ScalarTraits< ScalarType > SCT
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current solution to the linear problem.
int getNumBlocks() const
Get the maximum number of blocks used by the iterative solver in solving this linear problem.
GCRODRIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP, DM > > &tester, const Teuchos::RCP< MatOrthoManager< ScalarType, MV, OP, DM > > &ortho, Teuchos::ParameterList ¶ms)
GCRODRIter constructor with linear problem, solver utilities, and parameter list of solver options.
GCRODRIterState< ScalarType, MV, DM > getState() const
Get the current state of the linear solver.
SCT::magnitudeType MagnitudeType
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
void setNumBlocks(int numBlocks)
Set the maximum number of blocks used by the iterative solver.
void setBlockSize(int blockSize)
Set the blocksize.
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const
Get a constant reference to the linear problem.
void setSize(int recycledBlocks, int numBlocks)
Set the maximum number of blocks used by the iterative solver and the number of recycled vectors.
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace.
MultiVecTraits< ScalarType, MV, DM > MVT
bool isInitialized()
States whether the solver has been initialized or not.
DenseMatTraits< ScalarType, DM > DMT
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
virtual ~GCRODRIter()
Destructor.
void iterate()
This method performs block Gmres iterations until the status test indicates the need to stop or an er...
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
void updateLSQR(int dim=-1)
Method for updating QR factorization of upper Hessenberg matrix.
void initialize()
Initialize the solver with empty data. Calling this method will result in error, as GCRODRIter must b...
int getNumIters() const
Get the current iteration count.
void resetNumIters(int iter=0)
Reset the iteration count.
OperatorTraits< ScalarType, MV, OP > OPT
GCRODRIterInitFailure is thrown when the GCRODRIter object is unable to generate an initial iterate i...
GCRODRIterInitFailure(const std::string &what_arg)
GCRODRIterOrthoFailure is thrown when the GCRODRIter object is unable to compute independent directio...
GCRODRIterOrthoFailure(const std::string &what_arg)
Common base interface for GCRODRIter and FGCRODRIter.
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
Structure to contain pointers to GCRODRIter state variables.
Teuchos::RCP< DM > H
The current Hessenberg matrix.
Teuchos::RCP< DM > H2
The global projection matrix including Krylov subpace and recycled subspace.
Teuchos::RCP< DM > B
The projection of the Krylov subspace against the recycled subspace.
int curDim
The current dimension of the reduction.
Teuchos::RCP< MV > V
The current Krylov basis.
Teuchos::RCP< MV > U
The recycled subspace and its projection.
Teuchos::RCP< MV > Z
Optional flexible correction basis. Used by FGCRODRIter.