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 &
params);
61 state.curDim = curDim_;
76 Teuchos::RCP<const MV>
84 if (!initialized_)
return 0;
105 std::invalid_argument,
106 "Belos::FGCRODRIter::setBlockSize(): Cannot use a block size that is not one.");
115 cs_.resize(numBlocks_ + 1);
116 sn_.resize(numBlocks_ + 1);
117 z_ = DMT::Create(numBlocks_ + 1, 1,
false);
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 &
params) :
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");
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");
193 std::invalid_argument,
194 "Belos::FGCRODRIter() was passed a non-positive argument for \"Num Blocks\".");
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);
206 z_ = DMT::Create(numBlocks_ + 1, 1,
false);
207 R_ = DMT::Create(numBlocks_ + 1, numBlocks_,
false);
212template<
class ScalarType,
class MV,
class OP,
class DM>
225 Teuchos::BLAS<int,ScalarType>
blas;
229 Teuchos::RCP<DM> y = DMT::SubviewCopy(*z_, curDim_, 1);
231 DMT::SyncDeviceToHost(*y);
232 DMT::SyncDeviceToHost(*R_);
234 blas.TRSM(Teuchos::LEFT_SIDE,
237 Teuchos::NON_UNIT_DIAG,
241 DMT::GetConstRawHostPtr(*R_),
243 DMT::GetRawHostPtr(*y),
246 DMT::SyncHostToDevice(*y);
249 std::vector<int> index(curDim_);
250 for (
int i = 0;
i < curDim_; ++
i) {
254 Teuchos::RCP<const MV>
Zjp1 = MVT::CloneView(*Z_, index);
258 if (U_ != Teuchos::null) {
259 Teuchos::RCP<DM> z = DMT::Create(recycledBlocks_, 1);
261 DMT::SyncDeviceToHost(*H2_);
263 blas.GEMM(Teuchos::NO_TRANS,
269 DMT::GetConstRawHostPtr(*B_),
271 DMT::GetConstRawHostPtr(*y),
274 DMT::GetRawHostPtr(*z),
277 DMT::SyncHostToDevice(*z);
287template<
class ScalarType,
class MV,
class OP,
class DM>
288Teuchos::RCP<const MV>
292 if (
norms &&
static_cast<int>(
norms->size()) == 0) {
297 DMT::SyncDeviceToHost(*z_);
302 return Teuchos::null;
307template<
class ScalarType,
class MV,
class OP,
class DM>
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_);
337 std::invalid_argument,
338 "Belos::FGCRODRIter::initialize(): GCRODRIterState does not have V initialized.");
341 std::invalid_argument,
342 "Belos::FGCRODRIter::initialize(): GCRODRIterState does not have Z initialized.");
345 std::invalid_argument,
346 "Belos::FGCRODRIter::initialize(): GCRODRIterState does not have H2 initialized.");
354template<
class ScalarType,
class MV,
class OP,
class DM>
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);
377 Teuchos::RCP<DM>
z0 = DMT::Subview(*z_, 1, 1);
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;
406 Vprev = Teuchos::null;
410 Znext = Teuchos::null;
412 if (U_ != Teuchos::null) {
413 DMT::SyncHostToDevice(*H2_);
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);
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_);
442 Teuchos::RCP<DM>
subR2 =
443 DMT::Subview(*R_,
lclDim + 1, 1, 0, curDim_);
444 Teuchos::RCP<const DM>
subH2 =
445 DMT::SubviewConst(*H2_,
lclDim + 1, 1, ptrH00_, ptrH00_ + curDim_);
452 "Belos::FGCRODRIter::iterate(): couldn't generate basis of full rank.");
462template<
class ScalarType,
class MV,
class OP,
class DM>
469 int curDim = curDim_;
470 if ((
dim >= curDim_) && (
dim < getMaxSubspaceDim())) {
474 Teuchos::BLAS<int, ScalarType>
blas;
476 DMT::SyncDeviceToHost(*R_);
477 DMT::SyncDeviceToHost(*z_);
479 for (
i = 0;
i < curDim; ++
i) {
481 &(DMT::Value(*R_,
i, curDim)),
483 &(DMT::Value(*R_,
i+1, curDim)),
489 blas.ROTG(&(DMT::Value(*R_, curDim, curDim)),
490 &(DMT::Value(*R_, curDim+1, curDim)),
494 DMT::Value(*R_, curDim+1, curDim) =
zero;
497 &(DMT::Value(*z_, curDim, 0)),
499 &(DMT::Value(*z_, curDim+1, 0)),
504 DMT::SyncHostToDevice(*R_);
505 DMT::SyncHostToDevice(*z_);
Belos concrete class for performing the GCRO-DR iteration.
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 is thrown when the GCRODRIter object is unable to generate an initial iterate i...
GCRODRIterOrthoFailure is thrown when the GCRODRIter object is unable to compute independent directio...
Common base interface for GCRODRIter and FGCRODRIter.
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).