42 #ifndef BELOS_BLOCK_GMRES_SOLMGR_HPP 43 #define BELOS_BLOCK_GMRES_SOLMGR_HPP 68 #include "Teuchos_BLAS.hpp" 69 #ifdef BELOS_TEUCHOS_TIME_MONITOR 70 #include "Teuchos_TimeMonitor.hpp" 124 template<
class ScalarType,
class MV,
class OP>
130 typedef Teuchos::ScalarTraits<ScalarType> SCT;
131 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
132 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
167 const Teuchos::RCP<Teuchos::ParameterList> &pl );
184 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const;
195 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
196 return Teuchos::tuple(timerSolve_);
232 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms );
282 describe (Teuchos::FancyOStream& out,
283 const Teuchos::EVerbosityLevel verbLevel =
284 Teuchos::Describable::verbLevel_default)
const;
287 std::string description ()
const;
294 bool checkStatusTest();
297 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
300 Teuchos::RCP<OutputManager<ScalarType> > printer_;
301 Teuchos::RCP<std::ostream> outputStream_;
304 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > debugStatusTest_;
305 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
306 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
307 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
308 Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > expConvTest_, impConvTest_;
309 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
312 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > ortho_;
315 Teuchos::RCP<Teuchos::ParameterList> params_;
318 static const MagnitudeType convtol_default_;
319 static const MagnitudeType orthoKappa_default_;
320 static const int maxRestarts_default_;
321 static const int maxIters_default_;
322 static const bool adaptiveBlockSize_default_;
323 static const bool showMaxResNormOnly_default_;
324 static const bool flexibleGmres_default_;
325 static const bool expResTest_default_;
326 static const int blockSize_default_;
327 static const int numBlocks_default_;
328 static const int verbosity_default_;
329 static const int outputStyle_default_;
330 static const int outputFreq_default_;
331 static const std::string impResScale_default_;
332 static const std::string expResScale_default_;
333 static const std::string label_default_;
334 static const std::string orthoType_default_;
335 static const Teuchos::RCP<std::ostream> outputStream_default_;
338 MagnitudeType convtol_, orthoKappa_, achievedTol_;
339 int maxRestarts_, maxIters_, numIters_;
340 int blockSize_, numBlocks_, verbosity_, outputStyle_, outputFreq_;
341 bool adaptiveBlockSize_, showMaxResNormOnly_, isFlexible_, expResTest_;
342 std::string orthoType_;
343 std::string impResScale_, expResScale_;
347 Teuchos::RCP<Teuchos::Time> timerSolve_;
350 bool isSet_, isSTSet_;
356 template<
class ScalarType,
class MV,
class OP>
359 template<
class ScalarType,
class MV,
class OP>
362 template<
class ScalarType,
class MV,
class OP>
365 template<
class ScalarType,
class MV,
class OP>
368 template<
class ScalarType,
class MV,
class OP>
371 template<
class ScalarType,
class MV,
class OP>
374 template<
class ScalarType,
class MV,
class OP>
377 template<
class ScalarType,
class MV,
class OP>
380 template<
class ScalarType,
class MV,
class OP>
383 template<
class ScalarType,
class MV,
class OP>
386 template<
class ScalarType,
class MV,
class OP>
389 template<
class ScalarType,
class MV,
class OP>
392 template<
class ScalarType,
class MV,
class OP>
395 template<
class ScalarType,
class MV,
class OP>
398 template<
class ScalarType,
class MV,
class OP>
401 template<
class ScalarType,
class MV,
class OP>
404 template<
class ScalarType,
class MV,
class OP>
407 template<
class ScalarType,
class MV,
class OP>
412 template<
class ScalarType,
class MV,
class OP>
414 outputStream_(outputStream_default_),
415 convtol_(convtol_default_),
416 orthoKappa_(orthoKappa_default_),
417 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
418 maxRestarts_(maxRestarts_default_),
419 maxIters_(maxIters_default_),
421 blockSize_(blockSize_default_),
422 numBlocks_(numBlocks_default_),
423 verbosity_(verbosity_default_),
424 outputStyle_(outputStyle_default_),
425 outputFreq_(outputFreq_default_),
426 adaptiveBlockSize_(adaptiveBlockSize_default_),
427 showMaxResNormOnly_(showMaxResNormOnly_default_),
428 isFlexible_(flexibleGmres_default_),
429 expResTest_(expResTest_default_),
430 orthoType_(orthoType_default_),
431 impResScale_(impResScale_default_),
432 expResScale_(expResScale_default_),
433 label_(label_default_),
441 template<
class ScalarType,
class MV,
class OP>
444 const Teuchos::RCP<Teuchos::ParameterList> &pl) :
446 outputStream_(outputStream_default_),
447 convtol_(convtol_default_),
448 orthoKappa_(orthoKappa_default_),
449 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
450 maxRestarts_(maxRestarts_default_),
451 maxIters_(maxIters_default_),
453 blockSize_(blockSize_default_),
454 numBlocks_(numBlocks_default_),
455 verbosity_(verbosity_default_),
456 outputStyle_(outputStyle_default_),
457 outputFreq_(outputFreq_default_),
458 adaptiveBlockSize_(adaptiveBlockSize_default_),
459 showMaxResNormOnly_(showMaxResNormOnly_default_),
460 isFlexible_(flexibleGmres_default_),
461 expResTest_(expResTest_default_),
462 orthoType_(orthoType_default_),
463 impResScale_(impResScale_default_),
464 expResScale_(expResScale_default_),
465 label_(label_default_),
471 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager.");
474 if ( !is_null(pl) ) {
481 template<
class ScalarType,
class MV,
class OP>
482 Teuchos::RCP<const Teuchos::ParameterList>
485 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
486 if (is_null(validPL)) {
487 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
488 pl->set(
"Convergence Tolerance", convtol_default_,
489 "The relative residual tolerance that needs to be achieved by the\n" 490 "iterative solver in order for the linear system to be declared converged." );
491 pl->set(
"Maximum Restarts", maxRestarts_default_,
492 "The maximum number of restarts allowed for each\n" 493 "set of RHS solved.");
494 pl->set(
"Maximum Iterations", maxIters_default_,
495 "The maximum number of block iterations allowed for each\n" 496 "set of RHS solved.");
497 pl->set(
"Num Blocks", numBlocks_default_,
498 "The maximum number of blocks allowed in the Krylov subspace\n" 499 "for each set of RHS solved.");
500 pl->set(
"Block Size", blockSize_default_,
501 "The number of vectors in each block. This number times the\n" 502 "number of blocks is the total Krylov subspace dimension.");
503 pl->set(
"Adaptive Block Size", adaptiveBlockSize_default_,
504 "Whether the solver manager should adapt the block size\n" 505 "based on the number of RHS to solve.");
506 pl->set(
"Verbosity", verbosity_default_,
507 "What type(s) of solver information should be outputted\n" 508 "to the output stream.");
509 pl->set(
"Output Style", outputStyle_default_,
510 "What style is used for the solver information outputted\n" 511 "to the output stream.");
512 pl->set(
"Output Frequency", outputFreq_default_,
513 "How often convergence information should be outputted\n" 514 "to the output stream.");
515 pl->set(
"Output Stream", outputStream_default_,
516 "A reference-counted pointer to the output stream where all\n" 517 "solver output is sent.");
518 pl->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
519 "When convergence information is printed, only show the maximum\n" 520 "relative residual norm when the block size is greater than one.");
521 pl->set(
"Flexible Gmres", flexibleGmres_default_,
522 "Whether the solver manager should use the flexible variant\n" 524 pl->set(
"Explicit Residual Test", expResTest_default_,
525 "Whether the explicitly computed residual should be used in the convergence test.");
526 pl->set(
"Implicit Residual Scaling", impResScale_default_,
527 "The type of scaling used in the implicit residual convergence test.");
528 pl->set(
"Explicit Residual Scaling", expResScale_default_,
529 "The type of scaling used in the explicit residual convergence test.");
530 pl->set(
"Timer Label", label_default_,
531 "The string to use as a prefix for the timer labels.");
532 pl->set(
"Orthogonalization", orthoType_default_,
533 "The type of orthogonalization to use: DGKS, ICGS, or IMGS.");
534 pl->set(
"Orthogonalization Constant",orthoKappa_default_,
535 "The constant used by DGKS orthogonalization to determine\n" 536 "whether another step of classical Gram-Schmidt is necessary.");
543 template<
class ScalarType,
class MV,
class OP>
548 if (params_ == Teuchos::null) {
556 if (params->isParameter(
"Maximum Restarts")) {
557 maxRestarts_ = params->get(
"Maximum Restarts",maxRestarts_default_);
560 params_->set(
"Maximum Restarts", maxRestarts_);
564 if (params->isParameter(
"Maximum Iterations")) {
565 maxIters_ = params->get(
"Maximum Iterations",maxIters_default_);
568 params_->set(
"Maximum Iterations", maxIters_);
569 if (maxIterTest_!=Teuchos::null)
570 maxIterTest_->setMaxIters( maxIters_ );
574 if (params->isParameter(
"Block Size")) {
575 blockSize_ = params->get(
"Block Size",blockSize_default_);
576 TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ <= 0, std::invalid_argument,
577 "Belos::BlockGmresSolMgr: \"Block Size\" must be strictly positive.");
580 params_->set(
"Block Size", blockSize_);
584 if (params->isParameter(
"Adaptive Block Size")) {
585 adaptiveBlockSize_ = params->get(
"Adaptive Block Size",adaptiveBlockSize_default_);
588 params_->set(
"Adaptive Block Size", adaptiveBlockSize_);
592 if (params->isParameter(
"Num Blocks")) {
593 numBlocks_ = params->get(
"Num Blocks",numBlocks_default_);
594 TEUCHOS_TEST_FOR_EXCEPTION(numBlocks_ <= 0, std::invalid_argument,
595 "Belos::BlockGmresSolMgr: \"Num Blocks\" must be strictly positive.");
598 params_->set(
"Num Blocks", numBlocks_);
602 if (params->isParameter(
"Timer Label")) {
603 std::string tempLabel = params->get(
"Timer Label", label_default_);
606 if (tempLabel != label_) {
608 params_->set(
"Timer Label", label_);
609 std::string solveLabel = label_ +
": BlockGmresSolMgr total solve time";
610 #ifdef BELOS_TEUCHOS_TIME_MONITOR 611 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
613 if (ortho_ != Teuchos::null) {
614 ortho_->setLabel( label_ );
620 if (params->isParameter(
"Flexible Gmres")) {
621 isFlexible_ = Teuchos::getParameter<bool>(*params,
"Flexible Gmres");
622 params_->set(
"Flexible Gmres", isFlexible_);
623 if (isFlexible_ && expResTest_) {
631 if (params->isParameter(
"Orthogonalization")) {
632 std::string tempOrthoType = params->get(
"Orthogonalization",orthoType_default_);
633 TEUCHOS_TEST_FOR_EXCEPTION( tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" && tempOrthoType !=
"IMGS",
634 std::invalid_argument,
635 "Belos::BlockGmresSolMgr: \"Orthogonalization\" must be either \"DGKS\", \"ICGS\", or \"IMGS\".");
636 if (tempOrthoType != orthoType_) {
637 orthoType_ = tempOrthoType;
638 params_->set(
"Orthogonalization", orthoType_);
640 if (orthoType_==
"DGKS") {
641 if (orthoKappa_ <= 0) {
649 else if (orthoType_==
"ICGS") {
652 else if (orthoType_==
"IMGS") {
659 if (params->isParameter(
"Orthogonalization Constant")) {
660 orthoKappa_ = params->get(
"Orthogonalization Constant",orthoKappa_default_);
663 params_->set(
"Orthogonalization Constant",orthoKappa_);
664 if (orthoType_==
"DGKS") {
665 if (orthoKappa_ > 0 && ortho_ != Teuchos::null) {
672 if (params->isParameter(
"Verbosity")) {
673 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
674 verbosity_ = params->get(
"Verbosity", verbosity_default_);
676 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
680 params_->set(
"Verbosity", verbosity_);
681 if (printer_ != Teuchos::null)
682 printer_->setVerbosity(verbosity_);
686 if (params->isParameter(
"Output Style")) {
687 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
688 outputStyle_ = params->get(
"Output Style", outputStyle_default_);
690 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
694 params_->set(
"Output Style", outputStyle_);
695 if (outputTest_ != Teuchos::null) {
701 if (params->isParameter(
"Output Stream")) {
702 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
705 params_->set(
"Output Stream", outputStream_);
706 if (printer_ != Teuchos::null)
707 printer_->setOStream( outputStream_ );
712 if (params->isParameter(
"Output Frequency")) {
713 outputFreq_ = params->get(
"Output Frequency", outputFreq_default_);
717 params_->set(
"Output Frequency", outputFreq_);
718 if (outputTest_ != Teuchos::null)
719 outputTest_->setOutputFrequency( outputFreq_ );
723 if (printer_ == Teuchos::null) {
728 if (params->isParameter(
"Convergence Tolerance")) {
729 convtol_ = params->get(
"Convergence Tolerance",convtol_default_);
732 params_->set(
"Convergence Tolerance", convtol_);
733 if (impConvTest_ != Teuchos::null)
734 impConvTest_->setTolerance( convtol_ );
735 if (expConvTest_ != Teuchos::null)
736 expConvTest_->setTolerance( convtol_ );
740 if (params->isParameter(
"Implicit Residual Scaling")) {
741 std::string tempImpResScale = Teuchos::getParameter<std::string>( *params,
"Implicit Residual Scaling" );
744 if (impResScale_ != tempImpResScale) {
746 impResScale_ = tempImpResScale;
749 params_->set(
"Implicit Residual Scaling", impResScale_);
750 if (impConvTest_ != Teuchos::null) {
754 catch (std::exception& e) {
762 if (params->isParameter(
"Explicit Residual Scaling")) {
763 std::string tempExpResScale = Teuchos::getParameter<std::string>( *params,
"Explicit Residual Scaling" );
766 if (expResScale_ != tempExpResScale) {
768 expResScale_ = tempExpResScale;
771 params_->set(
"Explicit Residual Scaling", expResScale_);
772 if (expConvTest_ != Teuchos::null) {
776 catch (std::exception& e) {
784 if (params->isParameter(
"Explicit Residual Test")) {
785 expResTest_ = Teuchos::getParameter<bool>( *params,
"Explicit Residual Test" );
788 params_->set(
"Explicit Residual Test", expResTest_);
789 if (expConvTest_ == Teuchos::null) {
795 if (params->isParameter(
"Show Maximum Residual Norm Only")) {
796 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,
"Show Maximum Residual Norm Only");
799 params_->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_);
800 if (impConvTest_ != Teuchos::null)
801 impConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
802 if (expConvTest_ != Teuchos::null)
803 expConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
807 if (ortho_ == Teuchos::null) {
808 params_->set(
"Orthogonalization", orthoType_);
809 if (orthoType_==
"DGKS") {
810 if (orthoKappa_ <= 0) {
818 else if (orthoType_==
"ICGS") {
821 else if (orthoType_==
"IMGS") {
825 TEUCHOS_TEST_FOR_EXCEPTION(orthoType_!=
"ICGS"&&orthoType_!=
"DGKS"&&orthoType_!=
"IMGS",std::logic_error,
826 "Belos::BlockGmresSolMgr(): Invalid orthogonalization type.");
831 if (timerSolve_ == Teuchos::null) {
832 std::string solveLabel = label_ +
": BlockGmresSolMgr total solve time";
833 #ifdef BELOS_TEUCHOS_TIME_MONITOR 834 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
843 template<
class ScalarType,
class MV,
class OP>
855 if (!Teuchos::is_null(problem_->getLeftPrec()) && !isFlexible_) {
862 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
863 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_ ) );
865 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
866 impConvTest_ = tmpImpConvTest;
869 Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
870 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_ ) );
871 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
873 tmpExpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
874 expConvTest_ = tmpExpConvTest;
877 convTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
883 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
884 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_ ) );
886 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
887 impConvTest_ = tmpImpConvTest;
892 Teuchos::RCP<StatusTestImpResNorm_t> tmpImpConvTest =
893 Teuchos::rcp(
new StatusTestImpResNorm_t( convtol_ ) );
895 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
896 impConvTest_ = tmpImpConvTest;
900 expConvTest_ = impConvTest_;
901 convTest_ = impConvTest_;
905 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
908 if (nonnull(debugStatusTest_) ) {
910 Teuchos::rcp_dynamic_cast<StatusTestCombo_t>(sTest_)->addStatusTest( debugStatusTest_ );
919 std::string solverDesc =
" Block Gmres ";
921 solverDesc =
"Flexible" + solverDesc;
922 outputTest_->setSolverDesc( solverDesc );
930 template<
class ScalarType,
class MV,
class OP>
935 debugStatusTest_ = debugStatusTest;
940 template<
class ScalarType,
class MV,
class OP>
950 Teuchos::BLAS<int,ScalarType> blas;
953 "Belos::BlockGmresSolMgr::solve(): Linear problem is not a valid object.");
956 "Belos::BlockGmresSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
960 "Belos::BlockGmresSolMgr::solve(): Linear problem does not have a preconditioner required for flexible GMRES, call setRightPrec().");
963 if (!isSTSet_ || (!expResTest_ && !Teuchos::is_null(problem_->getLeftPrec())) ) {
965 "Belos::BlockGmresSolMgr::solve(): Linear problem and requested status tests are incompatible.");
971 int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
973 std::vector<int> currIdx;
976 if ( adaptiveBlockSize_ ) {
977 blockSize_ = numCurrRHS;
978 currIdx.resize( numCurrRHS );
979 for (
int i=0; i<numCurrRHS; ++i)
980 { currIdx[i] = startPtr+i; }
984 currIdx.resize( blockSize_ );
985 for (
int i=0; i<numCurrRHS; ++i)
986 { currIdx[i] = startPtr+i; }
987 for (
int i=numCurrRHS; i<blockSize_; ++i)
992 problem_->setLSIndex( currIdx );
996 Teuchos::ParameterList plist;
997 plist.set(
"Block Size",blockSize_);
1000 if (blockSize_*static_cast<ptrdiff_t>(numBlocks_) > dim) {
1001 int tmpNumBlocks = 0;
1002 if (blockSize_ == 1)
1003 tmpNumBlocks = dim / blockSize_;
1005 tmpNumBlocks = ( dim - blockSize_) / blockSize_;
1007 "Belos::BlockGmresSolMgr::solve(): Warning! Requested Krylov subspace dimension is larger than operator dimension!" 1008 << std::endl <<
" The maximum number of blocks allowed for the Krylov subspace will be adjusted to " << tmpNumBlocks << std::endl;
1009 plist.set(
"Num Blocks",tmpNumBlocks);
1012 plist.set(
"Num Blocks",numBlocks_);
1015 outputTest_->reset();
1016 loaDetected_ =
false;
1019 bool isConverged =
true;
1024 Teuchos::RCP<GmresIteration<ScalarType,MV,OP> > block_gmres_iter;
1033 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1034 Teuchos::TimeMonitor slvtimer(*timerSolve_);
1037 while ( numRHS2Solve > 0 ) {
1040 if (blockSize_*numBlocks_ > dim) {
1041 int tmpNumBlocks = 0;
1042 if (blockSize_ == 1)
1043 tmpNumBlocks = dim / blockSize_;
1045 tmpNumBlocks = ( dim - blockSize_) / blockSize_;
1046 block_gmres_iter->setSize( blockSize_, tmpNumBlocks );
1049 block_gmres_iter->setSize( blockSize_, numBlocks_ );
1052 block_gmres_iter->resetNumIters();
1055 outputTest_->resetNumCalls();
1058 Teuchos::RCP<MV> V_0;
1061 if (currIdx[blockSize_-1] == -1) {
1062 V_0 =
MVT::Clone( *(problem_->getInitResVec()), blockSize_ );
1063 problem_->computeCurrResVec( &*V_0 );
1071 if (currIdx[blockSize_-1] == -1) {
1072 V_0 =
MVT::Clone( *(problem_->getInitPrecResVec()), blockSize_ );
1073 problem_->computeCurrPrecResVec( &*V_0 );
1076 V_0 =
MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1081 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > z_0 =
1082 Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1085 int rank = ortho_->normalize( *V_0, z_0 );
1087 "Belos::BlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors.");
1094 block_gmres_iter->initializeGmres(newstate);
1095 int numRestarts = 0;
1100 block_gmres_iter->iterate();
1107 if ( convTest_->getStatus() ==
Passed ) {
1108 if ( expConvTest_->getLOADetected() ) {
1110 loaDetected_ =
true;
1112 "Belos::BlockGmresSolMgr::solve(): Warning! Solver has experienced a loss of accuracy!" << std::endl;
1113 isConverged =
false;
1122 else if ( maxIterTest_->getStatus() ==
Passed ) {
1124 isConverged =
false;
1132 else if ( block_gmres_iter->getCurSubspaceDim() == block_gmres_iter->getMaxSubspaceDim() ) {
1134 if ( numRestarts >= maxRestarts_ ) {
1135 isConverged =
false;
1140 printer_->stream(
Debug) <<
" Performing restart number " << numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
1143 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1146 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1150 problem_->updateSolution( update,
true );
1159 problem_->computeCurrResVec( &*V_0 );
1161 problem_->computeCurrPrecResVec( &*V_0 );
1164 z_0 = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1167 rank = ortho_->normalize( *V_0, z_0 );
1169 "Belos::BlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors after restart.");
1175 block_gmres_iter->initializeGmres(newstate);
1187 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
1188 "Belos::BlockGmresSolMgr::solve(): Invalid return from BlockGmresIter::iterate().");
1193 if (blockSize_ != 1) {
1194 printer_->stream(
Errors) <<
"Error! Caught std::exception in BlockGmresIter::iterate() at iteration " 1195 << block_gmres_iter->getNumIters() << std::endl
1196 << e.what() << std::endl;
1197 if (convTest_->getStatus() !=
Passed)
1198 isConverged =
false;
1203 block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
1206 sTest_->checkStatus( &*block_gmres_iter );
1207 if (convTest_->getStatus() !=
Passed)
1208 isConverged =
false;
1212 catch (
const std::exception &e) {
1213 printer_->stream(
Errors) <<
"Error! Caught std::exception in BlockGmresIter::iterate() at iteration " 1214 << block_gmres_iter->getNumIters() << std::endl
1215 << e.what() << std::endl;
1224 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1225 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1227 if (update != Teuchos::null)
1232 if ( !Teuchos::is_null(expConvTest_->getSolution()) ) {
1233 Teuchos::RCP<MV> newX = expConvTest_->getSolution();
1234 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1238 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1239 problem_->updateSolution( update,
true );
1244 problem_->setCurrLS();
1247 startPtr += numCurrRHS;
1248 numRHS2Solve -= numCurrRHS;
1249 if ( numRHS2Solve > 0 ) {
1250 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1252 if ( adaptiveBlockSize_ ) {
1253 blockSize_ = numCurrRHS;
1254 currIdx.resize( numCurrRHS );
1255 for (
int i=0; i<numCurrRHS; ++i)
1256 { currIdx[i] = startPtr+i; }
1259 currIdx.resize( blockSize_ );
1260 for (
int i=0; i<numCurrRHS; ++i)
1261 { currIdx[i] = startPtr+i; }
1262 for (
int i=numCurrRHS; i<blockSize_; ++i)
1263 { currIdx[i] = -1; }
1266 problem_->setLSIndex( currIdx );
1269 currIdx.resize( numRHS2Solve );
1280 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1285 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1289 numIters_ = maxIterTest_->getNumIters();
1303 const std::vector<MagnitudeType>* pTestValues = NULL;
1305 pTestValues = expConvTest_->getTestValue();
1306 if (pTestValues == NULL || pTestValues->size() < 1) {
1307 pTestValues = impConvTest_->getTestValue();
1312 pTestValues = impConvTest_->getTestValue();
1314 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1315 "Belos::BlockGmresSolMgr::solve(): The implicit convergence test's " 1316 "getTestValue() method returned NULL. Please report this bug to the " 1317 "Belos developers.");
1318 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1319 "Belos::BlockGmresSolMgr::solve(): The implicit convergence test's " 1320 "getTestValue() method returned a vector of length zero. Please report " 1321 "this bug to the Belos developers.");
1326 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1329 if (!isConverged || loaDetected_) {
1336 template<
class ScalarType,
class MV,
class OP>
1339 std::ostringstream out;
1340 out <<
"\"Belos::BlockGmresSolMgr\": {";
1341 if (this->getObjectLabel () !=
"") {
1342 out <<
"Label: " << this->getObjectLabel () <<
", ";
1344 out <<
"Flexible: " << (isFlexible_ ?
"true" :
"false")
1345 <<
", Num Blocks: " << numBlocks_
1346 <<
", Maximum Iterations: " << maxIters_
1347 <<
", Maximum Restarts: " << maxRestarts_
1348 <<
", Convergence Tolerance: " << convtol_
1354 template<
class ScalarType,
class MV,
class OP>
1358 const Teuchos::EVerbosityLevel verbLevel)
const 1360 using Teuchos::TypeNameTraits;
1361 using Teuchos::VERB_DEFAULT;
1362 using Teuchos::VERB_NONE;
1363 using Teuchos::VERB_LOW;
1370 const Teuchos::EVerbosityLevel vl =
1371 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
1373 if (vl != VERB_NONE) {
1374 Teuchos::OSTab tab0 (out);
1376 out <<
"\"Belos::BlockGmresSolMgr\":" << endl;
1377 Teuchos::OSTab tab1 (out);
1378 out <<
"Template parameters:" << endl;
1380 Teuchos::OSTab tab2 (out);
1381 out <<
"ScalarType: " << TypeNameTraits<ScalarType>::name () << endl
1382 <<
"MV: " << TypeNameTraits<MV>::name () << endl
1383 <<
"OP: " << TypeNameTraits<OP>::name () << endl;
1385 if (this->getObjectLabel () !=
"") {
1386 out <<
"Label: " << this->getObjectLabel () << endl;
1388 out <<
"Flexible: " << (isFlexible_ ?
"true" :
"false") << endl
1389 <<
"Num Blocks: " << numBlocks_ << endl
1390 <<
"Maximum Iterations: " << maxIters_ << endl
1391 <<
"Maximum Restarts: " << maxRestarts_ << endl
1392 <<
"Convergence Tolerance: " << convtol_ << endl;
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Collection of types and exceptions used within the Belos solvers.
void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &debugStatusTest)
Set a debug status test that will be checked at the same time as the top-level status test...
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.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
ScaleType
The type of scaling to use on the residual norm value.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
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.
Virtual base class for StatusTest that printing status tests.
A factory class for generating StatusTestOutput objects.
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.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
BlockGmresSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
Structure to contain pointers to GmresIteration state variables.
Belos::StatusTest class for specifying a maximum number of iterations.
Interface to Block GMRES and Flexible GMRES.
A pure virtual class for defining the status tests for the Belos iterative solvers.
virtual ~BlockGmresSolMgr()
Destructor.
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 > 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. ...
int curDim
The current dimension of the reduction.
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.
BlockGmresSolMgrLinearProblemFailure(const std::string &what_arg)
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
This class implements the block flexible GMRES iteration, where a block Krylov subspace is constructe...
std::string description() const
Return a one-line description of this object.
bool isLOADetected() const
Return whether a loss of accuracy was detected by this solver during the most current solve...
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 ...
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
Belos concrete class for performing the block GMRES iteration.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
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 ...
static ptrdiff_t GetGlobalLength(const MV &mv)
Return the number of rows in the given multivector mv.
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
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 ...
BlockGmresSolMgr()
Empty constructor for BlockGmresSolMgr. This constructor takes no arguments and sets the default valu...
int getNumIters() const
Get the iteration count for the most recent call to solve().
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
BlockGmresSolMgrOrthoFailure(const std::string &what_arg)
A class for extending the status testing capabilities of Belos via logical combinations.
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
BlockGmresSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate ortho...
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...
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get current linear problem being solved for in this object.
Belos concrete class for performing the block, flexible GMRES iteration.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the parameters the solver manager should use to solve the linear problem.