10#ifndef BELOS_PCPG_SOLMGR_HPP
11#define BELOS_PCPG_SOLMGR_HPP
33#include "Teuchos_LAPACK.hpp"
34#ifdef BELOS_TEUCHOS_TIME_MONITOR
35# include "Teuchos_TimeMonitor.hpp"
37#if defined(HAVE_TEUCHOSCORE_CXX11)
38# include <type_traits>
112 template<
class ScalarType,
class MV,
class OP,
class DM = DefaultDenseMatrix<
int,ScalarType>,
113 const
bool supportsScalarType =
114 Belos::Details::LapackSupportsScalar<ScalarType>::value &&
115 ! Teuchos::ScalarTraits<ScalarType>::isComplex>
118 Belos::Details::LapackSupportsScalar<ScalarType>::value &&
119 ! Teuchos::ScalarTraits<ScalarType>::isComplex>
121 static const bool scalarTypeIsSupported =
123 ! Teuchos::ScalarTraits<ScalarType>::isComplex;
125 scalarTypeIsSupported> base_type;
132 const Teuchos::RCP<Teuchos::ParameterList> &pl) :
138 Teuchos::RCP<SolverManager<ScalarType, MV, OP, DM> >
clone ()
const override {
143 template<
class ScalarType,
class MV,
class OP,
class DM>
150 typedef Teuchos::ScalarTraits<ScalarType> SCT;
151 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
152 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
202 const Teuchos::RCP<Teuchos::ParameterList> &pl );
208 virtual Teuchos::RCP<SolverManager<ScalarType, MV, OP, DM> >
clone ()
const override {
224 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const override;
235 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
236 return Teuchos::tuple(timerSolve_);
266 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms )
override;
270 debugStatusTest_ = debugStatusTest;
315 std::string description()
const override;
323 int ARRQR(
int numVecs,
int numOrthVecs,
const std::vector<ScalarType>& D);
326 Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > problem_;
329 Teuchos::RCP<OutputManager<ScalarType> > printer_;
330 Teuchos::RCP<std::ostream> outputStream_;
333 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > sTest_;
334 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP,DM> > maxIterTest_;
335 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP,DM> > convTest_;
336 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP,DM> > outputTest_;
337 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > debugStatusTest_;
340 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP,DM> > ortho_;
343 Teuchos::RCP<Teuchos::ParameterList> params_;
346 static constexpr int maxIters_default_ = 1000;
347 static constexpr int deflatedBlocks_default_ = 2;
348 static constexpr int savedBlocks_default_ = 16;
351 static constexpr int outputFreq_default_ = -1;
352 static constexpr const char * label_default_ =
"Belos";
353 static constexpr const char * orthoType_default_ =
"ICGS";
360 MagnitudeType convtol_;
363 MagnitudeType orthoKappa_;
366 MagnitudeType achievedTol_;
374 int deflatedBlocks_, savedBlocks_, verbosity_, outputStyle_, outputFreq_;
375 std::string orthoType_;
378 Teuchos::RCP<MV> U_, C_, R_;
385 Teuchos::RCP<Teuchos::Time> timerSolve_;
393template<
class ScalarType,
class MV,
class OP,
class DM>
395 outputStream_(Teuchos::rcpFromRef(std::cout)),
398 achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
400 maxIters_(maxIters_default_),
401 deflatedBlocks_(deflatedBlocks_default_),
402 savedBlocks_(savedBlocks_default_),
403 verbosity_(verbosity_default_),
404 outputStyle_(outputStyle_default_),
405 outputFreq_(outputFreq_default_),
406 orthoType_(orthoType_default_),
408 label_(label_default_),
414template<
class ScalarType,
class MV,
class OP,
class DM>
417 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
419 outputStream_(Teuchos::rcpFromRef(std::cout)),
423 achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
425 maxIters_(maxIters_default_),
426 deflatedBlocks_(deflatedBlocks_default_),
427 savedBlocks_(savedBlocks_default_),
428 verbosity_(verbosity_default_),
429 outputStyle_(outputStyle_default_),
430 outputFreq_(outputFreq_default_),
431 orthoType_(orthoType_default_),
433 label_(label_default_),
436 TEUCHOS_TEST_FOR_EXCEPTION(
437 problem_.is_null (), std::invalid_argument,
438 "Belos::PCPGSolMgr two-argument constructor: "
439 "'problem' is null. You must supply a non-null Belos::LinearProblem "
440 "instance when calling this constructor.");
442 if (! pl.is_null ()) {
449template<
class ScalarType,
class MV,
class OP,
class DM>
453 if (params_ == Teuchos::null) {
461 if (params->isParameter(
"Maximum Iterations")) {
462 maxIters_ = params->get(
"Maximum Iterations",maxIters_default_);
465 params_->set(
"Maximum Iterations", maxIters_);
466 if (maxIterTest_!=Teuchos::null)
467 maxIterTest_->setMaxIters( maxIters_ );
471 if (params->isParameter(
"Num Saved Blocks")) {
472 savedBlocks_ = params->get(
"Num Saved Blocks",savedBlocks_default_);
473 TEUCHOS_TEST_FOR_EXCEPTION(savedBlocks_ <= 0, std::invalid_argument,
474 "Belos::PCPGSolMgr: \"Num Saved Blocks\" must be strictly positive.");
481 params_->set(
"Num Saved Blocks", savedBlocks_);
483 if (params->isParameter(
"Num Deflated Blocks")) {
484 deflatedBlocks_ = params->get(
"Num Deflated Blocks",deflatedBlocks_default_);
485 TEUCHOS_TEST_FOR_EXCEPTION(deflatedBlocks_ < 0, std::invalid_argument,
486 "Belos::PCPGSolMgr: \"Num Deflated Blocks\" must be positive.");
488 TEUCHOS_TEST_FOR_EXCEPTION(deflatedBlocks_ > savedBlocks_, std::invalid_argument,
489 "Belos::PCPGSolMgr: \"Num Deflated Blocks\" must be <= \"Num Saved Blocks\".");
493 params_->set(
"Num Deflated Blocks",
static_cast<int>(deflatedBlocks_));
497 if (params->isParameter(
"Timer Label")) {
498 std::string tempLabel = params->get(
"Timer Label", label_default_);
501 if (tempLabel != label_) {
503 params_->set(
"Timer Label", label_);
504 std::string solveLabel = label_ +
": PCPGSolMgr total solve time";
505#ifdef BELOS_TEUCHOS_TIME_MONITOR
506 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
508 if (ortho_ != Teuchos::null) {
509 ortho_->setLabel( label_ );
515 if (params->isParameter(
"Verbosity")) {
516 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
517 verbosity_ = params->get(
"Verbosity", verbosity_default_);
519 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
523 params_->set(
"Verbosity", verbosity_);
524 if (printer_ != Teuchos::null)
525 printer_->setVerbosity(verbosity_);
529 if (params->isParameter(
"Output Style")) {
530 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
531 outputStyle_ = params->get(
"Output Style", outputStyle_default_);
533 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
537 params_->set(
"Output Style", outputStyle_);
538 outputTest_ = Teuchos::null;
542 if (params->isParameter(
"Output Stream")) {
543 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
546 params_->set(
"Output Stream", outputStream_);
547 if (printer_ != Teuchos::null)
548 printer_->setOStream( outputStream_ );
553 if (params->isParameter(
"Output Frequency")) {
554 outputFreq_ = params->get(
"Output Frequency", outputFreq_default_);
558 params_->set(
"Output Frequency", outputFreq_);
559 if (outputTest_ != Teuchos::null)
560 outputTest_->setOutputFrequency( outputFreq_ );
564 if (printer_ == Teuchos::null) {
569 bool changedOrthoType =
false;
570 if (params->isParameter(
"Orthogonalization")) {
571 std::string tempOrthoType = params->get(
"Orthogonalization",orthoType_default_);
572 if (tempOrthoType != orthoType_) {
573 orthoType_ = tempOrthoType;
574 changedOrthoType =
true;
577 params_->set(
"Orthogonalization", orthoType_);
580 if (params->isParameter(
"Orthogonalization Constant")) {
581 if (params->isType<MagnitudeType> (
"Orthogonalization Constant")) {
582 orthoKappa_ = params->get (
"Orthogonalization Constant",
586 orthoKappa_ = params->get (
"Orthogonalization Constant",
591 params_->set(
"Orthogonalization Constant",orthoKappa_);
592 if (orthoType_==
"DGKS") {
593 if (orthoKappa_ > 0 && ortho_ != Teuchos::null && !changedOrthoType) {
594 Teuchos::rcp_dynamic_cast<DGKSOrthoManager<ScalarType,MV,OP,DM> >(ortho_)->setDepTol( orthoKappa_ );
600 if (ortho_ == Teuchos::null || changedOrthoType) {
602 Teuchos::RCP<Teuchos::ParameterList> paramsOrtho;
603 if (orthoType_==
"DGKS" && orthoKappa_ > 0) {
604 paramsOrtho = Teuchos::rcp(
new Teuchos::ParameterList());
605 paramsOrtho->set (
"depTol", orthoKappa_ );
608 ortho_ = factory.
makeMatOrthoManager (orthoType_, Teuchos::null, printer_, label_, paramsOrtho);
616 if (params->isParameter(
"Convergence Tolerance")) {
617 if (params->isType<MagnitudeType> (
"Convergence Tolerance")) {
618 convtol_ = params->get (
"Convergence Tolerance",
626 params_->set(
"Convergence Tolerance", convtol_);
627 if (convTest_ != Teuchos::null)
628 convTest_->setTolerance( convtol_ );
634 if (maxIterTest_ == Teuchos::null)
637 if (convTest_ == Teuchos::null)
638 convTest_ = Teuchos::rcp(
new StatusTestResNorm_t( convtol_, 1 ) );
640 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
646 if (Teuchos::nonnull(debugStatusTest_)) {
647 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, sTest_, debugStatusTest_ ) );
656 std::string solverDesc =
" PCPG ";
657 outputTest_->setSolverDesc( solverDesc );
660 if (timerSolve_ == Teuchos::null) {
661 std::string solveLabel = label_ +
": PCPGSolMgr total solve time";
662#ifdef BELOS_TEUCHOS_TIME_MONITOR
663 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
672template<
class ScalarType,
class MV,
class OP,
class DM>
673Teuchos::RCP<const Teuchos::ParameterList>
676 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
677 if (is_null(validPL)) {
678 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
681 "The relative residual tolerance that needs to be achieved by the\n"
682 "iterative solver in order for the linear system to be declared converged.");
683 pl->set(
"Maximum Iterations",
static_cast<int>(maxIters_default_),
684 "The maximum number of iterations allowed for each\n"
685 "set of RHS solved.");
686 pl->set(
"Num Deflated Blocks",
static_cast<int>(deflatedBlocks_default_),
687 "The maximum number of vectors in the seed subspace." );
688 pl->set(
"Num Saved Blocks",
static_cast<int>(savedBlocks_default_),
689 "The maximum number of vectors saved from old Krylov subspaces." );
690 pl->set(
"Verbosity",
static_cast<int>(verbosity_default_),
691 "What type(s) of solver information should be outputted\n"
692 "to the output stream.");
693 pl->set(
"Output Style",
static_cast<int>(outputStyle_default_),
694 "What style is used for the solver information outputted\n"
695 "to the output stream.");
696 pl->set(
"Output Frequency",
static_cast<int>(outputFreq_default_),
697 "How often convergence information should be outputted\n"
698 "to the output stream.");
699 pl->set(
"Output Stream", Teuchos::rcpFromRef(std::cout),
700 "A reference-counted pointer to the output stream where all\n"
701 "solver output is sent.");
702 pl->set(
"Timer Label",
static_cast<const char *
>(label_default_),
703 "The string to use as a prefix for the timer labels.");
704 pl->set(
"Orthogonalization",
static_cast<const char *
>(orthoType_default_),
705 "The type of orthogonalization to use: DGKS, ICGS, IMGS");
707 "The constant used by DGKS orthogonalization to determine\n"
708 "whether another step of classical Gram-Schmidt is necessary.");
716template<
class ScalarType,
class MV,
class OP,
class DM>
723 Teuchos::LAPACK<int,ScalarType> lapack;
724 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
725 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
728 "Belos::PCPGSolMgr::solve(): Linear problem is not a valid object.");
731 "Belos::PCPGSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
735 std::vector<int> currIdx(1);
739 problem_->setLSIndex( currIdx );
742 bool isConverged =
true;
746 Teuchos::ParameterList plist;
747 plist.set(
"Saved Blocks", savedBlocks_);
748 plist.set(
"Block Size", 1);
749 plist.set(
"Keep Diagonal",
true);
750 plist.set(
"Initialize Diagonal",
true);
755 Teuchos::RCP<PCPGIter<ScalarType,MV,OP,DM> > pcpg_iter;
761#ifdef BELOS_TEUCHOS_TIME_MONITOR
762 Teuchos::TimeMonitor slvtimer(*timerSolve_);
764 while ( numRHS2Solve > 0 ) {
767 outputTest_->reset();
770 if (R_ == Teuchos::null)
773 problem_->computeCurrResVec( &*R_ );
779 if( U_ != Teuchos::null ){
784 Teuchos::RCP<MV> cur_soln_vec = problem_->getCurrLHSVec();
785 std::vector<MagnitudeType> rnorm0(1);
789 printer_->stream(
Debug) <<
"Solver Manager: dimU_ = " << dimU_ << std::endl;
792 Teuchos::RCP<const MV> Uactive, Cactive;
793 std::vector<int> active_columns( dimU_ );
794 for (
int i=0; i < dimU_; ++i) active_columns[i] = i;
799 Teuchos::RCP<MV> tempU =
MVT::Clone( *R_, 1 );
801 MVT::MvAddMv( one, *tempU, one, *cur_soln_vec, *cur_soln_vec );
804 std::vector<MagnitudeType> rnorm(1);
806 if( rnorm[0] < rnorm0[0] * .001 ){
809 MVT::MvAddMv( one, *tempU, one, *cur_soln_vec, *cur_soln_vec );
813 Uactive = Teuchos::null;
814 Cactive = Teuchos::null;
815 tempU = Teuchos::null;
826 if( U_ != Teuchos::null ) pcpgState.
U = U_;
827 if( C_ != Teuchos::null ) pcpgState.
C = C_;
828 if( dimU_ > 0 ) pcpgState.
curDim = dimU_;
829 pcpg_iter->initialize(pcpgState);
835 if( !dimU_ ) printer_->stream(
Debug) <<
" No recycled subspace available for RHS index " << currIdx[0] << std::endl << std::endl;
836 pcpg_iter->resetNumIters();
838 if( dimU_ > savedBlocks_ )
839 printer_->stream(
Debug) <<
"Error: dimU_ = " << dimU_ <<
" > savedBlocks_ = " << savedBlocks_ << std::endl;
845 printer_->stream(
Debug) <<
"********** Calling iterate...\n" << std::endl;
846 pcpg_iter->iterate();
853 if ( convTest_->getStatus() ==
Passed ) {
862 else if ( maxIterTest_->getStatus() ==
Passed ) {
873 else if (Teuchos::nonnull(debugStatusTest_) &&
874 debugStatusTest_->getStatus() ==
Passed) {
891 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
892 "Belos::PCPGSolMgr::solve(): Invalid return from PCPGIter::iterate().");
898 achievedTol_ = MT::one();
899 Teuchos::RCP<MV> X = problem_->getLHS();
901 printer_->stream(
Warnings) <<
"Belos::PCPG::solve(): Warning! NaN has been detected!"
905 catch (
const std::exception &e) {
907 printer_->stream(
Errors) <<
"Error! Caught exception in PCPGIter::iterate() at iteration "
908 << pcpg_iter->getNumIters() << std::endl
909 << e.what() << std::endl;
915 Teuchos::RCP<MV> update = pcpg_iter->getCurrentUpdate();
916 problem_->updateSolution( update,
true );
919 problem_->setCurrLS();
927 printer_->stream(
Debug) <<
"SolverManager: dimU_ " << dimU_ <<
" prevUdim= " << q << std::endl;
929 if( q > deflatedBlocks_ )
930 printer_->stream(
Debug) <<
"SolverManager: Error deflatedBlocks = " << deflatedBlocks_ << std::endl;
939 rank = ARRQR(dimU_,q, oldState.
D );
941 printer_->stream(
Debug) <<
" rank decreased in ARRQR, something to do? " << std::endl;
947 if( dimU_ > deflatedBlocks_ ){
949 if( !deflatedBlocks_ ){
952 dimU_ = deflatedBlocks_;
956 bool Harmonic =
false;
958 Teuchos::RCP<MV> Uorth;
960 std::vector<int> active_cols( dimU_ );
961 for (
int i=0; i < dimU_; ++i) active_cols[i] = i;
972 rank = ortho_->normalize(*Uorth, R);
979 "Belos::PCPGSolMgr::solve(): Failed to compute orthonormal basis for initial recycled subspace.");
983 ScalarType *VT=0, *Ur=0;
987 if( problem_->isHermitian() ) lrwork = dimU_;
988 std::vector<ScalarType> work(lwork);
989 std::vector<ScalarType> Svec(dimU_);
990 std::vector<ScalarType> rwork(lrwork);
991 lapack.GESVD(
'N',
'O',
1000 "Belos::PCPGSolMgr::solve(): LAPACK _GESVD failed to compute singular values.");
1004 if( work[0] != 67. * dimU_ )
1005 printer_->stream(
Debug) <<
" SVD " << dimU_ <<
" lwork " << work[0] << std::endl;
1006 for(
int i=0; i< dimU_; i++)
1007 printer_->stream(
Debug) << i <<
" " << Svec[i] << std::endl;
1011 int startRow = 0, startCol = 0;
1013 startCol = dimU_ - deflatedBlocks_;
1017 std::vector<int> active_columns( dimU_ );
1018 std::vector<int> def_cols( deflatedBlocks_ );
1019 for (
int i=0; i < dimU_; ++i) active_columns[i] = i;
1020 for (
int i=0; i < deflatedBlocks_; ++i) def_cols[i] = i;
1028 dimU_ = deflatedBlocks_;
1030 printer_->stream(
Debug) <<
" Generated recycled subspace using RHS index " << currIdx[0] <<
" of dimension " << dimU_ << std::endl << std::endl;
1033 problem_->setCurrLS();
1037 if ( numRHS2Solve > 0 ) {
1041 problem_->setLSIndex( currIdx );
1044 currIdx.resize( numRHS2Solve );
1053#ifdef BELOS_TEUCHOS_TIME_MONITOR
1058 Teuchos::TimeMonitor::summarize( printer_->stream(
TimingDetails) );
1063 using Teuchos::rcp_dynamic_cast;
1066 const std::vector<MagnitudeType>* pTestValues =
1067 rcp_dynamic_cast<conv_test_type>(convTest_)->
getTestValue();
1069 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1070 "Belos::PCPGSolMgr::solve(): The convergence test's getTestValue() "
1071 "method returned NULL. Please report this bug to the Belos developers.");
1073 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1074 "Belos::PCPGSolMgr::solve(): The convergence test's getTestValue() "
1075 "method returned a vector of length zero. Please report this bug to the "
1076 "Belos developers.");
1081 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1085 numIters_ = maxIterTest_->getNumIters();
1096template<
class ScalarType,
class MV,
class OP,
class DM>
1100 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1101 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1104 ScalarType gamma, anorm;
1105 Teuchos::RCP<DM> alpha = DMT::Create( 1, 1 );
1106 std::vector<int> curind(1);
1107 std::vector<int> ipiv(p - q);
1108 std::vector<ScalarType> Pivots(p);
1110 ScalarType rteps = 1.5e-8;
1113 for( i = q ; i < p ; i++ ){
1116 RCP<MV> P = MVT::CloneViewNonConst(*U_,curind);
1117 RCP<MV> AP = MVT::CloneViewNonConst(*C_,curind);
1118 anorm = one / Teuchos::ScalarTraits<ScalarType>::squareroot( D[i-q] ) ;
1119 MVT::MvScale( *P, anorm );
1120 MVT::MvScale( *AP, anorm );
1124 for( i = q ; i < p ; i++ ){
1125 if( q < i && i < p-1 ){
1128 for( j = i+1 ; j < p ; j++ ){
1129 const int k = ipiv[j-q];
1130 if( Pivots[k] > Pivots[l] ){
1137 ipiv[imax-q] = ipiv[i-q];
1143 if( Pivots[k] > 1.5625e-2 ){
1148 RCP<const MV> P = MVT::CloneView(*U_,curind);
1149 RCP<const MV> AP = MVT::CloneView(*C_,curind);
1150 MVT::MvTransMv( one, *P, *AP, *alpha);
1151 DMT::SyncDeviceToHost( *alpha );
1152 anorm = Teuchos::ScalarTraits<ScalarType>::squareroot( DMT::ValueConst(*alpha,0,0) ) ;
1154 if( rteps <= anorm && anorm < 9.765625e-4){
1162 printer_->stream(
Errors) <<
"ARRQR: Bad case not implemented" << std::endl;
1164 if( anorm < rteps ){
1165 printer_->stream(
Errors) <<
"ARRQR : deficient case not implemented " << std::endl;
1173 RCP<MV> P = MVT::CloneViewNonConst(*U_,curind);
1174 RCP<MV> AP = MVT::CloneViewNonConst(*C_,curind);
1175 MVT::MvScale( *P, anorm );
1176 MVT::MvScale( *AP, anorm );
1178 for( j = i+1 ; j < p ; j++ ){
1181 RCP<MV> Q = MVT::CloneViewNonConst(*U_,curind);
1182 MVT::MvTransMv( one, *Q, *AP, *alpha);
1183 DMT::SyncDeviceToHost(*alpha);
1184 MVT::MvAddMv( -DMT::ValueConst(*alpha,0,0), *P, one, *Q, *Q );
1185 RCP<MV> AQ = MVT::CloneViewNonConst(*C_,curind);
1186 MVT::MvAddMv( -DMT::ValueConst(*alpha,0,0), *AP, one, *AQ, *AQ );
1187 gamma = ( Pivots[l] - DMT::ValueConst(*alpha,0,0))*( Pivots[l] + DMT::ValueConst(*alpha,0,0));
1189 Pivots[l] = Teuchos::ScalarTraits<ScalarType>::squareroot( gamma );
1200template<
class ScalarType,
class MV,
class OP,
class DM>
1203 std::ostringstream oss;
1204 oss <<
"Belos::PCPGSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<
">";
1206 oss <<
"Ortho Type='"<<orthoType_;
1213#ifdef HAVE_BELOS_TPETRA
1216#define BELOS_TPETRA_PCPGSOLMGR_NOEXTERN_CALL(SC, LO, GO, NT) \
1217 BELOS_TPETRA_CALL(Belos::PCPGSolMgr, SC, LO, GO, NT)
1219#define BELOS_TPETRA_PCPGSOLMGR_EXTERN_CALL(SC, LO, GO, NT) \
1220 BELOS_TPETRA_EXTERN_CALL(Belos::PCPGSolMgr, SC, LO, GO, NT)
1222TPETRA_INSTANTIATE_SLGN_NO_ORDINAL_SCALAR(BELOS_TPETRA_PCPGSOLMGR_EXTERN_CALL)
Belos header file which uses auto-configuration information to include necessary C++ headers.
Full specialization of Belos::DenseMatTraits for Kokkos::DualView with arbitrary scalarType....
Class which describes the linear problem to be solved by the iterative solver.
Class which manages the output and verbosity of the Belos solvers.
Belos concrete class to iterate Preconditioned Conjugate Projected Gradients.
Pure virtual base class which describes the basic interface for a solver manager.
Belos::StatusTest for logically combining several status tests.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Full specialization of Belos::DenseMatTraits for Teuchos::SerialDenseMatrix with ordinal type int and...
Collection of types and exceptions used within the Belos solvers.
BelosError(const std::string &what_arg)
Virtual base class which defines basic traits for the multi-vector type.
static void SyncHostToDevice(DM &dm)
static int GetNumRows(const DM &dm)
Obtain the number of rows of dm.
static Teuchos::RCP< DM > CreateCopy(const DM &dm, bool transpose=false)
Create a new copy DM, possibly transposed.
static ScalarType * GetRawHostPtr(DM &dm)
Returns a raw pointer to the (non-const) data on the host.
static void SyncDeviceToHost(DM &dm)
static Teuchos::RCP< const DM > SubviewConst(const DM &source, int numRows, int numCols, int startRow=0, int startCol=0)
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.
static int GetNumCols(const DM &dm)
Obtain the number of columns of dm.
Base class for Belos::SolverManager subclasses which normally can only compile with real ScalarType t...
Traits class which defines basic operations on multivectors.
static void MvInit(MV &mv, const ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
static void MvNorm(const MV &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, NormType type=TwoNorm)
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
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 void MvTransMv(const ScalarType alpha, const MV &A, const MV &mv, DM &B)
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
static int GetNumberVecs(const MV &mv)
Class which defines basic traits for the operator type.
Enumeration of all valid Belos (Mat)OrthoManager classes.
Teuchos::RCP< Belos::MatOrthoManager< Scalar, MV, OP, DM > > makeMatOrthoManager(const std::string &ortho, const Teuchos::RCP< const OP > &M, const Teuchos::RCP< OutputManager< Scalar > > &, const std::string &label, const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Return an instance of the specified MatOrthoManager subclass.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
This class implements the PCPG iteration, where a single-vector Krylov subspace is constructed....
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem) override
Set the linear problem that needs to be solved.
int getNumIters() const override
Get the iteration count for the most recent call to solve().
PCPGSolMgr()
Empty constructor for PCPGSolMgr. This constructor takes no arguments and sets the default values for...
virtual Teuchos::RCP< SolverManager< ScalarType, MV, OP, DM > > clone() const override
clone for Inverted Injection (DII)
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
virtual ~PCPGSolMgr()
Destructor.
void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP, DM > > &debugStatusTest) override
Set a debug status test, OR-combined into the top-level status test.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const override
Get current linear problem being solved for in this object.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms) override
Set the parameters the solver manager should use to solve the linear problem.
PCPG iterative linear solver.
Teuchos::RCP< SolverManager< ScalarType, MV, OP, DM > > clone() const override
clone for Inverted Injection (DII)
PCPGSolMgr(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem, const Teuchos::RCP< Teuchos::ParameterList > &pl)
PCPGSolMgrLAPACKFailure is thrown when a nonzero value is retuned from an LAPACK call.
PCPGSolMgrLAPACKFailure(const std::string &what_arg)
PCPGSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i.e.
PCPGSolMgrLinearProblemFailure(const std::string &what_arg)
PCPGSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate orthonormal...
PCPGSolMgrOrthoFailure(const std::string &what_arg)
A class for extending the status testing capabilities of Belos via logical combinations.
An implementation of StatusTestResNorm using a family of residual norms.
const std::vector< MagnitudeType > * getTestValue() const
Returns the test value, , computed in most recent call to CheckStatus.
A pure virtual class for defining the status tests for the Belos iterative solvers.
A Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP, DM > > create(const Teuchos::RCP< OutputManager< ScalarType > > &printer, Teuchos::RCP< StatusTest< ScalarType, MV, OP, DM > > test, int mod, int printStates)
Create the StatusTestOutput object specified by the outputStyle.
ReturnType
Whether the Belos solve converged for all linear systems.
ResetType
How to reset the solver.
Default parameters common to most Belos solvers.
static const double convTol
Default convergence tolerance.
static const double orthoKappa
DGKS orthogonalization constant.
Structure to contain pointers to PCPGIter state variables.
int curDim
The current dimension of the reduction.
int prevUdim
Number of block columns in matrices C and U before current iteration.
Teuchos::RCP< MV > C
C = AU, U spans recycled subspace.
std::vector< ScalarType > D
The current diagonal matrix.
Teuchos::RCP< MV > R
The current residual.
Teuchos::RCP< MV > U
The recycled subspace.