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
69 #ifdef BELOS_TEUCHOS_TIME_MONITOR
128 template<
class ScalarType,
class MV,
class OP>
281 return Teuchos::tuple(timerSolve_);
442 bool checkStatusTest();
466 static const MagnitudeType convtol_default_;
467 static const MagnitudeType orthoKappa_default_;
468 static const int maxRestarts_default_;
469 static const int maxIters_default_;
470 static const bool showMaxResNormOnly_default_;
471 static const int blockSize_default_;
472 static const int numBlocks_default_;
473 static const int verbosity_default_;
474 static const int outputStyle_default_;
475 static const int outputFreq_default_;
476 static const int defQuorum_default_;
477 static const std::string impResScale_default_;
478 static const std::string expResScale_default_;
479 static const std::string label_default_;
480 static const std::string orthoType_default_;
484 MagnitudeType convtol_, orthoKappa_, achievedTol_;
485 int maxRestarts_, maxIters_, numIters_;
486 int blockSize_, numBlocks_, verbosity_, outputStyle_, outputFreq_, defQuorum_;
487 bool showMaxResNormOnly_;
488 std::string orthoType_;
489 std::string impResScale_, expResScale_;
496 bool isSet_, isSTSet_, expResTest_;
502 template<
class ScalarType,
class MV,
class OP>
503 const typename PseudoBlockGmresSolMgr<ScalarType,MV,OP>::MagnitudeType PseudoBlockGmresSolMgr<ScalarType,MV,OP>::convtol_default_ = 1e-8;
505 template<
class ScalarType,
class MV,
class OP>
506 const typename PseudoBlockGmresSolMgr<ScalarType,MV,OP>::MagnitudeType PseudoBlockGmresSolMgr<ScalarType,MV,OP>::orthoKappa_default_ = -1.0;
508 template<
class ScalarType,
class MV,
class OP>
509 const int PseudoBlockGmresSolMgr<ScalarType,MV,OP>::maxRestarts_default_ = 20;
511 template<
class ScalarType,
class MV,
class OP>
512 const int PseudoBlockGmresSolMgr<ScalarType,MV,OP>::maxIters_default_ = 1000;
514 template<
class ScalarType,
class MV,
class OP>
515 const bool PseudoBlockGmresSolMgr<ScalarType,MV,OP>::showMaxResNormOnly_default_ =
false;
517 template<
class ScalarType,
class MV,
class OP>
518 const int PseudoBlockGmresSolMgr<ScalarType,MV,OP>::blockSize_default_ = 1;
520 template<
class ScalarType,
class MV,
class OP>
521 const int PseudoBlockGmresSolMgr<ScalarType,MV,OP>::numBlocks_default_ = 300;
523 template<
class ScalarType,
class MV,
class OP>
524 const int PseudoBlockGmresSolMgr<ScalarType,MV,OP>::verbosity_default_ =
Belos::Errors;
526 template<
class ScalarType,
class MV,
class OP>
527 const int PseudoBlockGmresSolMgr<ScalarType,MV,OP>::outputStyle_default_ =
Belos::General;
529 template<
class ScalarType,
class MV,
class OP>
530 const int PseudoBlockGmresSolMgr<ScalarType,MV,OP>::outputFreq_default_ = -1;
532 template<
class ScalarType,
class MV,
class OP>
533 const int PseudoBlockGmresSolMgr<ScalarType,MV,OP>::defQuorum_default_ = 1;
535 template<
class ScalarType,
class MV,
class OP>
536 const std::string PseudoBlockGmresSolMgr<ScalarType,MV,OP>::impResScale_default_ =
"Norm of Preconditioned Initial Residual";
538 template<
class ScalarType,
class MV,
class OP>
539 const std::string PseudoBlockGmresSolMgr<ScalarType,MV,OP>::expResScale_default_ =
"Norm of Initial Residual";
541 template<
class ScalarType,
class MV,
class OP>
542 const std::string PseudoBlockGmresSolMgr<ScalarType,MV,OP>::label_default_ =
"Belos";
544 template<
class ScalarType,
class MV,
class OP>
545 const std::string PseudoBlockGmresSolMgr<ScalarType,MV,OP>::orthoType_default_ =
"DGKS";
547 template<
class ScalarType,
class MV,
class OP>
552 template<
class ScalarType,
class MV,
class OP>
554 outputStream_(outputStream_default_),
555 convtol_(convtol_default_),
556 orthoKappa_(orthoKappa_default_),
557 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
558 maxRestarts_(maxRestarts_default_),
559 maxIters_(maxIters_default_),
561 blockSize_(blockSize_default_),
562 numBlocks_(numBlocks_default_),
563 verbosity_(verbosity_default_),
564 outputStyle_(outputStyle_default_),
565 outputFreq_(outputFreq_default_),
566 defQuorum_(defQuorum_default_),
567 showMaxResNormOnly_(showMaxResNormOnly_default_),
568 orthoType_(orthoType_default_),
569 impResScale_(impResScale_default_),
570 expResScale_(expResScale_default_),
571 label_(label_default_),
579 template<
class ScalarType,
class MV,
class OP>
584 outputStream_(outputStream_default_),
585 convtol_(convtol_default_),
586 orthoKappa_(orthoKappa_default_),
587 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
588 maxRestarts_(maxRestarts_default_),
589 maxIters_(maxIters_default_),
591 blockSize_(blockSize_default_),
592 numBlocks_(numBlocks_default_),
593 verbosity_(verbosity_default_),
594 outputStyle_(outputStyle_default_),
595 outputFreq_(outputFreq_default_),
596 defQuorum_(defQuorum_default_),
597 showMaxResNormOnly_(showMaxResNormOnly_default_),
598 orthoType_(orthoType_default_),
599 impResScale_(impResScale_default_),
600 expResScale_(expResScale_default_),
601 label_(label_default_),
616 template<
class ScalarType,
class MV,
class OP>
622 using Teuchos::parameterList;
624 using Teuchos::rcp_dynamic_cast;
627 if (params_ == Teuchos::null) {
628 params_ = parameterList (*getValidParameters ());
635 maxRestarts_ = params->
get (
"Maximum Restarts", maxRestarts_default_);
638 params_->set (
"Maximum Restarts", maxRestarts_);
643 maxIters_ = params->
get (
"Maximum Iterations", maxIters_default_);
646 params_->set (
"Maximum Iterations", maxIters_);
647 if (! maxIterTest_.is_null ()) {
648 maxIterTest_->setMaxIters (maxIters_);
654 blockSize_ = params->
get (
"Block Size", blockSize_default_);
656 blockSize_ <= 0, std::invalid_argument,
657 "Belos::PseudoBlockGmresSolMgr::setParameters: "
658 "The \"Block Size\" parameter must be strictly positive, "
659 "but you specified a value of " << blockSize_ <<
".");
662 params_->set (
"Block Size", blockSize_);
667 numBlocks_ = params->
get (
"Num Blocks", numBlocks_default_);
669 numBlocks_ <= 0, std::invalid_argument,
670 "Belos::PseudoBlockGmresSolMgr::setParameters: "
671 "The \"Num Blocks\" parameter must be strictly positive, "
672 "but you specified a value of " << numBlocks_ <<
".");
675 params_->set (
"Num Blocks", numBlocks_);
680 const std::string tempLabel = params->
get (
"Timer Label", label_default_);
683 if (tempLabel != label_) {
685 params_->set (
"Timer Label", label_);
686 const std::string solveLabel =
687 label_ +
": PseudoBlockGmresSolMgr total solve time";
688 #ifdef BELOS_TEUCHOS_TIME_MONITOR
690 #endif // BELOS_TEUCHOS_TIME_MONITOR
691 if (ortho_ != Teuchos::null) {
692 ortho_->setLabel( label_ );
699 std::string tempOrthoType = params->
get (
"Orthogonalization", orthoType_default_);
700 #ifdef HAVE_BELOS_TSQR
702 tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" &&
703 tempOrthoType !=
"IMGS" && tempOrthoType !=
"TSQR",
704 std::invalid_argument,
705 "Belos::PseudoBlockGmresSolMgr::setParameters: "
706 "The \"Orthogonalization\" parameter must be one of \"DGKS\", \"ICGS\", "
707 "\"IMGS\", or \"TSQR\".");
710 tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" &&
711 tempOrthoType !=
"IMGS",
712 std::invalid_argument,
713 "Belos::PseudoBlockGmresSolMgr::setParameters: "
714 "The \"Orthogonalization\" parameter must be one of \"DGKS\", \"ICGS\", "
716 #endif // HAVE_BELOS_TSQR
718 if (tempOrthoType != orthoType_) {
719 orthoType_ = tempOrthoType;
721 if (orthoType_ ==
"DGKS") {
723 if (orthoKappa_ <= 0) {
724 ortho_ =
rcp (
new ortho_type (label_));
727 ortho_ =
rcp (
new ortho_type (label_));
728 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
731 else if (orthoType_ ==
"ICGS") {
733 ortho_ =
rcp (
new ortho_type (label_));
735 else if (orthoType_ ==
"IMGS") {
737 ortho_ =
rcp (
new ortho_type (label_));
739 #ifdef HAVE_BELOS_TSQR
740 else if (orthoType_ ==
"TSQR") {
742 ortho_ =
rcp (
new ortho_type (label_));
744 #endif // HAVE_BELOS_TSQR
749 if (params->
isParameter (
"Orthogonalization Constant")) {
750 orthoKappa_ = params->
get (
"Orthogonalization Constant", orthoKappa_default_);
753 params_->set (
"Orthogonalization Constant", orthoKappa_);
754 if (orthoType_ ==
"DGKS") {
755 if (orthoKappa_ > 0 && ! ortho_.is_null ()) {
757 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
764 if (Teuchos::isParameterType<int> (*params,
"Verbosity")) {
765 verbosity_ = params->
get (
"Verbosity", verbosity_default_);
767 verbosity_ = (int) Teuchos::getParameter<Belos::MsgType> (*params,
"Verbosity");
771 params_->set (
"Verbosity", verbosity_);
772 if (! printer_.is_null ()) {
773 printer_->setVerbosity (verbosity_);
779 if (Teuchos::isParameterType<int> (*params,
"Output Style")) {
780 outputStyle_ = params->
get (
"Output Style", outputStyle_default_);
782 outputStyle_ = (int) Teuchos::getParameter<Belos::OutputType> (*params,
"Output Style");
786 params_->set (
"Output Style", verbosity_);
787 if (! outputTest_.is_null ()) {
794 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> > (*params,
"Output Stream");
797 params_->set(
"Output Stream", outputStream_);
798 if (! printer_.is_null ()) {
799 printer_->setOStream (outputStream_);
806 outputFreq_ = params->
get (
"Output Frequency", outputFreq_default_);
810 params_->set (
"Output Frequency", outputFreq_);
811 if (! outputTest_.is_null ()) {
812 outputTest_->setOutputFrequency (outputFreq_);
817 if (printer_.is_null ()) {
824 if (params->
isParameter (
"Convergence Tolerance")) {
825 convtol_ = params->
get (
"Convergence Tolerance", convtol_default_);
828 params_->set (
"Convergence Tolerance", convtol_);
829 if (! impConvTest_.is_null ()) {
830 impConvTest_->setTolerance (convtol_);
832 if (! expConvTest_.is_null ()) {
833 expConvTest_->setTolerance (convtol_);
838 if (params->
isParameter (
"Implicit Residual Scaling")) {
839 const std::string tempImpResScale =
840 Teuchos::getParameter<std::string> (*params,
"Implicit Residual Scaling");
843 if (impResScale_ != tempImpResScale) {
845 impResScale_ = tempImpResScale;
848 params_->set (
"Implicit Residual Scaling", impResScale_);
849 if (! impConvTest_.is_null ()) {
853 catch (std::exception& e) {
861 if (params->
isParameter (
"Explicit Residual Scaling")) {
862 const std::string tempExpResScale =
863 Teuchos::getParameter<std::string> (*params,
"Explicit Residual Scaling");
866 if (expResScale_ != tempExpResScale) {
868 expResScale_ = tempExpResScale;
871 params_->set (
"Explicit Residual Scaling", expResScale_);
872 if (! expConvTest_.is_null ()) {
876 catch (std::exception& e) {
885 if (params->
isParameter (
"Show Maximum Residual Norm Only")) {
886 showMaxResNormOnly_ =
887 Teuchos::getParameter<bool> (*params,
"Show Maximum Residual Norm Only");
890 params_->set (
"Show Maximum Residual Norm Only", showMaxResNormOnly_);
891 if (! impConvTest_.is_null ()) {
892 impConvTest_->setShowMaxResNormOnly (showMaxResNormOnly_);
894 if (! expConvTest_.is_null ()) {
895 expConvTest_->setShowMaxResNormOnly (showMaxResNormOnly_);
903 defQuorum_ = params->
get(
"Deflation Quorum", defQuorum_);
905 defQuorum_ > blockSize_, std::invalid_argument,
906 "Belos::PseudoBlockGmresSolMgr::setParameters: "
907 "The \"Deflation Quorum\" parameter (= " << defQuorum_ <<
") must not be "
908 "larger than \"Block Size\" (= " << blockSize_ <<
").");
909 params_->set (
"Deflation Quorum", defQuorum_);
910 if (! impConvTest_.is_null ()) {
911 impConvTest_->setQuorum (defQuorum_);
913 if (! expConvTest_.is_null ()) {
914 expConvTest_->setQuorum (defQuorum_);
919 if (ortho_.is_null ()) {
920 if (orthoType_ ==
"DGKS") {
922 if (orthoKappa_ <= 0) {
923 ortho_ =
rcp (
new ortho_type (label_));
926 ortho_ =
rcp (
new ortho_type (label_));
927 rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
930 else if (orthoType_ ==
"ICGS") {
932 ortho_ =
rcp (
new ortho_type (label_));
934 else if (orthoType_ ==
"IMGS") {
936 ortho_ =
rcp (
new ortho_type (label_));
938 #ifdef HAVE_BELOS_TSQR
939 else if (orthoType_ ==
"TSQR") {
941 ortho_ =
rcp (
new ortho_type (label_));
943 #endif // HAVE_BELOS_TSQR
945 #ifdef HAVE_BELOS_TSQR
947 orthoType_ !=
"ICGS" && orthoType_ !=
"DGKS" &&
948 orthoType_ !=
"IMGS" && orthoType_ !=
"TSQR",
950 "Belos::PseudoBlockGmresSolMgr::setParameters(): "
951 "Invalid orthogonalization type \"" << orthoType_ <<
"\".");
954 orthoType_ !=
"ICGS" && orthoType_ !=
"DGKS" &&
955 orthoType_ !=
"IMGS",
957 "Belos::PseudoBlockGmresSolMgr::setParameters(): "
958 "Invalid orthogonalization type \"" << orthoType_ <<
"\".");
959 #endif // HAVE_BELOS_TSQR
964 if (timerSolve_ == Teuchos::null) {
965 std::string solveLabel = label_ +
": PseudoBlockGmresSolMgr total solve time";
966 #ifdef BELOS_TEUCHOS_TIME_MONITOR
976 template<
class ScalarType,
class MV,
class OP>
982 userConvStatusTest_ = userConvStatusTest;
986 template<
class ScalarType,
class MV,
class OP>
995 pl->
set(
"Convergence Tolerance", convtol_default_,
996 "The relative residual tolerance that needs to be achieved by the\n"
997 "iterative solver in order for the linear system to be declared converged.");
998 pl->
set(
"Maximum Restarts", maxRestarts_default_,
999 "The maximum number of restarts allowed for each\n"
1000 "set of RHS solved.");
1001 pl->
set(
"Maximum Iterations", maxIters_default_,
1002 "The maximum number of block iterations allowed for each\n"
1003 "set of RHS solved.");
1004 pl->
set(
"Num Blocks", numBlocks_default_,
1005 "The maximum number of vectors allowed in the Krylov subspace\n"
1006 "for each set of RHS solved.");
1007 pl->
set(
"Block Size", blockSize_default_,
1008 "The number of RHS solved simultaneously.");
1009 pl->
set(
"Verbosity", verbosity_default_,
1010 "What type(s) of solver information should be outputted\n"
1011 "to the output stream.");
1012 pl->
set(
"Output Style", outputStyle_default_,
1013 "What style is used for the solver information outputted\n"
1014 "to the output stream.");
1015 pl->
set(
"Output Frequency", outputFreq_default_,
1016 "How often convergence information should be outputted\n"
1017 "to the output stream.");
1018 pl->
set(
"Deflation Quorum", defQuorum_default_,
1019 "The number of linear systems that need to converge before\n"
1020 "they are deflated. This number should be <= block size.");
1021 pl->
set(
"Output Stream", outputStream_default_,
1022 "A reference-counted pointer to the output stream where all\n"
1023 "solver output is sent.");
1024 pl->
set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
1025 "When convergence information is printed, only show the maximum\n"
1026 "relative residual norm when the block size is greater than one.");
1027 pl->
set(
"Implicit Residual Scaling", impResScale_default_,
1028 "The type of scaling used in the implicit residual convergence test.");
1029 pl->
set(
"Explicit Residual Scaling", expResScale_default_,
1030 "The type of scaling used in the explicit residual convergence test.");
1031 pl->
set(
"Timer Label", label_default_,
1032 "The string to use as a prefix for the timer labels.");
1034 pl->
set(
"Orthogonalization", orthoType_default_,
1035 "The type of orthogonalization to use: DGKS, ICGS, IMGS.");
1036 pl->
set(
"Orthogonalization Constant",orthoKappa_default_,
1037 "The constant used by DGKS orthogonalization to determine\n"
1038 "whether another step of classical Gram-Schmidt is necessary.");
1045 template<
class ScalarType,
class MV,
class OP>
1065 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
1067 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1068 impConvTest_ = tmpImpConvTest;
1072 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
1073 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
1075 tmpExpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1076 expConvTest_ = tmpExpConvTest;
1079 convTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
1086 Teuchos::rcp(
new StatusTestImpResNorm_t( convtol_, defQuorum_ ) );
1088 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1089 impConvTest_ = tmpImpConvTest;
1092 expConvTest_ = impConvTest_;
1093 convTest_ = impConvTest_;
1096 if (
nonnull(userConvStatusTest_) ) {
1099 new StatusTestCombo_t( StatusTestCombo_t::SEQ, convTest_, userConvStatusTest_ ) );
1104 sTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
1108 StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
1112 std::string solverDesc =
" Pseudo Block Gmres ";
1113 outputTest_->setSolverDesc( solverDesc );
1124 template<
class ScalarType,
class MV,
class OP>
1130 if (!isSet_) { setParameters( params_ ); }
1135 "Belos::PseudoBlockGmresSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
1138 if (!isSTSet_ || (!expResTest_ && !
Teuchos::is_null(problem_->getLeftPrec())) ) {
1140 "Belos::BlockGmresSolMgr::solve(): Linear problem and requested status tests are incompatible.");
1145 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
1146 int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1148 std::vector<int> currIdx( numCurrRHS );
1149 blockSize_ = numCurrRHS;
1150 for (
int i=0; i<numCurrRHS; ++i)
1151 { currIdx[i] = startPtr+i; }
1154 problem_->setLSIndex( currIdx );
1159 plist.
set(
"Num Blocks",numBlocks_);
1162 outputTest_->reset();
1163 loaDetected_ =
false;
1166 bool isConverged =
true;
1176 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1180 while ( numRHS2Solve > 0 ) {
1183 std::vector<int> convRHSIdx;
1184 std::vector<int> currRHSIdx( currIdx );
1185 currRHSIdx.resize(numCurrRHS);
1188 block_gmres_iter->setNumBlocks( numBlocks_ );
1191 block_gmres_iter->resetNumIters();
1194 outputTest_->resetNumCalls();
1200 std::vector<int> index(1);
1201 Teuchos::RCP<MV> tmpV, R_0 = MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1202 newState.
V.resize( blockSize_ );
1203 newState.
Z.resize( blockSize_ );
1204 for (
int i=0; i<blockSize_; ++i) {
1206 tmpV = MVT::CloneViewNonConst( *R_0, index );
1213 int rank = ortho_->normalize( *tmpV, tmpZ );
1215 "Belos::PseudoBlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors.");
1217 newState.
V[i] = tmpV;
1218 newState.
Z[i] = tmpZ;
1222 block_gmres_iter->initialize(newState);
1223 int numRestarts = 0;
1229 block_gmres_iter->iterate();
1236 if ( convTest_->getStatus() ==
Passed ) {
1238 if ( expConvTest_->getLOADetected() ) {
1248 loaDetected_ =
true;
1250 "Belos::PseudoBlockGmresSolMgr::solve(): Warning! Solver has experienced a loss of accuracy!" << std::endl;
1251 isConverged =
false;
1255 std::vector<int> convIdx = expConvTest_->convIndices();
1259 if (convIdx.size() == currRHSIdx.size())
1266 problem_->setCurrLS();
1270 int curDim = oldState.
curDim;
1275 std::vector<int> oldRHSIdx( currRHSIdx );
1276 std::vector<int> defRHSIdx;
1277 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
1279 for (
unsigned int j=0; j<convIdx.size(); ++j) {
1280 if (currRHSIdx[i] == convIdx[j]) {
1286 defRHSIdx.push_back( i );
1289 defState.
V.push_back( Teuchos::rcp_const_cast<MV>( oldState.
V[i] ) );
1294 currRHSIdx[have] = currRHSIdx[i];
1298 defRHSIdx.resize(currRHSIdx.size()-have);
1299 currRHSIdx.resize(have);
1307 problem_->setLSIndex( convIdx );
1310 problem_->updateSolution( defUpdate,
true );
1314 problem_->setLSIndex( currRHSIdx );
1317 defState.
curDim = curDim;
1320 block_gmres_iter->initialize(defState);
1327 else if ( maxIterTest_->getStatus() ==
Passed ) {
1329 isConverged =
false;
1337 else if ( block_gmres_iter->getCurSubspaceDim() == block_gmres_iter->getMaxSubspaceDim() ) {
1339 if ( numRestarts >= maxRestarts_ ) {
1340 isConverged =
false;
1345 printer_->stream(
Debug) <<
" Performing restart number " << numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
1349 problem_->updateSolution( update,
true );
1356 newstate.
V.resize(currRHSIdx.size());
1357 newstate.
Z.resize(currRHSIdx.size());
1361 R_0 = MVT::Clone( *(problem_->getInitPrecResVec()), currRHSIdx.size() );
1362 problem_->computeCurrPrecResVec( &*R_0 );
1363 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
1366 tmpV = MVT::CloneViewNonConst( *R_0, index );
1373 int rank = ortho_->normalize( *tmpV, tmpZ );
1375 "Belos::PseudoBlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors after the restart.");
1377 newstate.
V[i] = tmpV;
1378 newstate.
Z[i] = tmpZ;
1383 block_gmres_iter->initialize(newstate);
1396 "Belos::PseudoBlockGmresSolMgr::solve(): Invalid return from PseudoBlockGmresIter::iterate().");
1402 block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
1405 sTest_->checkStatus( &*block_gmres_iter );
1406 if (convTest_->getStatus() !=
Passed)
1407 isConverged =
false;
1410 catch (
const std::exception &e) {
1411 printer_->stream(
Errors) <<
"Error! Caught std::exception in PseudoBlockGmresIter::iterate() at iteration "
1412 << block_gmres_iter->getNumIters() << std::endl
1413 << e.what() << std::endl;
1420 if (
nonnull(userConvStatusTest_)) {
1423 problem_->updateSolution( update,
true );
1425 else if (
nonnull(expConvTest_->getSolution())) {
1429 MVT::MvAddMv( 0.0, *newX, 1.0, *newX, *curX );
1434 problem_->updateSolution( update,
true );
1438 problem_->setCurrLS();
1441 startPtr += numCurrRHS;
1442 numRHS2Solve -= numCurrRHS;
1443 if ( numRHS2Solve > 0 ) {
1444 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1446 blockSize_ = numCurrRHS;
1447 currIdx.resize( numCurrRHS );
1448 for (
int i=0; i<numCurrRHS; ++i)
1449 { currIdx[i] = startPtr+i; }
1452 if (defQuorum_ > blockSize_) {
1453 if (impConvTest_ != Teuchos::null)
1454 impConvTest_->setQuorum( blockSize_ );
1455 if (expConvTest_ != Teuchos::null)
1456 expConvTest_->setQuorum( blockSize_ );
1460 problem_->setLSIndex( currIdx );
1463 currIdx.resize( numRHS2Solve );
1474 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1483 numIters_ = maxIterTest_->getNumIters();
1496 const std::vector<MagnitudeType>* pTestValues = NULL;
1498 pTestValues = expConvTest_->getTestValue();
1499 if (pTestValues == NULL || pTestValues->size() < 1) {
1500 pTestValues = impConvTest_->getTestValue();
1505 pTestValues = impConvTest_->getTestValue();
1508 "Belos::PseudoBlockGmresSolMgr::solve(): The implicit convergence test's "
1509 "getTestValue() method returned NULL. Please report this bug to the "
1510 "Belos developers.");
1512 "Belos::PseudoBlockGmresSolMgr::solve(): The implicit convergence test's "
1513 "getTestValue() method returned a vector of length zero. Please report "
1514 "this bug to the Belos developers.");
1519 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1522 if (!isConverged || loaDetected_) {
1529 template<
class ScalarType,
class MV,
class OP>
1532 std::ostringstream oss;
1535 oss <<
"Ortho Type='"<<orthoType_<<
"\', Block Size=" <<blockSize_;
1536 oss <<
", Num Blocks="<<numBlocks_<<
", Max Restarts=" << maxRestarts_;
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.
bool is_null(const boost::shared_ptr< T > &p)
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...
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)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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.
static std::string name()
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.
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="")
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
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. ...
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.
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.
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 ...
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 ...
bool nonnull(const boost::shared_ptr< T > &p)
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.
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 ...
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 description of the pseudoblock GMRES solver manager.
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...