10#ifndef BELOS_FGCRODR_ITER_HPP
11#define BELOS_FGCRODR_ITER_HPP
33template<
class ScalarType,
class MV,
class OP,
class DM = DefaultDenseMatrix<
int, ScalarType> >
39 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
46 Teuchos::ParameterList ¶ms);
76 Teuchos::RCP<const MV>
84 if (!initialized_)
return 0;
97 setSize(recycledBlocks_, numBlocks);
103 TEUCHOS_TEST_FOR_EXCEPTION(
105 std::invalid_argument,
106 "Belos::FGCRODRIter::setBlockSize(): Cannot use a block size that is not one.");
109 void setSize(
int recycledBlocks,
int numBlocks) {
110 if (recycledBlocks_ != recycledBlocks)
111 recycledBlocks_ = recycledBlocks;
113 if (numBlocks_ != numBlocks) {
114 numBlocks_ = numBlocks;
115 cs_.resize(numBlocks_ + 1);
116 sn_.resize(numBlocks_ + 1);
118 R_ =
DMT::Create(numBlocks_ + 1, numBlocks_,
false);
125 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > lp_;
126 const Teuchos::RCP<OutputManager<ScalarType> > om_;
127 const Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > stest_;
128 const Teuchos::RCP<OrthoManager<ScalarType,MV,DM> > ortho_;
133 std::vector<ScalarType> sn_;
134 std::vector<MagnitudeType> cs_;
142 Teuchos::RCP<MV> U_, C_;
144 Teuchos::RCP<DM> H2_;
154template<
class ScalarType,
class MV,
class OP,
class DM>
160 Teuchos::ParameterList ¶ms) :
179 TEUCHOS_TEST_FOR_EXCEPTION(
180 !params.isParameter(
"Num Blocks"),
181 std::invalid_argument,
182 "Belos::FGCRODRIter::constructor: mandatory parameter \"Num Blocks\" is not specified.");
183 int nb = Teuchos::getParameter<int>(params,
"Num Blocks");
185 TEUCHOS_TEST_FOR_EXCEPTION(
186 !params.isParameter(
"Recycled Blocks"),
187 std::invalid_argument,
188 "Belos::FGCRODRIter::constructor: mandatory parameter \"Recycled Blocks\" is not specified.");
189 int rb = Teuchos::getParameter<int>(params,
"Recycled Blocks");
191 TEUCHOS_TEST_FOR_EXCEPTION(
193 std::invalid_argument,
194 "Belos::FGCRODRIter() was passed a non-positive argument for \"Num Blocks\".");
196 TEUCHOS_TEST_FOR_EXCEPTION(
198 std::invalid_argument,
199 "Belos::FGCRODRIter() the number of recycled blocks is larger than the allowable subspace.");
202 recycledBlocks_ = rb;
204 cs_.resize(numBlocks_ + 1);
205 sn_.resize(numBlocks_ + 1);
207 R_ =
DMT::Create(numBlocks_ + 1, numBlocks_,
false);
212template<
class ScalarType,
class MV,
class OP,
class DM>
216 Teuchos::RCP<MV> currentUpdate = Teuchos::null;
219 return currentUpdate;
222 const ScalarType one = SCT::one();
223 const ScalarType zero = SCT::zero();
225 Teuchos::BLAS<int,ScalarType> blas;
234 blas.TRSM(Teuchos::LEFT_SIDE,
237 Teuchos::NON_UNIT_DIAG,
249 std::vector<int> index(curDim_);
250 for (
int i = 0; i < curDim_; ++i) {
258 if (U_ != Teuchos::null) {
259 Teuchos::RCP<DM> z =
DMT::Create(recycledBlocks_, 1);
263 blas.GEMM(Teuchos::NO_TRANS,
282 return currentUpdate;
287template<
class ScalarType,
class MV,
class OP,
class DM>
288Teuchos::RCP<const MV>
292 if (norms &&
static_cast<int>(norms->size()) == 0) {
299 (*norms)[0] = SCT::magnitude(curNativeResid);
302 return Teuchos::null;
307template<
class ScalarType,
class MV,
class OP,
class DM>
312 if (newstate.
V != Teuchos::null &&
313 newstate.
Z != Teuchos::null &&
314 newstate.
H2 != Teuchos::null) {
315 curDim_ = newstate.
curDim;
323 if (newstate.
U == Teuchos::null) {
324 ptrH00_ = recycledBlocks_ + 1;
325 H_ =
DMT::Subview(*H2_, numBlocks_ + 1, numBlocks_, ptrH00_, ptrH00_);
329 ptrH00_ = recycledBlocks_;
330 H_ =
DMT::Subview(*H2_, numBlocks_ + 1, numBlocks_, ptrH00_, ptrH00_);
331 B_ =
DMT::Subview(*H2_, recycledBlocks_, numBlocks_, 0, ptrH00_);
335 TEUCHOS_TEST_FOR_EXCEPTION(
336 newstate.
V == Teuchos::null,
337 std::invalid_argument,
338 "Belos::FGCRODRIter::initialize(): GCRODRIterState does not have V initialized.");
339 TEUCHOS_TEST_FOR_EXCEPTION(
340 newstate.
Z == Teuchos::null,
341 std::invalid_argument,
342 "Belos::FGCRODRIter::initialize(): GCRODRIterState does not have Z initialized.");
343 TEUCHOS_TEST_FOR_EXCEPTION(
344 newstate.
H2 == Teuchos::null,
345 std::invalid_argument,
346 "Belos::FGCRODRIter::initialize(): GCRODRIterState does not have H2 initialized.");
354template<
class ScalarType,
class MV,
class OP,
class DM>
358 TEUCHOS_TEST_FOR_EXCEPTION(
359 initialized_ ==
false,
361 "Belos::FGCRODRIter::iterate(): FGCRODRIter class not initialized.");
363 setSize(recycledBlocks_, numBlocks_);
365 Teuchos::RCP<MV> Vnext;
366 Teuchos::RCP<MV> Znext;
367 Teuchos::RCP<const MV> Vprev;
369 std::vector<int> curind(1);
378 int rank = ortho_->normalize(*Vnext, z0);
380 TEUCHOS_TEST_FOR_EXCEPTION(
383 "Belos::FGCRODRIter::iterate(): couldn't generate initial basis of full rank.");
385 std::vector<int> prevind(numBlocks_ + 1);
387 while (stest_->checkStatus(
this) !=
Passed && curDim_ + 1 <= numBlocks_) {
390 const int lclDim = curDim_ + 1;
405 lp_->applyRightPrec(*Vprev, *Znext);
406 Vprev = Teuchos::null;
409 lp_->applyOp(*Znext, *Vnext);
410 Znext = Teuchos::null;
412 if (U_ != Teuchos::null) {
416 Teuchos::Array<Teuchos::RCP<const MV> > C(1, C_);
417 Teuchos::RCP<DM> subB =
418 DMT::Subview(*H2_, recycledBlocks_, 1, 0, ptrH00_ + curDim_);
419 Teuchos::Array<Teuchos::RCP<DM> > AsubB(1, subB);
421 ortho_->project(*Vnext, AsubB, C);
425 prevind.resize(lclDim);
426 for (
int i = 0; i < lclDim; ++i) {
431 Teuchos::Array<Teuchos::RCP<const MV> > AVprev(1, Vprev);
433 Teuchos::RCP<DM> subH =
434 DMT::Subview(*H2_, lclDim, 1, ptrH00_, ptrH00_ + curDim_);
435 Teuchos::Array<Teuchos::RCP<DM> > AsubH(1, subH);
437 Teuchos::RCP<DM> subR =
438 DMT::Subview(*H2_, 1, 1, ptrH00_ + lclDim, ptrH00_ + curDim_);
440 rank = ortho_->projectAndNormalize(*Vnext, AsubH, subR, AVprev);
442 Teuchos::RCP<DM> subR2 =
444 Teuchos::RCP<const DM> subH2 =
449 TEUCHOS_TEST_FOR_EXCEPTION(
452 "Belos::FGCRODRIter::iterate(): couldn't generate basis of full rank.");
462template<
class ScalarType,
class MV,
class OP,
class DM>
467 const ScalarType zero = SCT::zero();
469 int curDim = curDim_;
474 Teuchos::BLAS<int, ScalarType> blas;
479 for (i = 0; i < curDim; ++i) {
Belos concrete class for performing the GCRO-DR iteration.
Virtual base class which defines basic traits for the multi-vector type.
static Teuchos::RCP< DM > Subview(DM &source, int numRows, int numCols, int startRow=0, int startCol=0)
Marks host data modified to avoid device sync errors.
static Teuchos::RCP< DM > SubviewCopy(const DM &source, int numRows, int numCols, int startRow=0, int startCol=0)
Returns a deep copy of the requested subview.
static void SyncHostToDevice(DM &dm)
static void PutScalar(DM &dm, ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Fill all entries with value. Value is zero if not specified.
static ScalarType * GetRawHostPtr(DM &dm)
Returns a raw pointer to the (non-const) data on the host.
static const ScalarType & ValueConst(const DM &dm, const int i, const int j)
Access a const reference to the (i,j) entry of dm, e_i^T dm e_j.
static void SyncDeviceToHost(DM &dm)
static void Assign(DM &thisDM, const DM &sourceDM)
Copies entries of sourceDM to thisDM (deep copy).
static Teuchos::RCP< const DM > SubviewConst(const DM &source, int numRows, int numCols, int startRow=0, int startCol=0)
static ScalarType const * GetConstRawHostPtr(const DM &dm)
Returns a raw pointer to const data on the host.
static ScalarType & Value(DM &dm, const int i, const int j)
Access a reference to the (i,j) entry of dm, e_i^T dm e_j.
static int GetStride(const DM &dm)
Obtain the stride between the columns of dm.
static Teuchos::RCP< DM > Create()
Creates a new empty DM with no dimension.
GCRODRIterState< ScalarType, MV, DM > getState() const
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const
Get a constant reference to the linear problem.
void setSize(int recycledBlocks, int numBlocks)
MultiVecTraits< ScalarType, MV, DM > MVT
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
SCT::magnitudeType MagnitudeType
Teuchos::ScalarTraits< ScalarType > SCT
OperatorTraits< ScalarType, MV, OP > OPT
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
int getCurSubspaceDim() const
void resetNumIters(int iter=0)
Reset the iteration count to iter.
int getNumIters() const
Get the current iteration count.
int getMaxSubspaceDim() const
void updateLSQR(int dim=-1)
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver in solving this linear problem.
void iterate()
This method performs linear solver iterations until the status test indicates the need to stop or an ...
void setNumBlocks(int numBlocks)
DenseMatTraits< ScalarType, DM > DMT
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
bool isInitialized()
States whether the solver has been initialized or not.
FGCRODRIter(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)
FGCRODRIterInitFailure(const std::string &what_arg)
FGCRODRIterOrthoFailure(const std::string &what_arg)
GCRODRIterInitFailure(const std::string &what_arg)
GCRODRIterOrthoFailure(const std::string &what_arg)
Common base interface for GCRODRIter and FGCRODRIter.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
Traits class which defines basic operations on multivectors.
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const DM &B, const ScalarType beta, MV &mv)
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Class which defines basic traits for the operator type.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
A pure virtual class for defining the status tests for the Belos iterative solvers.
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.