42 #ifndef BELOS_GMRES_POLY_SOLMGR_HPP 43 #define BELOS_GMRES_POLY_SOLMGR_HPP 67 #include "Teuchos_BLAS.hpp" 68 #include "Teuchos_LAPACK.hpp" 69 #include "Teuchos_as.hpp" 70 #ifdef BELOS_TEUCHOS_TIME_MONITOR 71 #include "Teuchos_TimeMonitor.hpp" 122 template<
class ScalarType,
class MV,
class OP>
129 typedef Teuchos::ScalarTraits<ScalarType> SCT;
130 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
131 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
159 const Teuchos::RCP<Teuchos::ParameterList> &pl );
176 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const;
187 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
188 return Teuchos::tuple(timerSolve_, timerPoly_);
210 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms );
222 problem_->setProblem();
223 isPolyBuilt_ =
false;
256 std::string description()
const;
263 bool checkStatusTest();
269 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
272 Teuchos::RCP<OutputManager<ScalarType> > printer_;
273 Teuchos::RCP<std::ostream> outputStream_;
276 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
277 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
278 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
279 Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > expConvTest_, impConvTest_;
280 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
283 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > ortho_;
286 Teuchos::RCP<Teuchos::ParameterList> params_;
289 static const MagnitudeType polytol_default_;
290 static const MagnitudeType convtol_default_;
291 static const MagnitudeType orthoKappa_default_;
292 static const int maxDegree_default_;
293 static const int maxRestarts_default_;
294 static const int maxIters_default_;
295 static const bool strictConvTol_default_;
296 static const bool showMaxResNormOnly_default_;
297 static const int blockSize_default_;
298 static const int numBlocks_default_;
299 static const int verbosity_default_;
300 static const int outputStyle_default_;
301 static const int outputFreq_default_;
302 static const std::string impResScale_default_;
303 static const std::string expResScale_default_;
304 static const std::string label_default_;
305 static const std::string orthoType_default_;
306 static const Teuchos::RCP<std::ostream> outputStream_default_;
309 MagnitudeType polytol_, convtol_, orthoKappa_;
310 int maxDegree_, maxRestarts_, maxIters_, numIters_;
311 int blockSize_, numBlocks_, verbosity_, outputStyle_, outputFreq_;
312 bool strictConvTol_, showMaxResNormOnly_;
313 std::string orthoType_;
314 std::string impResScale_, expResScale_;
318 Teuchos::RCP<Teuchos::SerialDenseMatrix<int, ScalarType> > poly_H_, poly_y_;
319 Teuchos::RCP<Teuchos::SerialDenseVector<int, ScalarType> > poly_r0_;
320 Teuchos::RCP<Belos::GmresPolyOp<ScalarType, MV, OP> > poly_Op_;
324 Teuchos::RCP<Teuchos::Time> timerSolve_, timerPoly_;
328 bool isSet_, isSTSet_, expResTest_;
334 template<
class ScalarType,
class MV,
class OP>
337 template<
class ScalarType,
class MV,
class OP>
340 template<
class ScalarType,
class MV,
class OP>
343 template<
class ScalarType,
class MV,
class OP>
346 template<
class ScalarType,
class MV,
class OP>
349 template<
class ScalarType,
class MV,
class OP>
352 template<
class ScalarType,
class MV,
class OP>
355 template<
class ScalarType,
class MV,
class OP>
358 template<
class ScalarType,
class MV,
class OP>
361 template<
class ScalarType,
class MV,
class OP>
364 template<
class ScalarType,
class MV,
class OP>
367 template<
class ScalarType,
class MV,
class OP>
370 template<
class ScalarType,
class MV,
class OP>
373 template<
class ScalarType,
class MV,
class OP>
376 template<
class ScalarType,
class MV,
class OP>
379 template<
class ScalarType,
class MV,
class OP>
382 template<
class ScalarType,
class MV,
class OP>
385 template<
class ScalarType,
class MV,
class OP>
390 template<
class ScalarType,
class MV,
class OP>
392 outputStream_(outputStream_default_),
393 polytol_(polytol_default_),
394 convtol_(convtol_default_),
395 orthoKappa_(orthoKappa_default_),
396 maxDegree_(maxDegree_default_),
397 maxRestarts_(maxRestarts_default_),
398 maxIters_(maxIters_default_),
399 blockSize_(blockSize_default_),
400 numBlocks_(numBlocks_default_),
401 verbosity_(verbosity_default_),
402 outputStyle_(outputStyle_default_),
403 outputFreq_(outputFreq_default_),
404 strictConvTol_(strictConvTol_default_),
405 showMaxResNormOnly_(showMaxResNormOnly_default_),
406 orthoType_(orthoType_default_),
407 impResScale_(impResScale_default_),
408 expResScale_(expResScale_default_),
409 label_(label_default_),
419 template<
class ScalarType,
class MV,
class OP>
422 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
424 outputStream_(outputStream_default_),
425 polytol_(polytol_default_),
426 convtol_(convtol_default_),
427 orthoKappa_(orthoKappa_default_),
428 maxDegree_(maxDegree_default_),
429 maxRestarts_(maxRestarts_default_),
430 maxIters_(maxIters_default_),
431 blockSize_(blockSize_default_),
432 numBlocks_(numBlocks_default_),
433 verbosity_(verbosity_default_),
434 outputStyle_(outputStyle_default_),
435 outputFreq_(outputFreq_default_),
436 strictConvTol_(strictConvTol_default_),
437 showMaxResNormOnly_(showMaxResNormOnly_default_),
438 orthoType_(orthoType_default_),
439 impResScale_(impResScale_default_),
440 expResScale_(expResScale_default_),
441 label_(label_default_),
449 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager.");
452 if ( !is_null(pl) ) {
459 template<
class ScalarType,
class MV,
class OP>
460 Teuchos::RCP<const Teuchos::ParameterList>
463 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
464 if (is_null(validPL)) {
465 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
466 pl->set(
"Polynomial Tolerance", polytol_default_,
467 "The relative residual tolerance that used to construct the GMRES polynomial.");
468 pl->set(
"Maximum Degree", maxDegree_default_,
469 "The maximum degree allowed for any GMRES polynomial.");
470 pl->set(
"Convergence Tolerance", convtol_default_,
471 "The relative residual tolerance that needs to be achieved by the\n" 472 "iterative solver in order for the linear system to be declared converged." );
473 pl->set(
"Maximum Restarts", maxRestarts_default_,
474 "The maximum number of restarts allowed for each\n" 475 "set of RHS solved.");
476 pl->set(
"Maximum Iterations", maxIters_default_,
477 "The maximum number of block iterations allowed for each\n" 478 "set of RHS solved.");
479 pl->set(
"Num Blocks", numBlocks_default_,
480 "The maximum number of blocks allowed in the Krylov subspace\n" 481 "for each set of RHS solved.");
482 pl->set(
"Block Size", blockSize_default_,
483 "The number of vectors in each block. This number times the\n" 484 "number of blocks is the total Krylov subspace dimension.");
485 pl->set(
"Verbosity", verbosity_default_,
486 "What type(s) of solver information should be outputted\n" 487 "to the output stream.");
488 pl->set(
"Output Style", outputStyle_default_,
489 "What style is used for the solver information outputted\n" 490 "to the output stream.");
491 pl->set(
"Output Frequency", outputFreq_default_,
492 "How often convergence information should be outputted\n" 493 "to the output stream.");
494 pl->set(
"Output Stream", outputStream_default_,
495 "A reference-counted pointer to the output stream where all\n" 496 "solver output is sent.");
497 pl->set(
"Strict Convergence", strictConvTol_default_,
498 "After polynomial is applied, whether solver should try to achieve\n" 499 "the relative residual tolerance.");
500 pl->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
501 "When convergence information is printed, only show the maximum\n" 502 "relative residual norm when the block size is greater than one.");
503 pl->set(
"Implicit Residual Scaling", impResScale_default_,
504 "The type of scaling used in the implicit residual convergence test.");
505 pl->set(
"Explicit Residual Scaling", expResScale_default_,
506 "The type of scaling used in the explicit residual convergence test.");
507 pl->set(
"Timer Label", label_default_,
508 "The string to use as a prefix for the timer labels.");
510 pl->set(
"Orthogonalization", orthoType_default_,
511 "The type of orthogonalization to use: DGKS, ICGS, or IMGS.");
512 pl->set(
"Orthogonalization Constant",orthoKappa_default_,
513 "The constant used by DGKS orthogonalization to determine\n" 514 "whether another step of classical Gram-Schmidt is necessary.");
521 template<
class ScalarType,
class MV,
class OP>
526 if (params_ == Teuchos::null) {
534 if (params->isParameter(
"Maximum Degree")) {
535 maxDegree_ = params->get(
"Maximum Degree",maxDegree_default_);
538 params_->set(
"Maximum Degree", maxDegree_);
542 if (params->isParameter(
"Maximum Restarts")) {
543 maxRestarts_ = params->get(
"Maximum Restarts",maxRestarts_default_);
546 params_->set(
"Maximum Restarts", maxRestarts_);
550 if (params->isParameter(
"Maximum Iterations")) {
551 maxIters_ = params->get(
"Maximum Iterations",maxIters_default_);
554 params_->set(
"Maximum Iterations", maxIters_);
555 if (maxIterTest_!=Teuchos::null)
556 maxIterTest_->setMaxIters( maxIters_ );
560 if (params->isParameter(
"Block Size")) {
561 blockSize_ = params->get(
"Block Size",blockSize_default_);
562 TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ <= 0, std::invalid_argument,
563 "Belos::GmresPolySolMgr: \"Block Size\" must be strictly positive.");
566 params_->set(
"Block Size", blockSize_);
570 if (params->isParameter(
"Num Blocks")) {
571 numBlocks_ = params->get(
"Num Blocks",numBlocks_default_);
572 TEUCHOS_TEST_FOR_EXCEPTION(numBlocks_ <= 0, std::invalid_argument,
573 "Belos::GmresPolySolMgr: \"Num Blocks\" must be strictly positive.");
576 params_->set(
"Num Blocks", numBlocks_);
580 if (params->isParameter(
"Timer Label")) {
581 std::string tempLabel = params->get(
"Timer Label", label_default_);
584 if (tempLabel != label_) {
586 params_->set(
"Timer Label", label_);
587 std::string solveLabel = label_ +
": GmresPolySolMgr total solve time";
588 #ifdef BELOS_TEUCHOS_TIME_MONITOR 589 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
591 std::string polyLabel = label_ +
": GmresPolySolMgr polynomial creation time";
592 #ifdef BELOS_TEUCHOS_TIME_MONITOR 593 timerPoly_ = Teuchos::TimeMonitor::getNewCounter(polyLabel);
595 if (ortho_ != Teuchos::null) {
596 ortho_->setLabel( label_ );
602 if (params->isParameter(
"Orthogonalization")) {
603 std::string tempOrthoType = params->get(
"Orthogonalization",orthoType_default_);
604 TEUCHOS_TEST_FOR_EXCEPTION( tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" && tempOrthoType !=
"IMGS",
605 std::invalid_argument,
606 "Belos::GmresPolySolMgr: \"Orthogonalization\" must be either \"DGKS\", \"ICGS\", or \"IMGS\".");
607 if (tempOrthoType != orthoType_) {
608 orthoType_ = tempOrthoType;
610 if (orthoType_==
"DGKS") {
611 if (orthoKappa_ <= 0) {
619 else if (orthoType_==
"ICGS") {
622 else if (orthoType_==
"IMGS") {
629 if (params->isParameter(
"Orthogonalization Constant")) {
630 orthoKappa_ = params->get(
"Orthogonalization Constant",orthoKappa_default_);
633 params_->set(
"Orthogonalization Constant",orthoKappa_);
634 if (orthoType_==
"DGKS") {
635 if (orthoKappa_ > 0 && ortho_ != Teuchos::null) {
642 if (params->isParameter(
"Verbosity")) {
643 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
644 verbosity_ = params->get(
"Verbosity", verbosity_default_);
646 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
650 params_->set(
"Verbosity", verbosity_);
651 if (printer_ != Teuchos::null)
652 printer_->setVerbosity(verbosity_);
656 if (params->isParameter(
"Output Style")) {
657 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
658 outputStyle_ = params->get(
"Output Style", outputStyle_default_);
660 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
664 params_->set(
"Output Style", outputStyle_);
665 if (outputTest_ != Teuchos::null) {
671 if (params->isParameter(
"Output Stream")) {
672 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
675 params_->set(
"Output Stream", outputStream_);
676 if (printer_ != Teuchos::null)
677 printer_->setOStream( outputStream_ );
682 if (params->isParameter(
"Output Frequency")) {
683 outputFreq_ = params->get(
"Output Frequency", outputFreq_default_);
687 params_->set(
"Output Frequency", outputFreq_);
688 if (outputTest_ != Teuchos::null)
689 outputTest_->setOutputFrequency( outputFreq_ );
693 if (printer_ == Teuchos::null) {
702 if (params->isParameter(
"Polynomial Tolerance")) {
703 polytol_ = params->get(
"Polynomial Tolerance",polytol_default_);
706 params_->set(
"Polynomial Tolerance", polytol_);
710 if (params->isParameter(
"Convergence Tolerance")) {
711 convtol_ = params->get(
"Convergence Tolerance",convtol_default_);
714 params_->set(
"Convergence Tolerance", convtol_);
715 if (impConvTest_ != Teuchos::null)
716 impConvTest_->setTolerance( convtol_ );
717 if (expConvTest_ != Teuchos::null)
718 expConvTest_->setTolerance( convtol_ );
722 if (params->isParameter(
"Strict Convergence")) {
723 strictConvTol_ = params->get(
"Strict Convergence",strictConvTol_default_);
726 params_->set(
"Strict Convergence", strictConvTol_);
730 if (params->isParameter(
"Implicit Residual Scaling")) {
731 std::string tempImpResScale = Teuchos::getParameter<std::string>( *params,
"Implicit Residual Scaling" );
734 if (impResScale_ != tempImpResScale) {
736 impResScale_ = tempImpResScale;
739 params_->set(
"Implicit Residual Scaling", impResScale_);
740 if (impConvTest_ != Teuchos::null) {
744 catch (std::exception& e) {
752 if (params->isParameter(
"Explicit Residual Scaling")) {
753 std::string tempExpResScale = Teuchos::getParameter<std::string>( *params,
"Explicit Residual Scaling" );
756 if (expResScale_ != tempExpResScale) {
758 expResScale_ = tempExpResScale;
761 params_->set(
"Explicit Residual Scaling", expResScale_);
762 if (expConvTest_ != Teuchos::null) {
766 catch (std::exception& e) {
775 if (params->isParameter(
"Show Maximum Residual Norm Only")) {
776 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,
"Show Maximum Residual Norm Only");
779 params_->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_);
780 if (impConvTest_ != Teuchos::null)
781 impConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
782 if (expConvTest_ != Teuchos::null)
783 expConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
787 if (ortho_ == Teuchos::null) {
788 if (orthoType_==
"DGKS") {
789 if (orthoKappa_ <= 0) {
797 else if (orthoType_==
"ICGS") {
800 else if (orthoType_==
"IMGS") {
804 TEUCHOS_TEST_FOR_EXCEPTION(orthoType_!=
"ICGS"&&orthoType_!=
"DGKS"&&orthoType_!=
"IMGS",std::logic_error,
805 "Belos::GmresPolySolMgr(): Invalid orthogonalization type.");
810 if (timerSolve_ == Teuchos::null) {
811 std::string solveLabel = label_ +
": GmresPolySolMgr total solve time";
812 #ifdef BELOS_TEUCHOS_TIME_MONITOR 813 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
817 if (timerPoly_ == Teuchos::null) {
818 std::string polyLabel = label_ +
": GmresPolySolMgr polynomial creation time";
819 #ifdef BELOS_TEUCHOS_TIME_MONITOR 820 timerPoly_ = Teuchos::TimeMonitor::getNewCounter(polyLabel);
829 template<
class ScalarType,
class MV,
class OP>
841 if (!Teuchos::is_null(problem_->getLeftPrec())) {
848 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
849 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_ ) );
851 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
852 impConvTest_ = tmpImpConvTest;
855 Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
856 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_ ) );
857 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
859 tmpExpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
860 expConvTest_ = tmpExpConvTest;
863 convTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
869 Teuchos::RCP<StatusTestImpResNorm_t> tmpImpConvTest =
870 Teuchos::rcp(
new StatusTestImpResNorm_t( convtol_ ) );
872 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
873 impConvTest_ = tmpImpConvTest;
876 expConvTest_ = impConvTest_;
877 convTest_ = impConvTest_;
880 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
888 std::string solverDesc =
" Gmres Polynomial ";
889 outputTest_->setSolverDesc( solverDesc );
898 template<
class ScalarType,
class MV,
class OP>
902 Teuchos::RCP<MV> newX =
MVT::Clone( *(problem_->getLHS()), 1 );
903 Teuchos::RCP<MV> newB =
MVT::Clone( *(problem_->getRHS()), 1 );
906 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > newProblem =
908 newProblem->setLeftPrec( problem_->getLeftPrec() );
909 newProblem->setRightPrec( problem_->getRightPrec() );
910 newProblem->setLabel(
"Belos GMRES Poly Generation");
911 newProblem->setProblem();
912 std::vector<int> idx(1,0);
913 newProblem->setLSIndex( idx );
916 Teuchos::ParameterList polyList;
919 polyList.set(
"Num Blocks",maxDegree_);
920 polyList.set(
"Block Size",1);
921 polyList.set(
"Keep Hessenberg",
true);
924 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxItrTst =
928 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > convTst =
933 Teuchos::RCP<StatusTestCombo<ScalarType,MV,OP> > polyTest =
937 Teuchos::RCP<BlockGmresIter<ScalarType,MV,OP> > gmres_iter;
941 Teuchos::RCP<MV> V_0 =
MVT::Clone( *(newProblem->getRHS()), 1 );
942 newProblem->computeCurrPrecResVec( &*V_0 );
945 poly_r0_ = Teuchos::rcp(
new Teuchos::SerialDenseVector<int,ScalarType>(1) );
948 int rank = ortho_->normalize( *V_0, poly_r0_ );
950 "Belos::GmresPolySolMgr::generatePoly(): Failed to compute initial block of orthonormal vectors for polynomial generation.");
955 newstate.
z = poly_r0_;
957 gmres_iter->initializeGmres(newstate);
960 bool polyConverged =
false;
962 gmres_iter->iterate();
965 if ( convTst->getStatus() ==
Passed ) {
967 polyConverged =
true;
972 gmres_iter->updateLSQR( gmres_iter->getCurSubspaceDim() );
975 polyTest->checkStatus( &*gmres_iter );
976 if (convTst->getStatus() ==
Passed)
977 polyConverged =
true;
979 catch (std::exception e) {
980 printer_->stream(
Errors) <<
"Error! Caught exception in BlockGmresIter::iterate() at iteration " 981 << gmres_iter->getNumIters() << std::endl
982 << e.what() << std::endl;
989 (void) polyConverged;
992 Teuchos::RCP<MV> currX = gmres_iter->getCurrentUpdate();
998 poly_dim_ = gmresState.
curDim;
999 if (poly_dim_ == 0) {
1005 poly_y_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::Copy, *gmresState.
z, poly_dim_, 1 ) );
1006 poly_H_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( *gmresState.
H ) );
1010 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1011 Teuchos::BLAS<int,ScalarType> blas;
1012 blas.TRSM( Teuchos::LEFT_SIDE, Teuchos::UPPER_TRI, Teuchos::NO_TRANS,
1013 Teuchos::NON_UNIT_DIAG, poly_dim_, 1, one,
1014 gmresState.
R->values(), gmresState.
R->stride(),
1015 poly_y_->values(), poly_y_->stride() );
1019 poly_Op_ = Teuchos::rcp(
1026 template<
class ScalarType,
class MV,
class OP>
1036 Teuchos::BLAS<int,ScalarType> blas;
1037 Teuchos::LAPACK<int,ScalarType> lapack;
1040 "Belos::GmresPolySolMgr::solve(): Linear problem is not a valid object.");
1043 "Belos::GmresPolySolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
1045 if (!isSTSet_ || (!expResTest_ && !Teuchos::is_null(problem_->getLeftPrec())) ) {
1047 "Belos::GmresPolySolMgr::solve(): Linear problem and requested status tests are incompatible.");
1051 if (!isPolyBuilt_) {
1052 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1053 Teuchos::TimeMonitor slvtimer(*timerPoly_);
1055 isPolyBuilt_ = generatePoly();
1057 "Belos::GmresPolySolMgr::generatePoly(): Failed to generate a non-trivial polynomial, reduce polynomial tolerance.");
1059 "Belos::GmresPolySolMgr::generatePoly(): Failed to generate polynomial that satisfied requirements.");
1063 bool isConverged =
true;
1067 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1068 Teuchos::TimeMonitor slvtimer(*timerSolve_);
1072 poly_Op_->Apply( *problem_->getRHS(), *problem_->getLHS() );
1075 problem_->setProblem();
1078 if (strictConvTol_) {
1083 int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1085 std::vector<int> currIdx;
1088 currIdx.resize( blockSize_ );
1089 for (
int i=0; i<numCurrRHS; ++i)
1090 { currIdx[i] = startPtr+i; }
1091 for (
int i=numCurrRHS; i<blockSize_; ++i)
1092 { currIdx[i] = -1; }
1095 problem_->setLSIndex( currIdx );
1099 Teuchos::ParameterList plist;
1100 plist.set(
"Block Size",blockSize_);
1103 if (blockSize_*static_cast<ptrdiff_t>(numBlocks_) > dim) {
1104 ptrdiff_t tmpNumBlocks = 0;
1105 if (blockSize_ == 1)
1106 tmpNumBlocks = dim / blockSize_;
1108 tmpNumBlocks = ( dim - blockSize_) / blockSize_;
1110 "Warning! Requested Krylov subspace dimension is larger than operator dimension!" << std::endl <<
1111 " The maximum number of blocks allowed for the Krylov subspace will be adjusted to " << tmpNumBlocks << std::endl;
1112 plist.set(
"Num Blocks",Teuchos::asSafe<int>(tmpNumBlocks));
1115 plist.set(
"Num Blocks",numBlocks_);
1118 outputTest_->reset();
1119 loaDetected_ =
false;
1127 Teuchos::RCP<GmresIteration<ScalarType,MV,OP> > block_gmres_iter;
1132 while ( numRHS2Solve > 0 ) {
1135 if (blockSize_*numBlocks_ > dim) {
1136 int tmpNumBlocks = 0;
1137 if (blockSize_ == 1)
1138 tmpNumBlocks = dim / blockSize_;
1140 tmpNumBlocks = ( dim - blockSize_) / blockSize_;
1141 block_gmres_iter->setSize( blockSize_, tmpNumBlocks );
1144 block_gmres_iter->setSize( blockSize_, numBlocks_ );
1147 block_gmres_iter->resetNumIters();
1150 outputTest_->resetNumCalls();
1153 Teuchos::RCP<MV> V_0;
1154 V_0 =
MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1158 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > z_0 =
1159 Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1162 int rank = ortho_->normalize( *V_0, z_0 );
1164 "Belos::GmresPolySolMgr::solve(): Failed to compute initial block of orthonormal vectors.");
1171 block_gmres_iter->initializeGmres(newstate);
1172 int numRestarts = 0;
1177 block_gmres_iter->iterate();
1184 if ( convTest_->getStatus() ==
Passed ) {
1185 if ( expConvTest_->getLOADetected() ) {
1187 loaDetected_ =
true;
1188 isConverged =
false;
1197 else if ( maxIterTest_->getStatus() ==
Passed ) {
1199 isConverged =
false;
1207 else if ( block_gmres_iter->getCurSubspaceDim() == block_gmres_iter->getMaxSubspaceDim() ) {
1209 if ( numRestarts >= maxRestarts_ ) {
1210 isConverged =
false;
1215 printer_->stream(
Debug) <<
" Performing restart number " << numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
1218 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1219 problem_->updateSolution( update,
true );
1226 Teuchos::RCP<MV> V_0 =
MVT::Clone( *(oldState.
V), blockSize_ );
1227 problem_->computeCurrPrecResVec( &*V_0 );
1230 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > z_0 =
1231 Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1234 int rank = ortho_->normalize( *V_0, z_0 );
1236 "Belos::GmresPolySolMgr::solve(): Failed to compute initial block of orthonormal vectors after restart.");
1243 block_gmres_iter->initializeGmres(newstate);
1255 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
1256 "Belos::GmresPolySolMgr::solve(): Invalid return from BlockGmresIter::iterate().");
1261 if (blockSize_ != 1) {
1262 printer_->stream(
Errors) <<
"Error! Caught std::exception in BlockGmresIter::iterate() at iteration " 1263 << block_gmres_iter->getNumIters() << std::endl
1264 << e.what() << std::endl;
1265 if (convTest_->getStatus() !=
Passed)
1266 isConverged =
false;
1271 block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
1274 sTest_->checkStatus( &*block_gmres_iter );
1275 if (convTest_->getStatus() !=
Passed)
1276 isConverged =
false;
1280 catch (
const std::exception &e) {
1281 printer_->stream(
Errors) <<
"Error! Caught std::exception in BlockGmresIter::iterate() at iteration " 1282 << block_gmres_iter->getNumIters() << std::endl
1283 << e.what() << std::endl;
1291 if ( !Teuchos::is_null(expConvTest_->getSolution()) ) {
1292 Teuchos::RCP<MV> newX = expConvTest_->getSolution();
1293 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1297 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1298 problem_->updateSolution( update,
true );
1302 problem_->setCurrLS();
1305 startPtr += numCurrRHS;
1306 numRHS2Solve -= numCurrRHS;
1307 if ( numRHS2Solve > 0 ) {
1308 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1310 currIdx.resize( blockSize_ );
1311 for (
int i=0; i<numCurrRHS; ++i)
1312 { currIdx[i] = startPtr+i; }
1313 for (
int i=numCurrRHS; i<blockSize_; ++i)
1314 { currIdx[i] = -1; }
1317 problem_->setLSIndex( currIdx );
1320 currIdx.resize( numRHS2Solve );
1332 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1337 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1340 if (!isConverged || loaDetected_) {
1347 template<
class ScalarType,
class MV,
class OP>
1350 std::ostringstream oss;
1351 oss <<
"Belos::GmresPolySolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<
">";
1353 oss <<
"Ortho Type='"<<orthoType_<<
"\', Block Size=" <<blockSize_;
1354 oss <<
", Num Blocks=" <<numBlocks_<<
", Max Restarts=" << maxRestarts_;
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
std::string description() const
Method to return description of the hybrid block GMRES solver manager.
Collection of types and exceptions used within the Belos solvers.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
bool isLOADetected() const
Return whether a loss of accuracy was detected by this solver during the most current solve...
Class which manages the output and verbosity of the Belos solvers.
virtual ~GmresPolySolMgr()
Destructor.
Defines the GMRES polynomial operator hybrid-GMRES iterative linear solver.
ScaleType
The type of scaling to use on the residual norm value.
static void MvRandom(MV &mv)
Replace the vectors in mv with random vectors.
This class implements the block GMRES iteration, where a block Krylov subspace is constructed...
Convergence test using the implicit residual norm(s), with an explicit residual norm(s) check for los...
Teuchos::RCP< const MV > V
The current Krylov basis.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
A factory class for generating StatusTestOutput objects.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > z
The current right-hand side of the least squares system RY = Z.
An implementation of StatusTestResNorm using a family of residual norms.
Structure to contain pointers to GmresIteration state variables.
An extension of the MultiVecTraits class that adds a new vector length method.
Belos::StatusTest class for specifying a maximum number of iterations.
static void MvInit(MV &mv, const ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
Replace each element of the vectors in mv with alpha.
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.
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
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 > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
ResetType
How to reset the solver.
GmresPolySolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
Pure virtual base class which describes the basic interface for a solver manager. ...
int curDim
The current dimension of the reduction.
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > R
The current upper-triangular matrix from the QR reduction of H.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the parameters the solver manager should use to solve the linear problem.
The Belos::GmresPolySolMgr provides a powerful and fully-featured solver manager over the hybrid bloc...
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.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
Belos's class for applying the GMRES polynomial operator that is used by the hybrid-GMRES linear solv...
Belos concrete class for performing the block GMRES iteration.
Iterated Classical Gram-Schmidt (ICGS) implementation of the Belos::OrthoManager class.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
GmresPolySolMgrPolynomialFailure is thrown when their is a problem generating the GMRES polynomial fo...
GmresPolySolMgrPolynomialFailure(const std::string &what_arg)
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::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest for specifying an implicit residual norm stopping criteria that checks for loss of ...
static ptrdiff_t GetGlobalLength(const MV &mv)
Obtain the vector length of mv.
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.
Class which defines basic traits for the operator type.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get current linear problem being solved for in this object.
Parent class to all Belos exceptions.
GmresPolySolMgr()
Empty constructor for GmresPolySolMgr. This constructor takes no arguments and sets the default value...
Pure virtual base class which augments the basic interface for a Gmres linear solver iteration...
GmresIterationOrthoFailure is thrown when the GmresIteration object is unable to compute independent ...
Belos header file which uses auto-configuration information to include necessary C++ headers...
int getNumIters() const
Get the iteration count for the most recent call to solve().
GmresPolySolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate orthon...
GmresPolySolMgrOrthoFailure(const std::string &what_arg)
GmresPolySolMgrLinearProblemFailure(const std::string &what_arg)
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > H
The current Hessenberg matrix.