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 68 #include "Teuchos_BLAS.hpp" 69 #ifdef BELOS_TEUCHOS_TIME_MONITOR 70 #include "Teuchos_TimeMonitor.hpp" 128 template<
class ScalarType,
class MV,
class OP>
134 typedef Teuchos::ScalarTraits<ScalarType> SCT;
135 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
136 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
256 const Teuchos::RCP<Teuchos::ParameterList> &pl );
270 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const;
280 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
281 return Teuchos::tuple(timerSolve_);
371 void setParameters (
const Teuchos::RCP<Teuchos::ParameterList> ¶ms);
379 virtual void setUserConvStatusTest(
388 virtual void setDebugStatusTest(
437 describe (Teuchos::FancyOStream& out,
438 const Teuchos::EVerbosityLevel verbLevel =
439 Teuchos::Describable::verbLevel_default)
const;
442 std::string description ()
const;
462 bool checkStatusTest();
465 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
468 Teuchos::RCP<OutputManager<ScalarType> > printer_;
469 Teuchos::RCP<std::ostream> outputStream_;
472 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > userConvStatusTest_;
473 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > debugStatusTest_;
474 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
475 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
476 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
477 Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > impConvTest_, expConvTest_;
478 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
481 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > ortho_;
484 Teuchos::RCP<Teuchos::ParameterList> params_;
487 static const MagnitudeType convtol_default_;
488 static const MagnitudeType orthoKappa_default_;
489 static const int maxRestarts_default_;
490 static const int maxIters_default_;
491 static const bool showMaxResNormOnly_default_;
492 static const int blockSize_default_;
493 static const int numBlocks_default_;
494 static const int verbosity_default_;
495 static const int outputStyle_default_;
496 static const int outputFreq_default_;
497 static const int defQuorum_default_;
498 static const std::string impResScale_default_;
499 static const std::string expResScale_default_;
500 static const std::string label_default_;
501 static const std::string orthoType_default_;
502 static const Teuchos::RCP<std::ostream> outputStream_default_;
505 MagnitudeType convtol_, orthoKappa_, achievedTol_;
506 int maxRestarts_, maxIters_, numIters_;
507 int blockSize_, numBlocks_, verbosity_, outputStyle_, outputFreq_, defQuorum_;
508 bool showMaxResNormOnly_;
509 std::string orthoType_;
510 std::string impResScale_, expResScale_;
514 Teuchos::RCP<Teuchos::Time> timerSolve_;
517 bool isSet_, isSTSet_, expResTest_;
523 template<
class ScalarType,
class MV,
class OP>
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>
573 template<
class ScalarType,
class MV,
class OP>
575 outputStream_(outputStream_default_),
576 convtol_(convtol_default_),
577 orthoKappa_(orthoKappa_default_),
578 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
579 maxRestarts_(maxRestarts_default_),
580 maxIters_(maxIters_default_),
582 blockSize_(blockSize_default_),
583 numBlocks_(numBlocks_default_),
584 verbosity_(verbosity_default_),
585 outputStyle_(outputStyle_default_),
586 outputFreq_(outputFreq_default_),
587 defQuorum_(defQuorum_default_),
588 showMaxResNormOnly_(showMaxResNormOnly_default_),
589 orthoType_(orthoType_default_),
590 impResScale_(impResScale_default_),
591 expResScale_(expResScale_default_),
592 label_(label_default_),
600 template<
class ScalarType,
class MV,
class OP>
603 const Teuchos::RCP<Teuchos::ParameterList> &pl) :
605 outputStream_(outputStream_default_),
606 convtol_(convtol_default_),
607 orthoKappa_(orthoKappa_default_),
608 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
609 maxRestarts_(maxRestarts_default_),
610 maxIters_(maxIters_default_),
612 blockSize_(blockSize_default_),
613 numBlocks_(numBlocks_default_),
614 verbosity_(verbosity_default_),
615 outputStyle_(outputStyle_default_),
616 outputFreq_(outputFreq_default_),
617 defQuorum_(defQuorum_default_),
618 showMaxResNormOnly_(showMaxResNormOnly_default_),
619 orthoType_(orthoType_default_),
620 impResScale_(impResScale_default_),
621 expResScale_(expResScale_default_),
622 label_(label_default_),
628 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager.");
637 template<
class ScalarType,
class MV,
class OP>
642 using Teuchos::ParameterList;
643 using Teuchos::parameterList;
645 using Teuchos::rcp_dynamic_cast;
648 if (params_ == Teuchos::null) {
655 if (params->isParameter (
"Maximum Restarts")) {
656 maxRestarts_ = params->get (
"Maximum Restarts", maxRestarts_default_);
659 params_->set (
"Maximum Restarts", maxRestarts_);
663 if (params->isParameter (
"Maximum Iterations")) {
664 maxIters_ = params->get (
"Maximum Iterations", maxIters_default_);
667 params_->set (
"Maximum Iterations", maxIters_);
668 if (! maxIterTest_.is_null ()) {
669 maxIterTest_->setMaxIters (maxIters_);
674 if (params->isParameter (
"Block Size")) {
675 blockSize_ = params->get (
"Block Size", blockSize_default_);
676 TEUCHOS_TEST_FOR_EXCEPTION(
677 blockSize_ <= 0, std::invalid_argument,
678 "Belos::PseudoBlockGmresSolMgr::setParameters: " 679 "The \"Block Size\" parameter must be strictly positive, " 680 "but you specified a value of " << blockSize_ <<
".");
683 params_->set (
"Block Size", blockSize_);
687 if (params->isParameter (
"Num Blocks")) {
688 numBlocks_ = params->get (
"Num Blocks", numBlocks_default_);
689 TEUCHOS_TEST_FOR_EXCEPTION(
690 numBlocks_ <= 0, std::invalid_argument,
691 "Belos::PseudoBlockGmresSolMgr::setParameters: " 692 "The \"Num Blocks\" parameter must be strictly positive, " 693 "but you specified a value of " << numBlocks_ <<
".");
696 params_->set (
"Num Blocks", numBlocks_);
700 if (params->isParameter (
"Timer Label")) {
701 const std::string tempLabel = params->get (
"Timer Label", label_default_);
704 if (tempLabel != label_) {
706 params_->set (
"Timer Label", label_);
707 const std::string solveLabel =
708 label_ +
": PseudoBlockGmresSolMgr total solve time";
709 #ifdef BELOS_TEUCHOS_TIME_MONITOR 710 timerSolve_ = Teuchos::TimeMonitor::getNewCounter (solveLabel);
711 #endif // BELOS_TEUCHOS_TIME_MONITOR 712 if (ortho_ != Teuchos::null) {
713 ortho_->setLabel( label_ );
719 if (params->isParameter (
"Orthogonalization")) {
720 std::string tempOrthoType = params->get (
"Orthogonalization", orthoType_default_);
721 #ifdef HAVE_BELOS_TSQR 722 TEUCHOS_TEST_FOR_EXCEPTION(
723 tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" &&
724 tempOrthoType !=
"IMGS" && tempOrthoType !=
"TSQR",
725 std::invalid_argument,
726 "Belos::PseudoBlockGmresSolMgr::setParameters: " 727 "The \"Orthogonalization\" parameter must be one of \"DGKS\", \"ICGS\", " 728 "\"IMGS\", or \"TSQR\".");
730 TEUCHOS_TEST_FOR_EXCEPTION(
731 tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" &&
732 tempOrthoType !=
"IMGS",
733 std::invalid_argument,
734 "Belos::PseudoBlockGmresSolMgr::setParameters: " 735 "The \"Orthogonalization\" parameter must be one of \"DGKS\", \"ICGS\", " 737 #endif // HAVE_BELOS_TSQR 739 if (tempOrthoType != orthoType_) {
740 orthoType_ = tempOrthoType;
742 if (orthoType_ ==
"DGKS") {
744 if (orthoKappa_ <= 0) {
745 ortho_ = rcp (
new ortho_type (label_));
748 ortho_ = rcp (
new ortho_type (label_));
749 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
752 else if (orthoType_ ==
"ICGS") {
754 ortho_ = rcp (
new ortho_type (label_));
756 else if (orthoType_ ==
"IMGS") {
758 ortho_ = rcp (
new ortho_type (label_));
760 #ifdef HAVE_BELOS_TSQR 761 else if (orthoType_ ==
"TSQR") {
763 ortho_ = rcp (
new ortho_type (label_));
765 #endif // HAVE_BELOS_TSQR 770 if (params->isParameter (
"Orthogonalization Constant")) {
771 orthoKappa_ = params->get (
"Orthogonalization Constant", orthoKappa_default_);
774 params_->set (
"Orthogonalization Constant", orthoKappa_);
775 if (orthoType_ ==
"DGKS") {
776 if (orthoKappa_ > 0 && ! ortho_.is_null ()) {
778 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
784 if (params->isParameter (
"Verbosity")) {
785 if (Teuchos::isParameterType<int> (*params,
"Verbosity")) {
786 verbosity_ = params->get (
"Verbosity", verbosity_default_);
788 verbosity_ = (int) Teuchos::getParameter<Belos::MsgType> (*params,
"Verbosity");
792 params_->set (
"Verbosity", verbosity_);
793 if (! printer_.is_null ()) {
794 printer_->setVerbosity (verbosity_);
799 if (params->isParameter (
"Output Style")) {
800 if (Teuchos::isParameterType<int> (*params,
"Output Style")) {
801 outputStyle_ = params->get (
"Output Style", outputStyle_default_);
803 outputStyle_ = (int) Teuchos::getParameter<Belos::OutputType> (*params,
"Output Style");
807 params_->set (
"Output Style", verbosity_);
808 if (! outputTest_.is_null ()) {
814 if (params->isParameter (
"Output Stream")) {
815 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> > (*params,
"Output Stream");
818 params_->set(
"Output Stream", outputStream_);
819 if (! printer_.is_null ()) {
820 printer_->setOStream (outputStream_);
826 if (params->isParameter (
"Output Frequency")) {
827 outputFreq_ = params->get (
"Output Frequency", outputFreq_default_);
831 params_->set (
"Output Frequency", outputFreq_);
832 if (! outputTest_.is_null ()) {
833 outputTest_->setOutputFrequency (outputFreq_);
838 if (printer_.is_null ()) {
845 if (params->isParameter (
"Convergence Tolerance")) {
846 convtol_ = params->get (
"Convergence Tolerance", convtol_default_);
849 params_->set (
"Convergence Tolerance", convtol_);
850 if (! impConvTest_.is_null ()) {
851 impConvTest_->setTolerance (convtol_);
853 if (! expConvTest_.is_null ()) {
854 expConvTest_->setTolerance (convtol_);
859 if (params->isParameter (
"Implicit Residual Scaling")) {
860 const std::string tempImpResScale =
861 Teuchos::getParameter<std::string> (*params,
"Implicit Residual Scaling");
864 if (impResScale_ != tempImpResScale) {
866 impResScale_ = tempImpResScale;
869 params_->set (
"Implicit Residual Scaling", impResScale_);
870 if (! impConvTest_.is_null ()) {
874 catch (std::exception& e) {
882 if (params->isParameter (
"Explicit Residual Scaling")) {
883 const std::string tempExpResScale =
884 Teuchos::getParameter<std::string> (*params,
"Explicit Residual Scaling");
887 if (expResScale_ != tempExpResScale) {
889 expResScale_ = tempExpResScale;
892 params_->set (
"Explicit Residual Scaling", expResScale_);
893 if (! expConvTest_.is_null ()) {
897 catch (std::exception& e) {
906 if (params->isParameter (
"Show Maximum Residual Norm Only")) {
907 showMaxResNormOnly_ =
908 Teuchos::getParameter<bool> (*params,
"Show Maximum Residual Norm Only");
911 params_->set (
"Show Maximum Residual Norm Only", showMaxResNormOnly_);
912 if (! impConvTest_.is_null ()) {
913 impConvTest_->setShowMaxResNormOnly (showMaxResNormOnly_);
915 if (! expConvTest_.is_null ()) {
916 expConvTest_->setShowMaxResNormOnly (showMaxResNormOnly_);
923 if (params->isParameter(
"Deflation Quorum")) {
924 defQuorum_ = params->get(
"Deflation Quorum", defQuorum_);
925 TEUCHOS_TEST_FOR_EXCEPTION(
926 defQuorum_ > blockSize_, std::invalid_argument,
927 "Belos::PseudoBlockGmresSolMgr::setParameters: " 928 "The \"Deflation Quorum\" parameter (= " << defQuorum_ <<
") must not be " 929 "larger than \"Block Size\" (= " << blockSize_ <<
").");
930 params_->set (
"Deflation Quorum", defQuorum_);
931 if (! impConvTest_.is_null ()) {
932 impConvTest_->setQuorum (defQuorum_);
934 if (! expConvTest_.is_null ()) {
935 expConvTest_->setQuorum (defQuorum_);
940 if (ortho_.is_null ()) {
941 if (orthoType_ ==
"DGKS") {
943 if (orthoKappa_ <= 0) {
944 ortho_ = rcp (
new ortho_type (label_));
947 ortho_ = rcp (
new ortho_type (label_));
948 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
951 else if (orthoType_ ==
"ICGS") {
953 ortho_ = rcp (
new ortho_type (label_));
955 else if (orthoType_ ==
"IMGS") {
957 ortho_ = rcp (
new ortho_type (label_));
959 #ifdef HAVE_BELOS_TSQR 960 else if (orthoType_ ==
"TSQR") {
962 ortho_ = rcp (
new ortho_type (label_));
964 #endif // HAVE_BELOS_TSQR 966 #ifdef HAVE_BELOS_TSQR 967 TEUCHOS_TEST_FOR_EXCEPTION(
968 orthoType_ !=
"ICGS" && orthoType_ !=
"DGKS" &&
969 orthoType_ !=
"IMGS" && orthoType_ !=
"TSQR",
971 "Belos::PseudoBlockGmresSolMgr::setParameters(): " 972 "Invalid orthogonalization type \"" << orthoType_ <<
"\".");
974 TEUCHOS_TEST_FOR_EXCEPTION(
975 orthoType_ !=
"ICGS" && orthoType_ !=
"DGKS" &&
976 orthoType_ !=
"IMGS",
978 "Belos::PseudoBlockGmresSolMgr::setParameters(): " 979 "Invalid orthogonalization type \"" << orthoType_ <<
"\".");
980 #endif // HAVE_BELOS_TSQR 985 if (timerSolve_ == Teuchos::null) {
986 std::string solveLabel = label_ +
": PseudoBlockGmresSolMgr total solve time";
987 #ifdef BELOS_TEUCHOS_TIME_MONITOR 988 timerSolve_ = Teuchos::TimeMonitor::getNewCounter (solveLabel);
997 template<
class ScalarType,
class MV,
class OP>
1003 userConvStatusTest_ = userConvStatusTest;
1006 template<
class ScalarType,
class MV,
class OP>
1012 debugStatusTest_ = debugStatusTest;
1017 template<
class ScalarType,
class MV,
class OP>
1018 Teuchos::RCP<const Teuchos::ParameterList>
1021 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
1022 if (is_null(validPL)) {
1023 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
1025 pl= Teuchos::rcp(
new Teuchos::ParameterList() );
1026 pl->set(
"Convergence Tolerance", convtol_default_,
1027 "The relative residual tolerance that needs to be achieved by the\n" 1028 "iterative solver in order for the linear system to be declared converged.");
1029 pl->set(
"Maximum Restarts", maxRestarts_default_,
1030 "The maximum number of restarts allowed for each\n" 1031 "set of RHS solved.");
1032 pl->set(
"Maximum Iterations", maxIters_default_,
1033 "The maximum number of block iterations allowed for each\n" 1034 "set of RHS solved.");
1035 pl->set(
"Num Blocks", numBlocks_default_,
1036 "The maximum number of vectors allowed in the Krylov subspace\n" 1037 "for each set of RHS solved.");
1038 pl->set(
"Block Size", blockSize_default_,
1039 "The number of RHS solved simultaneously.");
1040 pl->set(
"Verbosity", verbosity_default_,
1041 "What type(s) of solver information should be outputted\n" 1042 "to the output stream.");
1043 pl->set(
"Output Style", outputStyle_default_,
1044 "What style is used for the solver information outputted\n" 1045 "to the output stream.");
1046 pl->set(
"Output Frequency", outputFreq_default_,
1047 "How often convergence information should be outputted\n" 1048 "to the output stream.");
1049 pl->set(
"Deflation Quorum", defQuorum_default_,
1050 "The number of linear systems that need to converge before\n" 1051 "they are deflated. This number should be <= block size.");
1052 pl->set(
"Output Stream", outputStream_default_,
1053 "A reference-counted pointer to the output stream where all\n" 1054 "solver output is sent.");
1055 pl->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
1056 "When convergence information is printed, only show the maximum\n" 1057 "relative residual norm when the block size is greater than one.");
1058 pl->set(
"Implicit Residual Scaling", impResScale_default_,
1059 "The type of scaling used in the implicit residual convergence test.");
1060 pl->set(
"Explicit Residual Scaling", expResScale_default_,
1061 "The type of scaling used in the explicit residual convergence test.");
1062 pl->set(
"Timer Label", label_default_,
1063 "The string to use as a prefix for the timer labels.");
1065 pl->set(
"Orthogonalization", orthoType_default_,
1066 "The type of orthogonalization to use: DGKS, ICGS, IMGS.");
1067 pl->set(
"Orthogonalization Constant",orthoKappa_default_,
1068 "The constant used by DGKS orthogonalization to determine\n" 1069 "whether another step of classical Gram-Schmidt is necessary.");
1076 template<
class ScalarType,
class MV,
class OP>
1088 if ( !Teuchos::is_null(problem_->getLeftPrec()) ) {
1095 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
1096 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
1098 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1099 impConvTest_ = tmpImpConvTest;
1102 Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
1103 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
1104 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
1106 tmpExpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1107 expConvTest_ = tmpExpConvTest;
1110 convTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
1116 Teuchos::RCP<StatusTestImpResNorm_t> tmpImpConvTest =
1117 Teuchos::rcp(
new StatusTestImpResNorm_t( convtol_, defQuorum_ ) );
1119 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1120 impConvTest_ = tmpImpConvTest;
1123 expConvTest_ = impConvTest_;
1124 convTest_ = impConvTest_;
1127 if (nonnull(debugStatusTest_) ) {
1129 convTest_ = Teuchos::rcp(
1130 new StatusTestCombo_t( StatusTestCombo_t::AND, convTest_, debugStatusTest_ ) );
1133 if (nonnull(userConvStatusTest_) ) {
1135 convTest_ = Teuchos::rcp(
1136 new StatusTestCombo_t( StatusTestCombo_t::SEQ, convTest_, userConvStatusTest_ ) );
1141 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
1149 std::string solverDesc =
" Pseudo Block Gmres ";
1150 outputTest_->setSolverDesc( solverDesc );
1161 template<
class ScalarType,
class MV,
class OP>
1169 Teuchos::BLAS<int,ScalarType> blas;
1172 "Belos::PseudoBlockGmresSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
1175 if (!isSTSet_ || (!expResTest_ && !Teuchos::is_null(problem_->getLeftPrec())) ) {
1177 "Belos::BlockGmresSolMgr::solve(): Linear problem and requested status tests are incompatible.");
1183 int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1185 std::vector<int> currIdx( numCurrRHS );
1186 blockSize_ = numCurrRHS;
1187 for (
int i=0; i<numCurrRHS; ++i)
1188 { currIdx[i] = startPtr+i; }
1191 problem_->setLSIndex( currIdx );
1195 Teuchos::ParameterList plist;
1196 plist.set(
"Num Blocks",numBlocks_);
1199 outputTest_->reset();
1200 loaDetected_ =
false;
1203 bool isConverged =
true;
1208 Teuchos::RCP<PseudoBlockGmresIter<ScalarType,MV,OP> > block_gmres_iter
1213 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1214 Teuchos::TimeMonitor slvtimer(*timerSolve_);
1217 while ( numRHS2Solve > 0 ) {
1220 std::vector<int> convRHSIdx;
1221 std::vector<int> currRHSIdx( currIdx );
1222 currRHSIdx.resize(numCurrRHS);
1225 block_gmres_iter->setNumBlocks( numBlocks_ );
1228 block_gmres_iter->resetNumIters();
1231 outputTest_->resetNumCalls();
1237 std::vector<int> index(1);
1238 Teuchos::RCP<MV> tmpV, R_0 =
MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1239 newState.
V.resize( blockSize_ );
1240 newState.
Z.resize( blockSize_ );
1241 for (
int i=0; i<blockSize_; ++i) {
1246 Teuchos::RCP<Teuchos::SerialDenseVector<int,ScalarType> > tmpZ
1247 = Teuchos::rcp(
new Teuchos::SerialDenseVector<int,ScalarType>( 1 ));
1250 int rank = ortho_->normalize( *tmpV, tmpZ );
1252 "Belos::PseudoBlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors.");
1254 newState.
V[i] = tmpV;
1255 newState.
Z[i] = tmpZ;
1259 block_gmres_iter->initialize(newState);
1260 int numRestarts = 0;
1266 block_gmres_iter->iterate();
1273 if ( convTest_->getStatus() ==
Passed ) {
1275 if ( expConvTest_->getLOADetected() ) {
1285 loaDetected_ =
true;
1287 "Belos::PseudoBlockGmresSolMgr::solve(): Warning! Solver has experienced a loss of accuracy!" << std::endl;
1288 isConverged =
false;
1292 std::vector<int> convIdx = expConvTest_->convIndices();
1296 if (convIdx.size() == currRHSIdx.size())
1303 problem_->setCurrLS();
1307 int curDim = oldState.
curDim;
1312 std::vector<int> oldRHSIdx( currRHSIdx );
1313 std::vector<int> defRHSIdx;
1314 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
1316 for (
unsigned int j=0; j<convIdx.size(); ++j) {
1317 if (currRHSIdx[i] == convIdx[j]) {
1323 defRHSIdx.push_back( i );
1326 defState.
V.push_back( Teuchos::rcp_const_cast<MV>( oldState.
V[i] ) );
1327 defState.
Z.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseVector<int,ScalarType> >( oldState.
Z[i] ) );
1328 defState.
H.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseMatrix<int,ScalarType> >( oldState.
H[i] ) );
1329 defState.
sn.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseVector<int,ScalarType> >( oldState.
sn[i] ) );
1330 defState.
cs.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseVector<int,MagnitudeType> >(oldState.
cs[i] ) );
1331 currRHSIdx[have] = currRHSIdx[i];
1335 defRHSIdx.resize(currRHSIdx.size()-have);
1336 currRHSIdx.resize(have);
1340 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1344 problem_->setLSIndex( convIdx );
1347 problem_->updateSolution( defUpdate,
true );
1351 problem_->setLSIndex( currRHSIdx );
1354 defState.
curDim = curDim;
1357 block_gmres_iter->initialize(defState);
1364 else if ( maxIterTest_->getStatus() ==
Passed ) {
1366 isConverged =
false;
1374 else if ( block_gmres_iter->getCurSubspaceDim() == block_gmres_iter->getMaxSubspaceDim() ) {
1376 if ( numRestarts >= maxRestarts_ ) {
1377 isConverged =
false;
1382 printer_->stream(
Debug) <<
" Performing restart number " << numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
1385 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1386 problem_->updateSolution( update,
true );
1393 newstate.
V.resize(currRHSIdx.size());
1394 newstate.
Z.resize(currRHSIdx.size());
1398 R_0 =
MVT::Clone( *(problem_->getInitPrecResVec()), currRHSIdx.size() );
1399 problem_->computeCurrPrecResVec( &*R_0 );
1400 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
1406 Teuchos::RCP<Teuchos::SerialDenseVector<int,ScalarType> > tmpZ
1407 = Teuchos::rcp(
new Teuchos::SerialDenseVector<int,ScalarType>( 1 ));
1410 int rank = ortho_->normalize( *tmpV, tmpZ );
1412 "Belos::PseudoBlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors after the restart.");
1414 newstate.
V[i] = tmpV;
1415 newstate.
Z[i] = tmpZ;
1420 block_gmres_iter->initialize(newstate);
1432 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
1433 "Belos::PseudoBlockGmresSolMgr::solve(): Invalid return from PseudoBlockGmresIter::iterate().");
1439 block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
1442 sTest_->checkStatus( &*block_gmres_iter );
1443 if (convTest_->getStatus() !=
Passed)
1444 isConverged =
false;
1447 catch (
const std::exception &e) {
1448 printer_->stream(
Errors) <<
"Error! Caught std::exception in PseudoBlockGmresIter::iterate() at iteration " 1449 << block_gmres_iter->getNumIters() << std::endl
1450 << e.what() << std::endl;
1457 if (nonnull(userConvStatusTest_)) {
1459 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1460 problem_->updateSolution( update,
true );
1462 else if (nonnull(expConvTest_->getSolution())) {
1464 Teuchos::RCP<MV> newX = expConvTest_->getSolution();
1465 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1470 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1471 problem_->updateSolution( update,
true );
1475 problem_->setCurrLS();
1478 startPtr += numCurrRHS;
1479 numRHS2Solve -= numCurrRHS;
1480 if ( numRHS2Solve > 0 ) {
1481 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1483 blockSize_ = numCurrRHS;
1484 currIdx.resize( numCurrRHS );
1485 for (
int i=0; i<numCurrRHS; ++i)
1486 { currIdx[i] = startPtr+i; }
1489 if (defQuorum_ > blockSize_) {
1490 if (impConvTest_ != Teuchos::null)
1491 impConvTest_->setQuorum( blockSize_ );
1492 if (expConvTest_ != Teuchos::null)
1493 expConvTest_->setQuorum( blockSize_ );
1497 problem_->setLSIndex( currIdx );
1500 currIdx.resize( numRHS2Solve );
1511 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1516 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1520 numIters_ = maxIterTest_->getNumIters();
1533 const std::vector<MagnitudeType>* pTestValues = NULL;
1535 pTestValues = expConvTest_->getTestValue();
1536 if (pTestValues == NULL || pTestValues->size() < 1) {
1537 pTestValues = impConvTest_->getTestValue();
1542 pTestValues = impConvTest_->getTestValue();
1544 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1545 "Belos::PseudoBlockGmresSolMgr::solve(): The implicit convergence test's " 1546 "getTestValue() method returned NULL. Please report this bug to the " 1547 "Belos developers.");
1548 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1549 "Belos::PseudoBlockGmresSolMgr::solve(): The implicit convergence test's " 1550 "getTestValue() method returned a vector of length zero. Please report " 1551 "this bug to the Belos developers.");
1556 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1559 if (!isConverged || loaDetected_) {
1566 template<
class ScalarType,
class MV,
class OP>
1569 std::ostringstream out;
1571 out <<
"\"Belos::PseudoBlockGmresSolMgr\": {";
1572 if (this->getObjectLabel () !=
"") {
1573 out <<
"Label: " << this->getObjectLabel () <<
", ";
1575 out <<
"Num Blocks: " << numBlocks_
1576 <<
", Maximum Iterations: " << maxIters_
1577 <<
", Maximum Restarts: " << maxRestarts_
1578 <<
", Convergence Tolerance: " << convtol_
1584 template<
class ScalarType,
class MV,
class OP>
1588 const Teuchos::EVerbosityLevel verbLevel)
const 1590 using Teuchos::TypeNameTraits;
1591 using Teuchos::VERB_DEFAULT;
1592 using Teuchos::VERB_NONE;
1593 using Teuchos::VERB_LOW;
1600 const Teuchos::EVerbosityLevel vl =
1601 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
1603 if (vl != VERB_NONE) {
1604 Teuchos::OSTab tab0 (out);
1606 out <<
"\"Belos::PseudoBlockGmresSolMgr\":" << endl;
1607 Teuchos::OSTab tab1 (out);
1608 out <<
"Template parameters:" << endl;
1610 Teuchos::OSTab tab2 (out);
1611 out <<
"ScalarType: " << TypeNameTraits<ScalarType>::name () << endl
1612 <<
"MV: " << TypeNameTraits<MV>::name () << endl
1613 <<
"OP: " << TypeNameTraits<OP>::name () << endl;
1615 if (this->getObjectLabel () !=
"") {
1616 out <<
"Label: " << this->getObjectLabel () << endl;
1618 out <<
"Num Blocks: " << numBlocks_ << endl
1619 <<
"Maximum Iterations: " << maxIters_ << endl
1620 <<
"Maximum Restarts: " << maxRestarts_ << endl
1621 <<
"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.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
The current parameters for this solver.
virtual ~PseudoBlockGmresSolMgr()
Destructor.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
Class which manages the output and verbosity of the Belos solvers.
virtual void setUserConvStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &userConvStatusTest)
Set a custom status test.
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)
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.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
Belos::StatusTest class for specifying a maximum number of iterations.
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.
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.
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.
Belos::StatusTest for logically combining several status tests.
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. ...
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.
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.
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 ...
bool isLOADetected() const
Whether a "loss of accuracy" was detected during the last solve().
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.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest for specifying an implicit residual norm stopping criteria that checks for loss of ...
virtual void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &debugStatusTest)
Set a debug 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.
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
MatOrthoManager subclass using TSQR or DGKS.
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().
Belos header file which uses auto-configuration information to include necessary C++ headers...
std::string description() const
Return a one-line description of this object.
This class implements the pseudo-block GMRES iteration, where a block Krylov subspace is constructed ...
PseudoBlockGmresIterOrthoFailure is thrown when the orthogonalization manager is unable to generate o...
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
PseudoBlockGmresSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate...