42 #ifndef BELOS_PSEUDO_BLOCK_GMRES_SOLMGR_HPP
43 #define BELOS_PSEUDO_BLOCK_GMRES_SOLMGR_HPP
59 #ifdef HAVE_BELOS_TSQR
61 #endif // HAVE_BELOS_TSQR
66 #ifdef BELOS_TEUCHOS_TIME_MONITOR
125 template<
class ScalarType,
class MV,
class OP>
290 return Teuchos::tuple(timerSolve_);
467 bool checkStatusTest();
494 static constexpr
int maxRestarts_default_ = 20;
495 static constexpr
int maxIters_default_ = 1000;
496 static constexpr
bool showMaxResNormOnly_default_ =
false;
497 static constexpr
int blockSize_default_ = 1;
498 static constexpr
int numBlocks_default_ = 300;
501 static constexpr
int outputFreq_default_ = -1;
502 static constexpr
int defQuorum_default_ = 1;
503 static constexpr
const char * impResScale_default_ =
"Norm of Preconditioned Initial Residual";
504 static constexpr
const char * expResScale_default_ =
"Norm of Initial Residual";
505 static constexpr
const char * label_default_ =
"Belos";
506 static constexpr
const char * orthoType_default_ =
"ICGS";
507 static constexpr std::ostream * outputStream_default_ = &std::cout;
510 MagnitudeType convtol_, orthoKappa_, achievedTol_;
511 int maxRestarts_, maxIters_, numIters_;
512 int blockSize_, numBlocks_, verbosity_, outputStyle_, outputFreq_, defQuorum_;
513 bool showMaxResNormOnly_;
514 std::string orthoType_;
515 std::string impResScale_, expResScale_;
516 MagnitudeType resScaleFactor_;
523 bool isSet_, isSTSet_, expResTest_;
529 template<
class ScalarType,
class MV,
class OP>
531 outputStream_(Teuchos::
rcp(outputStream_default_,false)),
532 taggedTests_(Teuchos::null),
535 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
536 maxRestarts_(maxRestarts_default_),
537 maxIters_(maxIters_default_),
539 blockSize_(blockSize_default_),
540 numBlocks_(numBlocks_default_),
541 verbosity_(verbosity_default_),
542 outputStyle_(outputStyle_default_),
543 outputFreq_(outputFreq_default_),
544 defQuorum_(defQuorum_default_),
545 showMaxResNormOnly_(showMaxResNormOnly_default_),
546 orthoType_(orthoType_default_),
547 impResScale_(impResScale_default_),
548 expResScale_(expResScale_default_),
550 label_(label_default_),
558 template<
class ScalarType,
class MV,
class OP>
563 outputStream_(Teuchos::
rcp(outputStream_default_,false)),
564 taggedTests_(Teuchos::null),
567 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
568 maxRestarts_(maxRestarts_default_),
569 maxIters_(maxIters_default_),
571 blockSize_(blockSize_default_),
572 numBlocks_(numBlocks_default_),
573 verbosity_(verbosity_default_),
574 outputStyle_(outputStyle_default_),
575 outputFreq_(outputFreq_default_),
576 defQuorum_(defQuorum_default_),
577 showMaxResNormOnly_(showMaxResNormOnly_default_),
578 orthoType_(orthoType_default_),
579 impResScale_(impResScale_default_),
580 expResScale_(expResScale_default_),
582 label_(label_default_),
597 template<
class ScalarType,
class MV,
class OP>
603 using Teuchos::parameterList;
605 using Teuchos::rcp_dynamic_cast;
608 if (params_ == Teuchos::null) {
609 params_ = parameterList (*getValidParameters ());
621 maxRestarts_ = params->
get (
"Maximum Restarts", maxRestarts_default_);
624 params_->set (
"Maximum Restarts", maxRestarts_);
629 maxIters_ = params->
get (
"Maximum Iterations", maxIters_default_);
632 params_->set (
"Maximum Iterations", maxIters_);
633 if (! maxIterTest_.is_null ()) {
634 maxIterTest_->setMaxIters (maxIters_);
640 blockSize_ = params->
get (
"Block Size", blockSize_default_);
642 blockSize_ <= 0, std::invalid_argument,
643 "Belos::PseudoBlockGmresSolMgr::setParameters: "
644 "The \"Block Size\" parameter must be strictly positive, "
645 "but you specified a value of " << blockSize_ <<
".");
648 params_->set (
"Block Size", blockSize_);
653 numBlocks_ = params->
get (
"Num Blocks", numBlocks_default_);
655 numBlocks_ <= 0, std::invalid_argument,
656 "Belos::PseudoBlockGmresSolMgr::setParameters: "
657 "The \"Num Blocks\" parameter must be strictly positive, "
658 "but you specified a value of " << numBlocks_ <<
".");
661 params_->set (
"Num Blocks", numBlocks_);
666 const std::string tempLabel = params->
get (
"Timer Label", label_default_);
669 if (tempLabel != label_) {
671 params_->set (
"Timer Label", label_);
672 const std::string solveLabel =
673 label_ +
": PseudoBlockGmresSolMgr total solve time";
674 #ifdef BELOS_TEUCHOS_TIME_MONITOR
676 #endif // BELOS_TEUCHOS_TIME_MONITOR
677 if (ortho_ != Teuchos::null) {
678 ortho_->setLabel( label_ );
685 std::string tempOrthoType = params->
get (
"Orthogonalization", orthoType_default_);
686 #ifdef HAVE_BELOS_TSQR
688 tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" &&
689 tempOrthoType !=
"IMGS" && tempOrthoType !=
"TSQR",
690 std::invalid_argument,
691 "Belos::PseudoBlockGmresSolMgr::setParameters: "
692 "The \"Orthogonalization\" parameter must be one of \"DGKS\", \"ICGS\", "
693 "\"IMGS\", or \"TSQR\".");
696 tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" &&
697 tempOrthoType !=
"IMGS",
698 std::invalid_argument,
699 "Belos::PseudoBlockGmresSolMgr::setParameters: "
700 "The \"Orthogonalization\" parameter must be one of \"DGKS\", \"ICGS\", "
702 #endif // HAVE_BELOS_TSQR
704 if (tempOrthoType != orthoType_) {
705 orthoType_ = tempOrthoType;
706 params_->set(
"Orthogonalization", orthoType_);
708 if (orthoType_ ==
"DGKS") {
710 if (orthoKappa_ <= 0) {
711 ortho_ =
rcp (
new ortho_type (label_));
714 ortho_ =
rcp (
new ortho_type (label_));
715 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
718 else if (orthoType_ ==
"ICGS") {
720 ortho_ =
rcp (
new ortho_type (label_));
722 else if (orthoType_ ==
"IMGS") {
724 ortho_ =
rcp (
new ortho_type (label_));
726 #ifdef HAVE_BELOS_TSQR
727 else if (orthoType_ ==
"TSQR") {
729 ortho_ =
rcp (
new ortho_type (label_));
731 #endif // HAVE_BELOS_TSQR
736 if (params->
isParameter (
"Orthogonalization Constant")) {
737 if (params->
isType<MagnitudeType> (
"Orthogonalization Constant")) {
738 orthoKappa_ = params->
get (
"Orthogonalization Constant",
742 orthoKappa_ = params->
get (
"Orthogonalization Constant",
747 params_->set (
"Orthogonalization Constant", orthoKappa_);
748 if (orthoType_ ==
"DGKS") {
749 if (orthoKappa_ > 0 && ! ortho_.is_null ()) {
751 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
758 if (Teuchos::isParameterType<int> (*params,
"Verbosity")) {
759 verbosity_ = params->
get (
"Verbosity", verbosity_default_);
761 verbosity_ = (int) Teuchos::getParameter<Belos::MsgType> (*params,
"Verbosity");
765 params_->set (
"Verbosity", verbosity_);
766 if (! printer_.is_null ()) {
767 printer_->setVerbosity (verbosity_);
773 if (Teuchos::isParameterType<int> (*params,
"Output Style")) {
774 outputStyle_ = params->
get (
"Output Style", outputStyle_default_);
776 outputStyle_ = (int) Teuchos::getParameter<Belos::OutputType> (*params,
"Output Style");
780 params_->set (
"Output Style", verbosity_);
781 if (! outputTest_.is_null ()) {
788 if (params->
isSublist (
"User Status Tests")) {
790 if ( userStatusTestsList.
numParams() > 0 ) {
791 std::string userCombo_string = params->
get<std::string>(
"User Status Tests Combo Type",
"SEQ");
793 setUserConvStatusTest( testFactory->buildStatusTests(userStatusTestsList), testFactory->stringToComboType(userCombo_string) );
794 taggedTests_ = testFactory->getTaggedTests();
801 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> > (*params,
"Output Stream");
804 params_->set(
"Output Stream", outputStream_);
805 if (! printer_.is_null ()) {
806 printer_->setOStream (outputStream_);
813 outputFreq_ = params->
get (
"Output Frequency", outputFreq_default_);
817 params_->set (
"Output Frequency", outputFreq_);
818 if (! outputTest_.is_null ()) {
819 outputTest_->setOutputFrequency (outputFreq_);
824 if (printer_.is_null ()) {
831 if (params->
isParameter (
"Convergence Tolerance")) {
832 if (params->
isType<MagnitudeType> (
"Convergence Tolerance")) {
833 convtol_ = params->
get (
"Convergence Tolerance",
841 params_->set (
"Convergence Tolerance", convtol_);
842 if (! impConvTest_.is_null ()) {
843 impConvTest_->setTolerance (convtol_);
845 if (! expConvTest_.is_null ()) {
846 expConvTest_->setTolerance (convtol_);
851 bool userDefinedResidualScalingUpdated =
false;
852 if (params->
isParameter (
"User Defined Residual Scaling")) {
854 if (params->
isType<MagnitudeType> (
"User Defined Residual Scaling")) {
855 tempResScaleFactor = params->
get (
"User Defined Residual Scaling",
859 tempResScaleFactor = params->
get (
"User Defined Residual Scaling",
864 if (resScaleFactor_ != tempResScaleFactor) {
865 resScaleFactor_ = tempResScaleFactor;
866 userDefinedResidualScalingUpdated =
true;
869 if(userDefinedResidualScalingUpdated)
871 if (! params->
isParameter (
"Implicit Residual Scaling") && ! impConvTest_.is_null ()) {
873 if(impResScale_ ==
"User Provided")
876 catch (std::exception& e) {
881 if (! params->
isParameter (
"Explicit Residual Scaling") && ! expConvTest_.is_null ()) {
883 if(expResScale_ ==
"User Provided")
886 catch (std::exception& e) {
895 if (params->
isParameter (
"Implicit Residual Scaling")) {
896 const std::string tempImpResScale =
897 Teuchos::getParameter<std::string> (*params,
"Implicit Residual Scaling");
900 if (impResScale_ != tempImpResScale) {
902 impResScale_ = tempImpResScale;
905 params_->set (
"Implicit Residual Scaling", impResScale_);
906 if (! impConvTest_.is_null ()) {
908 if(impResScale_ ==
"User Provided")
909 impConvTest_->defineScaleForm (impResScaleType,
Belos::TwoNorm, resScaleFactor_);
913 catch (std::exception& e) {
919 else if (userDefinedResidualScalingUpdated) {
922 if (! impConvTest_.is_null ()) {
924 if(impResScale_ ==
"User Provided")
925 impConvTest_->defineScaleForm (impResScaleType,
Belos::TwoNorm, resScaleFactor_);
927 catch (std::exception& e) {
935 if (params->
isParameter (
"Explicit Residual Scaling")) {
936 const std::string tempExpResScale =
937 Teuchos::getParameter<std::string> (*params,
"Explicit Residual Scaling");
940 if (expResScale_ != tempExpResScale) {
942 expResScale_ = tempExpResScale;
945 params_->set (
"Explicit Residual Scaling", expResScale_);
946 if (! expConvTest_.is_null ()) {
948 if(expResScale_ ==
"User Provided")
949 expConvTest_->defineScaleForm (expResScaleType,
Belos::TwoNorm, resScaleFactor_);
953 catch (std::exception& e) {
959 else if (userDefinedResidualScalingUpdated) {
962 if (! expConvTest_.is_null ()) {
964 if(expResScale_ ==
"User Provided")
965 expConvTest_->defineScaleForm (expResScaleType,
Belos::TwoNorm, resScaleFactor_);
967 catch (std::exception& e) {
976 if (params->
isParameter (
"Show Maximum Residual Norm Only")) {
977 showMaxResNormOnly_ =
978 Teuchos::getParameter<bool> (*params,
"Show Maximum Residual Norm Only");
981 params_->set (
"Show Maximum Residual Norm Only", showMaxResNormOnly_);
982 if (! impConvTest_.is_null ()) {
983 impConvTest_->setShowMaxResNormOnly (showMaxResNormOnly_);
985 if (! expConvTest_.is_null ()) {
986 expConvTest_->setShowMaxResNormOnly (showMaxResNormOnly_);
994 defQuorum_ = params->
get(
"Deflation Quorum", defQuorum_);
996 defQuorum_ > blockSize_, std::invalid_argument,
997 "Belos::PseudoBlockGmresSolMgr::setParameters: "
998 "The \"Deflation Quorum\" parameter (= " << defQuorum_ <<
") must not be "
999 "larger than \"Block Size\" (= " << blockSize_ <<
").");
1000 params_->set (
"Deflation Quorum", defQuorum_);
1001 if (! impConvTest_.is_null ()) {
1002 impConvTest_->setQuorum (defQuorum_);
1004 if (! expConvTest_.is_null ()) {
1005 expConvTest_->setQuorum (defQuorum_);
1010 if (ortho_.is_null ()) {
1011 params_->set(
"Orthogonalization", orthoType_);
1012 if (orthoType_ ==
"DGKS") {
1014 if (orthoKappa_ <= 0) {
1015 ortho_ =
rcp (
new ortho_type (label_));
1018 ortho_ =
rcp (
new ortho_type (label_));
1019 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
1022 else if (orthoType_ ==
"ICGS") {
1024 ortho_ =
rcp (
new ortho_type (label_));
1026 else if (orthoType_ ==
"IMGS") {
1028 ortho_ =
rcp (
new ortho_type (label_));
1030 #ifdef HAVE_BELOS_TSQR
1031 else if (orthoType_ ==
"TSQR") {
1033 ortho_ =
rcp (
new ortho_type (label_));
1035 #endif // HAVE_BELOS_TSQR
1037 #ifdef HAVE_BELOS_TSQR
1039 orthoType_ !=
"ICGS" && orthoType_ !=
"DGKS" &&
1040 orthoType_ !=
"IMGS" && orthoType_ !=
"TSQR",
1042 "Belos::PseudoBlockGmresSolMgr::setParameters(): "
1043 "Invalid orthogonalization type \"" << orthoType_ <<
"\".");
1046 orthoType_ !=
"ICGS" && orthoType_ !=
"DGKS" &&
1047 orthoType_ !=
"IMGS",
1049 "Belos::PseudoBlockGmresSolMgr::setParameters(): "
1050 "Invalid orthogonalization type \"" << orthoType_ <<
"\".");
1051 #endif // HAVE_BELOS_TSQR
1056 if (timerSolve_ == Teuchos::null) {
1057 std::string solveLabel = label_ +
": PseudoBlockGmresSolMgr total solve time";
1058 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1068 template<
class ScalarType,
class MV,
class OP>
1075 userConvStatusTest_ = userConvStatusTest;
1076 comboType_ = comboType;
1079 template<
class ScalarType,
class MV,
class OP>
1085 debugStatusTest_ = debugStatusTest;
1090 template<
class ScalarType,
class MV,
class OP>
1103 "The relative residual tolerance that needs to be achieved by the\n"
1104 "iterative solver in order for the linear system to be declared converged.");
1105 pl->
set(
"Maximum Restarts", static_cast<int>(maxRestarts_default_),
1106 "The maximum number of restarts allowed for each\n"
1107 "set of RHS solved.");
1108 pl->
set(
"Maximum Iterations", static_cast<int>(maxIters_default_),
1109 "The maximum number of block iterations allowed for each\n"
1110 "set of RHS solved.");
1111 pl->
set(
"Num Blocks", static_cast<int>(numBlocks_default_),
1112 "The maximum number of vectors allowed in the Krylov subspace\n"
1113 "for each set of RHS solved.");
1114 pl->
set(
"Block Size", static_cast<int>(blockSize_default_),
1115 "The number of RHS solved simultaneously.");
1116 pl->
set(
"Verbosity", static_cast<int>(verbosity_default_),
1117 "What type(s) of solver information should be outputted\n"
1118 "to the output stream.");
1119 pl->
set(
"Output Style", static_cast<int>(outputStyle_default_),
1120 "What style is used for the solver information outputted\n"
1121 "to the output stream.");
1122 pl->
set(
"Output Frequency", static_cast<int>(outputFreq_default_),
1123 "How often convergence information should be outputted\n"
1124 "to the output stream.");
1125 pl->
set(
"Deflation Quorum", static_cast<int>(defQuorum_default_),
1126 "The number of linear systems that need to converge before\n"
1127 "they are deflated. This number should be <= block size.");
1129 "A reference-counted pointer to the output stream where all\n"
1130 "solver output is sent.");
1131 pl->
set(
"Show Maximum Residual Norm Only", static_cast<bool>(showMaxResNormOnly_default_),
1132 "When convergence information is printed, only show the maximum\n"
1133 "relative residual norm when the block size is greater than one.");
1134 pl->
set(
"Implicit Residual Scaling", static_cast<const char *>(impResScale_default_),
1135 "The type of scaling used in the implicit residual convergence test.");
1136 pl->
set(
"Explicit Residual Scaling", static_cast<const char *>(expResScale_default_),
1137 "The type of scaling used in the explicit residual convergence test.");
1138 pl->
set(
"Timer Label", static_cast<const char *>(label_default_),
1139 "The string to use as a prefix for the timer labels.");
1140 pl->
set(
"Orthogonalization", static_cast<const char *>(orthoType_default_),
1141 "The type of orthogonalization to use.");
1143 "The constant used by DGKS orthogonalization to determine\n"
1144 "whether another step of classical Gram-Schmidt is necessary.");
1145 pl->
sublist(
"User Status Tests");
1146 pl->
set(
"User Status Tests Combo Type",
"SEQ",
1147 "Type of logical combination operation of user-defined\n"
1148 "and/or solver-specific status tests.");
1155 template<
class ScalarType,
class MV,
class OP>
1175 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
1176 if(impResScale_ ==
"User Provided")
1181 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1182 impConvTest_ = tmpImpConvTest;
1186 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
1187 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
1188 if(expResScale_ ==
"User Provided")
1192 tmpExpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1193 expConvTest_ = tmpExpConvTest;
1196 convTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
1203 Teuchos::rcp(
new StatusTestImpResNorm_t( convtol_, defQuorum_ ) );
1204 if(impResScale_ ==
"User Provided")
1208 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1209 impConvTest_ = tmpImpConvTest;
1212 expConvTest_ = impConvTest_;
1213 convTest_ = impConvTest_;
1216 if (
nonnull(userConvStatusTest_) ) {
1219 new StatusTestCombo_t( comboType_, convTest_, userConvStatusTest_ ) );
1226 sTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
1229 if (
nonnull(debugStatusTest_) ) {
1231 Teuchos::rcp_dynamic_cast<StatusTestCombo_t>(sTest_)->addStatusTest( debugStatusTest_ );
1236 StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_, taggedTests_ );
1240 std::string solverDesc =
" Pseudo Block Gmres ";
1241 outputTest_->setSolverDesc( solverDesc );
1252 template<
class ScalarType,
class MV,
class OP>
1258 if (!isSet_) { setParameters( params_ ); }
1263 "Belos::PseudoBlockGmresSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
1266 if (!isSTSet_ || (!expResTest_ && !
Teuchos::is_null(problem_->getLeftPrec())) ) {
1268 "Belos::BlockGmresSolMgr::solve(): Linear problem and requested status tests are incompatible.");
1273 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
1274 int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1276 std::vector<int> currIdx( numCurrRHS );
1277 blockSize_ = numCurrRHS;
1278 for (
int i=0; i<numCurrRHS; ++i)
1279 { currIdx[i] = startPtr+i; }
1282 problem_->setLSIndex( currIdx );
1287 plist.
set(
"Num Blocks",numBlocks_);
1290 outputTest_->reset();
1291 loaDetected_ =
false;
1294 bool isConverged =
true;
1304 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1308 while ( numRHS2Solve > 0 ) {
1311 std::vector<int> convRHSIdx;
1312 std::vector<int> currRHSIdx( currIdx );
1313 currRHSIdx.resize(numCurrRHS);
1316 block_gmres_iter->setNumBlocks( numBlocks_ );
1319 block_gmres_iter->resetNumIters();
1322 outputTest_->resetNumCalls();
1328 std::vector<int> index(1);
1329 Teuchos::RCP<MV> tmpV, R_0 = MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1330 newState.
V.resize( blockSize_ );
1331 newState.
Z.resize( blockSize_ );
1332 for (
int i=0; i<blockSize_; ++i) {
1334 tmpV = MVT::CloneViewNonConst( *R_0, index );
1341 int rank = ortho_->normalize( *tmpV, tmpZ );
1343 "Belos::PseudoBlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors.");
1345 newState.
V[i] = tmpV;
1346 newState.
Z[i] = tmpZ;
1350 block_gmres_iter->initialize(newState);
1351 int numRestarts = 0;
1357 block_gmres_iter->iterate();
1364 if ( convTest_->getStatus() ==
Passed ) {
1366 if ( expConvTest_->getLOADetected() ) {
1376 loaDetected_ =
true;
1378 "Belos::PseudoBlockGmresSolMgr::solve(): Warning! Solver has experienced a loss of accuracy!" << std::endl;
1379 isConverged =
false;
1383 std::vector<int> convIdx = expConvTest_->convIndices();
1387 if (convIdx.size() == currRHSIdx.size())
1394 problem_->setCurrLS();
1398 int curDim = oldState.
curDim;
1403 std::vector<int> oldRHSIdx( currRHSIdx );
1404 std::vector<int> defRHSIdx;
1405 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
1407 for (
unsigned int j=0; j<convIdx.size(); ++j) {
1408 if (currRHSIdx[i] == convIdx[j]) {
1414 defRHSIdx.push_back( i );
1417 defState.
V.push_back( Teuchos::rcp_const_cast<MV>( oldState.
V[i] ) );
1422 currRHSIdx[have] = currRHSIdx[i];
1426 defRHSIdx.resize(currRHSIdx.size()-have);
1427 currRHSIdx.resize(have);
1435 problem_->setLSIndex( convIdx );
1438 problem_->updateSolution( defUpdate,
true );
1442 problem_->setLSIndex( currRHSIdx );
1445 defState.
curDim = curDim;
1448 block_gmres_iter->initialize(defState);
1455 else if ( maxIterTest_->getStatus() ==
Passed ) {
1457 isConverged =
false;
1465 else if ( block_gmres_iter->getCurSubspaceDim() == block_gmres_iter->getMaxSubspaceDim() ) {
1467 if ( numRestarts >= maxRestarts_ ) {
1468 isConverged =
false;
1473 printer_->stream(
Debug) <<
" Performing restart number " << numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
1477 problem_->updateSolution( update,
true );
1484 newstate.
V.resize(currRHSIdx.size());
1485 newstate.
Z.resize(currRHSIdx.size());
1489 R_0 = MVT::Clone( *(problem_->getInitPrecResVec()), currRHSIdx.size() );
1490 problem_->computeCurrPrecResVec( &*R_0 );
1491 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
1494 tmpV = MVT::CloneViewNonConst( *R_0, index );
1501 int rank = ortho_->normalize( *tmpV, tmpZ );
1503 "Belos::PseudoBlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors after the restart.");
1505 newstate.
V[i] = tmpV;
1506 newstate.
Z[i] = tmpZ;
1511 block_gmres_iter->initialize(newstate);
1524 "Belos::PseudoBlockGmresSolMgr::solve(): Invalid return from PseudoBlockGmresIter::iterate().");
1530 block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
1533 sTest_->checkStatus( &*block_gmres_iter );
1534 if (convTest_->getStatus() !=
Passed)
1535 isConverged =
false;
1538 catch (
const std::exception &e) {
1539 printer_->stream(
Errors) <<
"Error! Caught std::exception in PseudoBlockGmresIter::iterate() at iteration "
1540 << block_gmres_iter->getNumIters() << std::endl
1541 << e.what() << std::endl;
1548 if (
nonnull(userConvStatusTest_)) {
1551 problem_->updateSolution( update,
true );
1553 else if (
nonnull(expConvTest_->getSolution())) {
1557 MVT::MvAddMv( 0.0, *newX, 1.0, *newX, *curX );
1562 problem_->updateSolution( update,
true );
1566 problem_->setCurrLS();
1569 startPtr += numCurrRHS;
1570 numRHS2Solve -= numCurrRHS;
1571 if ( numRHS2Solve > 0 ) {
1572 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1574 blockSize_ = numCurrRHS;
1575 currIdx.resize( numCurrRHS );
1576 for (
int i=0; i<numCurrRHS; ++i)
1577 { currIdx[i] = startPtr+i; }
1580 if (defQuorum_ > blockSize_) {
1581 if (impConvTest_ != Teuchos::null)
1582 impConvTest_->setQuorum( blockSize_ );
1583 if (expConvTest_ != Teuchos::null)
1584 expConvTest_->setQuorum( blockSize_ );
1588 problem_->setLSIndex( currIdx );
1591 currIdx.resize( numRHS2Solve );
1602 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1611 numIters_ = maxIterTest_->getNumIters();
1624 const std::vector<MagnitudeType>* pTestValues = NULL;
1626 pTestValues = expConvTest_->getTestValue();
1627 if (pTestValues == NULL || pTestValues->size() < 1) {
1628 pTestValues = impConvTest_->getTestValue();
1633 pTestValues = impConvTest_->getTestValue();
1636 "Belos::PseudoBlockGmresSolMgr::solve(): The implicit convergence test's "
1637 "getTestValue() method returned NULL. Please report this bug to the "
1638 "Belos developers.");
1640 "Belos::PseudoBlockGmresSolMgr::solve(): The implicit convergence test's "
1641 "getTestValue() method returned a vector of length zero. Please report "
1642 "this bug to the Belos developers.");
1647 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1650 if (!isConverged || loaDetected_) {
1657 template<
class ScalarType,
class MV,
class OP>
1660 std::ostringstream out;
1662 out <<
"\"Belos::PseudoBlockGmresSolMgr\": {";
1663 if (this->getObjectLabel () !=
"") {
1664 out <<
"Label: " << this->getObjectLabel () <<
", ";
1666 out <<
"Num Blocks: " << numBlocks_
1667 <<
", Maximum Iterations: " << maxIters_
1668 <<
", Maximum Restarts: " << maxRestarts_
1669 <<
", Convergence Tolerance: " << convtol_
1675 template<
class ScalarType,
class MV,
class OP>
1697 out <<
"\"Belos::PseudoBlockGmresSolMgr\":" << endl;
1699 out <<
"Template parameters:" << endl;
1702 out <<
"ScalarType: " << TypeNameTraits<ScalarType>::name () << endl
1703 <<
"MV: " << TypeNameTraits<MV>::name () << endl
1704 <<
"OP: " << TypeNameTraits<OP>::name () << endl;
1706 if (this->getObjectLabel () !=
"") {
1707 out <<
"Label: " << this->getObjectLabel () << endl;
1709 out <<
"Num Blocks: " << numBlocks_ << endl
1710 <<
"Maximum Iterations: " << maxIters_ << endl
1711 <<
"Maximum Restarts: " << maxRestarts_ << endl
1712 <<
"Convergence Tolerance: " << convtol_ << endl;
static const double orthoKappa
DGKS orthogonalization constant.
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
std::vector< Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > > H
The current Hessenberg matrix.
Collection of types and exceptions used within the Belos solvers.
ComboType
The test can be either the AND of all the component tests, or the OR of all the component tests...
virtual ~PseudoBlockGmresSolMgr()
Destructor.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms) override
Set the parameters the solver manager should use to solve the linear problem.
Class which manages the output and verbosity of the Belos solvers.
bool is_null(const boost::shared_ptr< T > &p)
PseudoBlockGmresSolMgr()
Empty constructor.
PseudoBlockGmresSolMgrLinearProblemFailure(const std::string &what_arg)
ScaleType
The type of scaling to use on the residual norm value.
Convergence test using the implicit residual norm(s), with an explicit residual norm(s) check for los...
T & get(const std::string &name, T def_value)
PseudoBlockGmresSolMgrOrthoFailure(const std::string &what_arg)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool is_null(const std::shared_ptr< T > &p)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &debugStatusTest) override
Set a debug status test that will be checked at the same time as the top-level status test...
std::vector< Teuchos::RCP< const MV > > V
The current Krylov basis.
An implementation of StatusTestResNorm using a family of residual norms.
Ordinal numParams() const
static const double convTol
Default convergence tolerance.
A pure virtual class for defining the status tests for the Belos iterative solvers.
Structure to contain pointers to PseudoBlockGmresIter state variables.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
A factory class for generating StatusTestOutput objects.
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
Traits class which defines basic operations on multivectors.
bool isParameter(const std::string &name) const
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class...
A Belos::StatusTest class for specifying a maximum number of iterations.
ResetType
How to reset the solver.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Pure virtual base class which describes the basic interface for a solver manager. ...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const override
Print the object with the given verbosity level to a FancyOStream.
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="", const bool ignoreZeroTimers=false)
bool isSublist(const std::string &name) const
PseudoBlockGmresSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, MagnitudeType > > > cs
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
Interface to standard and "pseudoblock" GMRES.
int getNumIters() const override
Iteration count for the most recent call to solve().
ReturnType
Whether the Belos solve converged for all linear systems.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
A list of valid default parameters for this solver.
Iterated Classical Gram-Schmidt (ICGS) implementation of the Belos::OrthoManager class.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
static const EVerbosityLevel verbLevel_default
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
bool isLOADetected() const override
Whether a "loss of accuracy" was detected during the last solve().
bool nonnull(const boost::shared_ptr< T > &p)
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, ScalarType > > > Z
The current right-hand side of the least squares system RY = Z.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem to solve.
Belos concrete class for performing the pseudo-block GMRES iteration.
bool isType(const std::string &name) const
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
A class for extending the status testing capabilities of Belos via logical combinations.
std::string description() const override
Return a one-line description of this object.
Orthogonalization manager based on Tall Skinny QR (TSQR)
Class which defines basic traits for the operator type.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
int curDim
The current dimension of the reduction.
Parent class to all Belos exceptions.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
Default parameters common to most Belos solvers.
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, ScalarType > > > sn
The current Given's rotation coefficients.
static const double resScaleFactor
User-defined residual scaling factor.
MatOrthoManager subclass using TSQR or DGKS.
Belos header file which uses auto-configuration information to include necessary C++ headers...
This class implements the pseudo-block GMRES iteration, where a block Krylov subspace is constructed ...
Factory to build a set of status tests from a parameter list.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
The current parameters for this solver.
PseudoBlockGmresIterOrthoFailure is thrown when the orthogonalization manager is unable to generate o...
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
PseudoBlockGmresSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate...
virtual void setUserConvStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &userConvStatusTest, const typename StatusTestCombo< ScalarType, MV, OP >::ComboType &comboType=StatusTestCombo< ScalarType, MV, OP >::SEQ) override
Set a custom status test.
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.