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 65 #include "Teuchos_BLAS.hpp" 66 #ifdef BELOS_TEUCHOS_TIME_MONITOR 67 #include "Teuchos_TimeMonitor.hpp" 125 template<
class ScalarType,
class MV,
class OP>
131 typedef Teuchos::ScalarTraits<ScalarType> SCT;
132 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
133 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
259 const Teuchos::RCP<Teuchos::ParameterList> &pl );
273 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const;
283 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
284 return Teuchos::tuple(timerSolve_);
374 void setParameters (
const Teuchos::RCP<Teuchos::ParameterList> ¶ms);
382 virtual void setUserConvStatusTest(
436 describe (Teuchos::FancyOStream& out,
437 const Teuchos::EVerbosityLevel verbLevel =
438 Teuchos::Describable::verbLevel_default)
const;
441 std::string description ()
const;
461 bool checkStatusTest();
464 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
467 Teuchos::RCP<OutputManager<ScalarType> > printer_;
468 Teuchos::RCP<std::ostream> outputStream_;
471 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > userConvStatusTest_;
472 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > debugStatusTest_;
473 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
474 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
475 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
476 Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > impConvTest_, expConvTest_;
477 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
479 Teuchos::RCP<std::map<std::string, Teuchos::RCP<StatusTest<ScalarType, MV, OP> > > > taggedTests_;
482 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > ortho_;
485 Teuchos::RCP<Teuchos::ParameterList> params_;
488 static const MagnitudeType convtol_default_;
489 static const MagnitudeType orthoKappa_default_;
490 static const int maxRestarts_default_;
491 static const int maxIters_default_;
492 static const bool showMaxResNormOnly_default_;
493 static const int blockSize_default_;
494 static const int numBlocks_default_;
495 static const int verbosity_default_;
496 static const int outputStyle_default_;
497 static const int outputFreq_default_;
498 static const int defQuorum_default_;
499 static const std::string impResScale_default_;
500 static const std::string expResScale_default_;
501 static const MagnitudeType resScaleFactor_default_;
502 static const std::string label_default_;
503 static const std::string orthoType_default_;
504 static const Teuchos::RCP<std::ostream> outputStream_default_;
507 MagnitudeType convtol_, orthoKappa_, achievedTol_;
508 int maxRestarts_, maxIters_, numIters_;
509 int blockSize_, numBlocks_, verbosity_, outputStyle_, outputFreq_, defQuorum_;
510 bool showMaxResNormOnly_;
511 std::string orthoType_;
512 std::string impResScale_, expResScale_;
513 MagnitudeType resScaleFactor_;
517 Teuchos::RCP<Teuchos::Time> timerSolve_;
520 bool isSet_, isSTSet_, expResTest_;
526 template<
class ScalarType,
class MV,
class OP>
529 template<
class ScalarType,
class MV,
class OP>
532 template<
class ScalarType,
class MV,
class OP>
535 template<
class ScalarType,
class MV,
class OP>
538 template<
class ScalarType,
class MV,
class OP>
541 template<
class ScalarType,
class MV,
class OP>
544 template<
class ScalarType,
class MV,
class OP>
547 template<
class ScalarType,
class MV,
class OP>
550 template<
class ScalarType,
class MV,
class OP>
553 template<
class ScalarType,
class MV,
class OP>
556 template<
class ScalarType,
class MV,
class OP>
559 template<
class ScalarType,
class MV,
class OP>
562 template<
class ScalarType,
class MV,
class OP>
565 template<
class ScalarType,
class MV,
class OP>
568 template<
class ScalarType,
class MV,
class OP>
571 template<
class ScalarType,
class MV,
class OP>
574 template<
class ScalarType,
class MV,
class OP>
578 template<
class ScalarType,
class MV,
class OP>
580 outputStream_(outputStream_default_),
581 taggedTests_(Teuchos::null),
582 convtol_(convtol_default_),
583 orthoKappa_(orthoKappa_default_),
584 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
585 maxRestarts_(maxRestarts_default_),
586 maxIters_(maxIters_default_),
588 blockSize_(blockSize_default_),
589 numBlocks_(numBlocks_default_),
590 verbosity_(verbosity_default_),
591 outputStyle_(outputStyle_default_),
592 outputFreq_(outputFreq_default_),
593 defQuorum_(defQuorum_default_),
594 showMaxResNormOnly_(showMaxResNormOnly_default_),
595 orthoType_(orthoType_default_),
596 impResScale_(impResScale_default_),
597 expResScale_(expResScale_default_),
598 resScaleFactor_(resScaleFactor_default_),
599 label_(label_default_),
607 template<
class ScalarType,
class MV,
class OP>
610 const Teuchos::RCP<Teuchos::ParameterList> &pl) :
612 outputStream_(outputStream_default_),
613 taggedTests_(Teuchos::null),
614 convtol_(convtol_default_),
615 orthoKappa_(orthoKappa_default_),
616 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
617 maxRestarts_(maxRestarts_default_),
618 maxIters_(maxIters_default_),
620 blockSize_(blockSize_default_),
621 numBlocks_(numBlocks_default_),
622 verbosity_(verbosity_default_),
623 outputStyle_(outputStyle_default_),
624 outputFreq_(outputFreq_default_),
625 defQuorum_(defQuorum_default_),
626 showMaxResNormOnly_(showMaxResNormOnly_default_),
627 orthoType_(orthoType_default_),
628 impResScale_(impResScale_default_),
629 expResScale_(expResScale_default_),
630 resScaleFactor_(resScaleFactor_default_),
631 label_(label_default_),
637 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager.");
646 template<
class ScalarType,
class MV,
class OP>
651 using Teuchos::ParameterList;
652 using Teuchos::parameterList;
654 using Teuchos::rcp_dynamic_cast;
657 if (params_ == Teuchos::null) {
669 if (params->isParameter (
"Maximum Restarts")) {
670 maxRestarts_ = params->get (
"Maximum Restarts", maxRestarts_default_);
673 params_->set (
"Maximum Restarts", maxRestarts_);
677 if (params->isParameter (
"Maximum Iterations")) {
678 maxIters_ = params->get (
"Maximum Iterations", maxIters_default_);
681 params_->set (
"Maximum Iterations", maxIters_);
682 if (! maxIterTest_.is_null ()) {
683 maxIterTest_->setMaxIters (maxIters_);
688 if (params->isParameter (
"Block Size")) {
689 blockSize_ = params->get (
"Block Size", blockSize_default_);
690 TEUCHOS_TEST_FOR_EXCEPTION(
691 blockSize_ <= 0, std::invalid_argument,
692 "Belos::PseudoBlockGmresSolMgr::setParameters: " 693 "The \"Block Size\" parameter must be strictly positive, " 694 "but you specified a value of " << blockSize_ <<
".");
697 params_->set (
"Block Size", blockSize_);
701 if (params->isParameter (
"Num Blocks")) {
702 numBlocks_ = params->get (
"Num Blocks", numBlocks_default_);
703 TEUCHOS_TEST_FOR_EXCEPTION(
704 numBlocks_ <= 0, std::invalid_argument,
705 "Belos::PseudoBlockGmresSolMgr::setParameters: " 706 "The \"Num Blocks\" parameter must be strictly positive, " 707 "but you specified a value of " << numBlocks_ <<
".");
710 params_->set (
"Num Blocks", numBlocks_);
714 if (params->isParameter (
"Timer Label")) {
715 const std::string tempLabel = params->get (
"Timer Label", label_default_);
718 if (tempLabel != label_) {
720 params_->set (
"Timer Label", label_);
721 const std::string solveLabel =
722 label_ +
": PseudoBlockGmresSolMgr total solve time";
723 #ifdef BELOS_TEUCHOS_TIME_MONITOR 724 timerSolve_ = Teuchos::TimeMonitor::getNewCounter (solveLabel);
725 #endif // BELOS_TEUCHOS_TIME_MONITOR 726 if (ortho_ != Teuchos::null) {
727 ortho_->setLabel( label_ );
733 if (params->isParameter (
"Orthogonalization")) {
734 std::string tempOrthoType = params->get (
"Orthogonalization", orthoType_default_);
735 #ifdef HAVE_BELOS_TSQR 736 TEUCHOS_TEST_FOR_EXCEPTION(
737 tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" &&
738 tempOrthoType !=
"IMGS" && tempOrthoType !=
"TSQR",
739 std::invalid_argument,
740 "Belos::PseudoBlockGmresSolMgr::setParameters: " 741 "The \"Orthogonalization\" parameter must be one of \"DGKS\", \"ICGS\", " 742 "\"IMGS\", or \"TSQR\".");
744 TEUCHOS_TEST_FOR_EXCEPTION(
745 tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" &&
746 tempOrthoType !=
"IMGS",
747 std::invalid_argument,
748 "Belos::PseudoBlockGmresSolMgr::setParameters: " 749 "The \"Orthogonalization\" parameter must be one of \"DGKS\", \"ICGS\", " 751 #endif // HAVE_BELOS_TSQR 753 if (tempOrthoType != orthoType_) {
754 orthoType_ = tempOrthoType;
755 params_->set(
"Orthogonalization", orthoType_);
757 if (orthoType_ ==
"DGKS") {
759 if (orthoKappa_ <= 0) {
760 ortho_ = rcp (
new ortho_type (label_));
763 ortho_ = rcp (
new ortho_type (label_));
764 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
767 else if (orthoType_ ==
"ICGS") {
769 ortho_ = rcp (
new ortho_type (label_));
771 else if (orthoType_ ==
"IMGS") {
773 ortho_ = rcp (
new ortho_type (label_));
775 #ifdef HAVE_BELOS_TSQR 776 else if (orthoType_ ==
"TSQR") {
778 ortho_ = rcp (
new ortho_type (label_));
780 #endif // HAVE_BELOS_TSQR 785 if (params->isParameter (
"Orthogonalization Constant")) {
786 orthoKappa_ = params->get (
"Orthogonalization Constant", orthoKappa_default_);
789 params_->set (
"Orthogonalization Constant", orthoKappa_);
790 if (orthoType_ ==
"DGKS") {
791 if (orthoKappa_ > 0 && ! ortho_.is_null ()) {
793 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
799 if (params->isParameter (
"Verbosity")) {
800 if (Teuchos::isParameterType<int> (*params,
"Verbosity")) {
801 verbosity_ = params->get (
"Verbosity", verbosity_default_);
803 verbosity_ = (int) Teuchos::getParameter<Belos::MsgType> (*params,
"Verbosity");
807 params_->set (
"Verbosity", verbosity_);
808 if (! printer_.is_null ()) {
809 printer_->setVerbosity (verbosity_);
814 if (params->isParameter (
"Output Style")) {
815 if (Teuchos::isParameterType<int> (*params,
"Output Style")) {
816 outputStyle_ = params->get (
"Output Style", outputStyle_default_);
818 outputStyle_ = (int) Teuchos::getParameter<Belos::OutputType> (*params,
"Output Style");
822 params_->set (
"Output Style", verbosity_);
823 if (! outputTest_.is_null ()) {
830 if (params->isSublist (
"User Status Tests")) {
831 Teuchos::ParameterList userStatusTestsList = params->sublist(
"User Status Tests",
true);
832 if ( userStatusTestsList.numParams() > 0 ) {
833 std::string userCombo_string = params->get<std::string>(
"User Status Tests Combo Type",
"SEQ");
835 setUserConvStatusTest( testFactory->buildStatusTests(userStatusTestsList), testFactory->stringToComboType(userCombo_string) );
836 taggedTests_ = testFactory->getTaggedTests();
842 if (params->isParameter (
"Output Stream")) {
843 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> > (*params,
"Output Stream");
846 params_->set(
"Output Stream", outputStream_);
847 if (! printer_.is_null ()) {
848 printer_->setOStream (outputStream_);
854 if (params->isParameter (
"Output Frequency")) {
855 outputFreq_ = params->get (
"Output Frequency", outputFreq_default_);
859 params_->set (
"Output Frequency", outputFreq_);
860 if (! outputTest_.is_null ()) {
861 outputTest_->setOutputFrequency (outputFreq_);
866 if (printer_.is_null ()) {
873 if (params->isParameter (
"Convergence Tolerance")) {
874 convtol_ = params->get (
"Convergence Tolerance", convtol_default_);
877 params_->set (
"Convergence Tolerance", convtol_);
878 if (! impConvTest_.is_null ()) {
879 impConvTest_->setTolerance (convtol_);
881 if (! expConvTest_.is_null ()) {
882 expConvTest_->setTolerance (convtol_);
887 bool userDefinedResidualScalingUpdated =
false;
888 if (params->isParameter (
"User Defined Residual Scaling")) {
889 const MagnitudeType tempResScaleFactor =
890 Teuchos::getParameter<MagnitudeType> (*params,
"User Defined Residual Scaling");
893 if (resScaleFactor_ != tempResScaleFactor) {
894 resScaleFactor_ = tempResScaleFactor;
895 userDefinedResidualScalingUpdated =
true;
898 if(userDefinedResidualScalingUpdated)
900 if (! params->isParameter (
"Implicit Residual Scaling") && ! impConvTest_.is_null ()) {
902 if(impResScale_ ==
"User Provided")
905 catch (std::exception& e) {
910 if (! params->isParameter (
"Explicit Residual Scaling") && ! expConvTest_.is_null ()) {
912 if(expResScale_ ==
"User Provided")
915 catch (std::exception& e) {
924 if (params->isParameter (
"Implicit Residual Scaling")) {
925 const std::string tempImpResScale =
926 Teuchos::getParameter<std::string> (*params,
"Implicit Residual Scaling");
929 if (impResScale_ != tempImpResScale) {
931 impResScale_ = tempImpResScale;
934 params_->set (
"Implicit Residual Scaling", impResScale_);
935 if (! impConvTest_.is_null ()) {
937 if(impResScale_ ==
"User Provided")
938 impConvTest_->defineScaleForm (impResScaleType,
Belos::TwoNorm, resScaleFactor_);
942 catch (std::exception& e) {
948 else if (userDefinedResidualScalingUpdated) {
951 if (! impConvTest_.is_null ()) {
953 if(impResScale_ ==
"User Provided")
954 impConvTest_->defineScaleForm (impResScaleType,
Belos::TwoNorm, resScaleFactor_);
956 catch (std::exception& e) {
964 if (params->isParameter (
"Explicit Residual Scaling")) {
965 const std::string tempExpResScale =
966 Teuchos::getParameter<std::string> (*params,
"Explicit Residual Scaling");
969 if (expResScale_ != tempExpResScale) {
971 expResScale_ = tempExpResScale;
974 params_->set (
"Explicit Residual Scaling", expResScale_);
975 if (! expConvTest_.is_null ()) {
977 if(expResScale_ ==
"User Provided")
978 expConvTest_->defineScaleForm (expResScaleType,
Belos::TwoNorm, resScaleFactor_);
982 catch (std::exception& e) {
988 else if (userDefinedResidualScalingUpdated) {
991 if (! expConvTest_.is_null ()) {
993 if(expResScale_ ==
"User Provided")
994 expConvTest_->defineScaleForm (expResScaleType,
Belos::TwoNorm, resScaleFactor_);
996 catch (std::exception& e) {
1005 if (params->isParameter (
"Show Maximum Residual Norm Only")) {
1006 showMaxResNormOnly_ =
1007 Teuchos::getParameter<bool> (*params,
"Show Maximum Residual Norm Only");
1010 params_->set (
"Show Maximum Residual Norm Only", showMaxResNormOnly_);
1011 if (! impConvTest_.is_null ()) {
1012 impConvTest_->setShowMaxResNormOnly (showMaxResNormOnly_);
1014 if (! expConvTest_.is_null ()) {
1015 expConvTest_->setShowMaxResNormOnly (showMaxResNormOnly_);
1022 if (params->isParameter(
"Deflation Quorum")) {
1023 defQuorum_ = params->get(
"Deflation Quorum", defQuorum_);
1024 TEUCHOS_TEST_FOR_EXCEPTION(
1025 defQuorum_ > blockSize_, std::invalid_argument,
1026 "Belos::PseudoBlockGmresSolMgr::setParameters: " 1027 "The \"Deflation Quorum\" parameter (= " << defQuorum_ <<
") must not be " 1028 "larger than \"Block Size\" (= " << blockSize_ <<
").");
1029 params_->set (
"Deflation Quorum", defQuorum_);
1030 if (! impConvTest_.is_null ()) {
1031 impConvTest_->setQuorum (defQuorum_);
1033 if (! expConvTest_.is_null ()) {
1034 expConvTest_->setQuorum (defQuorum_);
1039 if (ortho_.is_null ()) {
1040 params_->set(
"Orthogonalization", orthoType_);
1041 if (orthoType_ ==
"DGKS") {
1043 if (orthoKappa_ <= 0) {
1044 ortho_ = rcp (
new ortho_type (label_));
1047 ortho_ = rcp (
new ortho_type (label_));
1048 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
1051 else if (orthoType_ ==
"ICGS") {
1053 ortho_ = rcp (
new ortho_type (label_));
1055 else if (orthoType_ ==
"IMGS") {
1057 ortho_ = rcp (
new ortho_type (label_));
1059 #ifdef HAVE_BELOS_TSQR 1060 else if (orthoType_ ==
"TSQR") {
1062 ortho_ = rcp (
new ortho_type (label_));
1064 #endif // HAVE_BELOS_TSQR 1066 #ifdef HAVE_BELOS_TSQR 1067 TEUCHOS_TEST_FOR_EXCEPTION(
1068 orthoType_ !=
"ICGS" && orthoType_ !=
"DGKS" &&
1069 orthoType_ !=
"IMGS" && orthoType_ !=
"TSQR",
1071 "Belos::PseudoBlockGmresSolMgr::setParameters(): " 1072 "Invalid orthogonalization type \"" << orthoType_ <<
"\".");
1074 TEUCHOS_TEST_FOR_EXCEPTION(
1075 orthoType_ !=
"ICGS" && orthoType_ !=
"DGKS" &&
1076 orthoType_ !=
"IMGS",
1078 "Belos::PseudoBlockGmresSolMgr::setParameters(): " 1079 "Invalid orthogonalization type \"" << orthoType_ <<
"\".");
1080 #endif // HAVE_BELOS_TSQR 1085 if (timerSolve_ == Teuchos::null) {
1086 std::string solveLabel = label_ +
": PseudoBlockGmresSolMgr total solve time";
1087 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1088 timerSolve_ = Teuchos::TimeMonitor::getNewCounter (solveLabel);
1097 template<
class ScalarType,
class MV,
class OP>
1104 userConvStatusTest_ = userConvStatusTest;
1105 comboType_ = comboType;
1108 template<
class ScalarType,
class MV,
class OP>
1114 debugStatusTest_ = debugStatusTest;
1119 template<
class ScalarType,
class MV,
class OP>
1120 Teuchos::RCP<const Teuchos::ParameterList>
1123 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
1124 if (is_null(validPL)) {
1125 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
1127 pl= Teuchos::rcp(
new Teuchos::ParameterList() );
1128 pl->set(
"Convergence Tolerance", convtol_default_,
1129 "The relative residual tolerance that needs to be achieved by the\n" 1130 "iterative solver in order for the linear system to be declared converged.");
1131 pl->set(
"Maximum Restarts", maxRestarts_default_,
1132 "The maximum number of restarts allowed for each\n" 1133 "set of RHS solved.");
1134 pl->set(
"Maximum Iterations", maxIters_default_,
1135 "The maximum number of block iterations allowed for each\n" 1136 "set of RHS solved.");
1137 pl->set(
"Num Blocks", numBlocks_default_,
1138 "The maximum number of vectors allowed in the Krylov subspace\n" 1139 "for each set of RHS solved.");
1140 pl->set(
"Block Size", blockSize_default_,
1141 "The number of RHS solved simultaneously.");
1142 pl->set(
"Verbosity", verbosity_default_,
1143 "What type(s) of solver information should be outputted\n" 1144 "to the output stream.");
1145 pl->set(
"Output Style", outputStyle_default_,
1146 "What style is used for the solver information outputted\n" 1147 "to the output stream.");
1148 pl->set(
"Output Frequency", outputFreq_default_,
1149 "How often convergence information should be outputted\n" 1150 "to the output stream.");
1151 pl->set(
"Deflation Quorum", defQuorum_default_,
1152 "The number of linear systems that need to converge before\n" 1153 "they are deflated. This number should be <= block size.");
1154 pl->set(
"Output Stream", outputStream_default_,
1155 "A reference-counted pointer to the output stream where all\n" 1156 "solver output is sent.");
1157 pl->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
1158 "When convergence information is printed, only show the maximum\n" 1159 "relative residual norm when the block size is greater than one.");
1160 pl->set(
"Implicit Residual Scaling", impResScale_default_,
1161 "The type of scaling used in the implicit residual convergence test.");
1162 pl->set(
"Explicit Residual Scaling", expResScale_default_,
1163 "The type of scaling used in the explicit residual convergence test.");
1164 pl->set(
"Timer Label", label_default_,
1165 "The string to use as a prefix for the timer labels.");
1166 pl->set(
"Orthogonalization", orthoType_default_,
1167 "The type of orthogonalization to use: DGKS, ICGS, IMGS.");
1168 pl->set(
"Orthogonalization Constant",orthoKappa_default_,
1169 "The constant used by DGKS orthogonalization to determine\n" 1170 "whether another step of classical Gram-Schmidt is necessary.");
1171 pl->sublist(
"User Status Tests");
1172 pl->set(
"User Status Tests Combo Type",
"SEQ",
1173 "Type of logical combination operation of user-defined\n" 1174 "and/or solver-specific status tests.");
1181 template<
class ScalarType,
class MV,
class OP>
1193 if ( !Teuchos::is_null(problem_->getLeftPrec()) ) {
1200 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
1201 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
1202 if(impResScale_ ==
"User Provided")
1207 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1208 impConvTest_ = tmpImpConvTest;
1211 Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
1212 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
1213 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
1214 if(expResScale_ ==
"User Provided")
1218 tmpExpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1219 expConvTest_ = tmpExpConvTest;
1222 convTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
1228 Teuchos::RCP<StatusTestImpResNorm_t> tmpImpConvTest =
1229 Teuchos::rcp(
new StatusTestImpResNorm_t( convtol_, defQuorum_ ) );
1230 if(impResScale_ ==
"User Provided")
1234 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1235 impConvTest_ = tmpImpConvTest;
1238 expConvTest_ = impConvTest_;
1239 convTest_ = impConvTest_;
1242 if (nonnull(userConvStatusTest_) ) {
1244 convTest_ = Teuchos::rcp(
1245 new StatusTestCombo_t( comboType_, convTest_, userConvStatusTest_ ) );
1252 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
1255 if (nonnull(debugStatusTest_) ) {
1257 Teuchos::rcp_dynamic_cast<StatusTestCombo_t>(sTest_)->addStatusTest( debugStatusTest_ );
1266 std::string solverDesc =
" Pseudo Block Gmres ";
1267 outputTest_->setSolverDesc( solverDesc );
1278 template<
class ScalarType,
class MV,
class OP>
1286 Teuchos::BLAS<int,ScalarType> blas;
1289 "Belos::PseudoBlockGmresSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
1292 if (!isSTSet_ || (!expResTest_ && !Teuchos::is_null(problem_->getLeftPrec())) ) {
1294 "Belos::BlockGmresSolMgr::solve(): Linear problem and requested status tests are incompatible.");
1300 int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1302 std::vector<int> currIdx( numCurrRHS );
1303 blockSize_ = numCurrRHS;
1304 for (
int i=0; i<numCurrRHS; ++i)
1305 { currIdx[i] = startPtr+i; }
1308 problem_->setLSIndex( currIdx );
1312 Teuchos::ParameterList plist;
1313 plist.set(
"Num Blocks",numBlocks_);
1316 outputTest_->reset();
1317 loaDetected_ =
false;
1320 bool isConverged =
true;
1325 Teuchos::RCP<PseudoBlockGmresIter<ScalarType,MV,OP> > block_gmres_iter
1330 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1331 Teuchos::TimeMonitor slvtimer(*timerSolve_);
1334 while ( numRHS2Solve > 0 ) {
1337 std::vector<int> convRHSIdx;
1338 std::vector<int> currRHSIdx( currIdx );
1339 currRHSIdx.resize(numCurrRHS);
1342 block_gmres_iter->setNumBlocks( numBlocks_ );
1345 block_gmres_iter->resetNumIters();
1348 outputTest_->resetNumCalls();
1354 std::vector<int> index(1);
1355 Teuchos::RCP<MV> tmpV, R_0 =
MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1356 newState.
V.resize( blockSize_ );
1357 newState.
Z.resize( blockSize_ );
1358 for (
int i=0; i<blockSize_; ++i) {
1363 Teuchos::RCP<Teuchos::SerialDenseVector<int,ScalarType> > tmpZ
1364 = Teuchos::rcp(
new Teuchos::SerialDenseVector<int,ScalarType>( 1 ));
1367 int rank = ortho_->normalize( *tmpV, tmpZ );
1369 "Belos::PseudoBlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors.");
1371 newState.
V[i] = tmpV;
1372 newState.
Z[i] = tmpZ;
1376 block_gmres_iter->initialize(newState);
1377 int numRestarts = 0;
1383 block_gmres_iter->iterate();
1390 if ( convTest_->getStatus() ==
Passed ) {
1392 if ( expConvTest_->getLOADetected() ) {
1402 loaDetected_ =
true;
1404 "Belos::PseudoBlockGmresSolMgr::solve(): Warning! Solver has experienced a loss of accuracy!" << std::endl;
1405 isConverged =
false;
1409 std::vector<int> convIdx = expConvTest_->convIndices();
1413 if (convIdx.size() == currRHSIdx.size())
1420 problem_->setCurrLS();
1424 int curDim = oldState.
curDim;
1429 std::vector<int> oldRHSIdx( currRHSIdx );
1430 std::vector<int> defRHSIdx;
1431 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
1433 for (
unsigned int j=0; j<convIdx.size(); ++j) {
1434 if (currRHSIdx[i] == convIdx[j]) {
1440 defRHSIdx.push_back( i );
1443 defState.
V.push_back( Teuchos::rcp_const_cast<MV>( oldState.
V[i] ) );
1444 defState.
Z.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseVector<int,ScalarType> >( oldState.
Z[i] ) );
1445 defState.
H.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseMatrix<int,ScalarType> >( oldState.
H[i] ) );
1446 defState.
sn.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseVector<int,ScalarType> >( oldState.
sn[i] ) );
1447 defState.
cs.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseVector<int,MagnitudeType> >(oldState.
cs[i] ) );
1448 currRHSIdx[have] = currRHSIdx[i];
1452 defRHSIdx.resize(currRHSIdx.size()-have);
1453 currRHSIdx.resize(have);
1457 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1461 problem_->setLSIndex( convIdx );
1464 problem_->updateSolution( defUpdate,
true );
1468 problem_->setLSIndex( currRHSIdx );
1471 defState.
curDim = curDim;
1474 block_gmres_iter->initialize(defState);
1481 else if ( maxIterTest_->getStatus() ==
Passed ) {
1483 isConverged =
false;
1491 else if ( block_gmres_iter->getCurSubspaceDim() == block_gmres_iter->getMaxSubspaceDim() ) {
1493 if ( numRestarts >= maxRestarts_ ) {
1494 isConverged =
false;
1499 printer_->stream(
Debug) <<
" Performing restart number " << numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
1502 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1503 problem_->updateSolution( update,
true );
1510 newstate.
V.resize(currRHSIdx.size());
1511 newstate.
Z.resize(currRHSIdx.size());
1515 R_0 =
MVT::Clone( *(problem_->getInitPrecResVec()), currRHSIdx.size() );
1516 problem_->computeCurrPrecResVec( &*R_0 );
1517 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
1523 Teuchos::RCP<Teuchos::SerialDenseVector<int,ScalarType> > tmpZ
1524 = Teuchos::rcp(
new Teuchos::SerialDenseVector<int,ScalarType>( 1 ));
1527 int rank = ortho_->normalize( *tmpV, tmpZ );
1529 "Belos::PseudoBlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors after the restart.");
1531 newstate.
V[i] = tmpV;
1532 newstate.
Z[i] = tmpZ;
1537 block_gmres_iter->initialize(newstate);
1549 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
1550 "Belos::PseudoBlockGmresSolMgr::solve(): Invalid return from PseudoBlockGmresIter::iterate().");
1556 block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
1559 sTest_->checkStatus( &*block_gmres_iter );
1560 if (convTest_->getStatus() !=
Passed)
1561 isConverged =
false;
1564 catch (
const std::exception &e) {
1565 printer_->stream(
Errors) <<
"Error! Caught std::exception in PseudoBlockGmresIter::iterate() at iteration " 1566 << block_gmres_iter->getNumIters() << std::endl
1567 << e.what() << std::endl;
1574 if (nonnull(userConvStatusTest_)) {
1576 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1577 problem_->updateSolution( update,
true );
1579 else if (nonnull(expConvTest_->getSolution())) {
1581 Teuchos::RCP<MV> newX = expConvTest_->getSolution();
1582 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1587 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1588 problem_->updateSolution( update,
true );
1592 problem_->setCurrLS();
1595 startPtr += numCurrRHS;
1596 numRHS2Solve -= numCurrRHS;
1597 if ( numRHS2Solve > 0 ) {
1598 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1600 blockSize_ = numCurrRHS;
1601 currIdx.resize( numCurrRHS );
1602 for (
int i=0; i<numCurrRHS; ++i)
1603 { currIdx[i] = startPtr+i; }
1606 if (defQuorum_ > blockSize_) {
1607 if (impConvTest_ != Teuchos::null)
1608 impConvTest_->setQuorum( blockSize_ );
1609 if (expConvTest_ != Teuchos::null)
1610 expConvTest_->setQuorum( blockSize_ );
1614 problem_->setLSIndex( currIdx );
1617 currIdx.resize( numRHS2Solve );
1628 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1633 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1637 numIters_ = maxIterTest_->getNumIters();
1650 const std::vector<MagnitudeType>* pTestValues = NULL;
1652 pTestValues = expConvTest_->getTestValue();
1653 if (pTestValues == NULL || pTestValues->size() < 1) {
1654 pTestValues = impConvTest_->getTestValue();
1659 pTestValues = impConvTest_->getTestValue();
1661 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1662 "Belos::PseudoBlockGmresSolMgr::solve(): The implicit convergence test's " 1663 "getTestValue() method returned NULL. Please report this bug to the " 1664 "Belos developers.");
1665 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1666 "Belos::PseudoBlockGmresSolMgr::solve(): The implicit convergence test's " 1667 "getTestValue() method returned a vector of length zero. Please report " 1668 "this bug to the Belos developers.");
1673 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1676 if (!isConverged || loaDetected_) {
1683 template<
class ScalarType,
class MV,
class OP>
1686 std::ostringstream out;
1688 out <<
"\"Belos::PseudoBlockGmresSolMgr\": {";
1689 if (this->getObjectLabel () !=
"") {
1690 out <<
"Label: " << this->getObjectLabel () <<
", ";
1692 out <<
"Num Blocks: " << numBlocks_
1693 <<
", Maximum Iterations: " << maxIters_
1694 <<
", Maximum Restarts: " << maxRestarts_
1695 <<
", Convergence Tolerance: " << convtol_
1701 template<
class ScalarType,
class MV,
class OP>
1705 const Teuchos::EVerbosityLevel verbLevel)
const 1707 using Teuchos::TypeNameTraits;
1708 using Teuchos::VERB_DEFAULT;
1709 using Teuchos::VERB_NONE;
1710 using Teuchos::VERB_LOW;
1717 const Teuchos::EVerbosityLevel vl =
1718 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
1720 if (vl != VERB_NONE) {
1721 Teuchos::OSTab tab0 (out);
1723 out <<
"\"Belos::PseudoBlockGmresSolMgr\":" << endl;
1724 Teuchos::OSTab tab1 (out);
1725 out <<
"Template parameters:" << endl;
1727 Teuchos::OSTab tab2 (out);
1728 out <<
"ScalarType: " << TypeNameTraits<ScalarType>::name () << endl
1729 <<
"MV: " << TypeNameTraits<MV>::name () << endl
1730 <<
"OP: " << TypeNameTraits<OP>::name () << endl;
1732 if (this->getObjectLabel () !=
"") {
1733 out <<
"Label: " << this->getObjectLabel () << endl;
1735 out <<
"Num Blocks: " << numBlocks_ << endl
1736 <<
"Maximum Iterations: " << maxIters_ << endl
1737 <<
"Maximum Restarts: " << maxRestarts_ << endl
1738 <<
"Convergence Tolerance: " << convtol_ << endl;
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...
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
bool isLOADetected() const
Whether a "loss of accuracy" was detected during the last solve().
Class which manages the output and verbosity of the Belos solvers.
PseudoBlockGmresSolMgr()
Empty constructor.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the parameters the solver manager should use to solve the linear problem.
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...
PseudoBlockGmresSolMgrOrthoFailure(const std::string &what_arg)
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
A factory class for generating StatusTestOutput objects.
std::vector< Teuchos::RCP< const MV > > V
The current Krylov basis.
An implementation of StatusTestResNorm using a family of residual norms.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
A list of valid default parameters for this solver.
int getNumIters() const
Iteration count for the most recent call to solve().
A pure virtual class for defining the status tests for the Belos iterative solvers.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
Structure to contain pointers to PseudoBlockGmresIter state variables.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
A factory class for generating StatusTestOutput objects.
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
virtual void setUserConvStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &userConvStatusTest, const typename StatusTestCombo< ScalarType, MV, OP >::ComboType &comboType=StatusTestCombo< ScalarType, MV, OP >::SEQ)
Set a custom status test.
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
Traits class which defines basic operations on multivectors.
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class...
A Belos::StatusTest class for specifying a maximum number of iterations.
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
ResetType
How to reset the solver.
Pure virtual base class which describes the basic interface for a solver manager. ...
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.
std::string description() const
Return a one-line description of this object.
Interface to standard and "pseudoblock" GMRES.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
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 ...
Iterated Classical Gram-Schmidt (ICGS) implementation of the Belos::OrthoManager class.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
The current parameters for this solver.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, ScalarType > > > Z
The current right-hand side of the least squares system RY = Z.
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > create(const Teuchos::RCP< OutputManager< ScalarType > > &printer, Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test, int mod, int printStates)
Create the StatusTestOutput object specified by the outputStyle.
Belos concrete class for performing the pseudo-block GMRES iteration.
void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &debugStatusTest)
Set a debug status test that will be checked at the same time as the top-level status test...
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.
Orthogonalization manager based on Tall Skinny QR (TSQR)
Class which defines basic traits for the operator type.
int curDim
The current dimension of the reduction.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem to solve.
Parent class to all Belos exceptions.
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, ScalarType > > > sn
The current Given's rotation coefficients.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
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.
PseudoBlockGmresIterOrthoFailure is thrown when the orthogonalization manager is unable to generate o...
PseudoBlockGmresSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate...