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;
161 const Teuchos::RCP<Teuchos::ParameterList> &pl );
178 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const;
189 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
190 return Teuchos::tuple(timerSolve_);
226 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms );
273 describe (Teuchos::FancyOStream& out,
274 const Teuchos::EVerbosityLevel verbLevel =
275 Teuchos::Describable::verbLevel_default)
const;
278 std::string description ()
const;
285 bool checkStatusTest();
288 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
291 Teuchos::RCP<OutputManager<ScalarType> > printer_;
292 Teuchos::RCP<std::ostream> outputStream_;
295 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
296 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
297 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
298 Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > expConvTest_, impConvTest_;
299 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
302 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > ortho_;
305 Teuchos::RCP<Teuchos::ParameterList> params_;
308 static const MagnitudeType convtol_default_;
309 static const MagnitudeType orthoKappa_default_;
310 static const int maxRestarts_default_;
311 static const int maxIters_default_;
312 static const bool adaptiveBlockSize_default_;
313 static const bool showMaxResNormOnly_default_;
314 static const bool flexibleGmres_default_;
315 static const bool expResTest_default_;
316 static const int blockSize_default_;
317 static const int numBlocks_default_;
318 static const int verbosity_default_;
319 static const int outputStyle_default_;
320 static const int outputFreq_default_;
321 static const std::string impResScale_default_;
322 static const std::string expResScale_default_;
323 static const std::string label_default_;
324 static const std::string orthoType_default_;
325 static const Teuchos::RCP<std::ostream> outputStream_default_;
328 MagnitudeType convtol_, orthoKappa_, achievedTol_;
329 int maxRestarts_, maxIters_, numIters_;
330 int blockSize_, numBlocks_, verbosity_, outputStyle_, outputFreq_;
331 bool adaptiveBlockSize_, showMaxResNormOnly_, isFlexible_, expResTest_;
332 std::string orthoType_;
333 std::string impResScale_, expResScale_;
337 Teuchos::RCP<Teuchos::Time> timerSolve_;
340 bool isSet_, isSTSet_;
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>
388 template<
class ScalarType,
class MV,
class OP>
391 template<
class ScalarType,
class MV,
class OP>
394 template<
class ScalarType,
class MV,
class OP>
397 template<
class ScalarType,
class MV,
class OP>
402 template<
class ScalarType,
class MV,
class OP>
404 outputStream_(outputStream_default_),
405 convtol_(convtol_default_),
406 orthoKappa_(orthoKappa_default_),
407 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
408 maxRestarts_(maxRestarts_default_),
409 maxIters_(maxIters_default_),
411 blockSize_(blockSize_default_),
412 numBlocks_(numBlocks_default_),
413 verbosity_(verbosity_default_),
414 outputStyle_(outputStyle_default_),
415 outputFreq_(outputFreq_default_),
416 adaptiveBlockSize_(adaptiveBlockSize_default_),
417 showMaxResNormOnly_(showMaxResNormOnly_default_),
418 isFlexible_(flexibleGmres_default_),
419 expResTest_(expResTest_default_),
420 orthoType_(orthoType_default_),
421 impResScale_(impResScale_default_),
422 expResScale_(expResScale_default_),
423 label_(label_default_),
431 template<
class ScalarType,
class MV,
class OP>
434 const Teuchos::RCP<Teuchos::ParameterList> &pl) :
436 outputStream_(outputStream_default_),
437 convtol_(convtol_default_),
438 orthoKappa_(orthoKappa_default_),
439 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
440 maxRestarts_(maxRestarts_default_),
441 maxIters_(maxIters_default_),
443 blockSize_(blockSize_default_),
444 numBlocks_(numBlocks_default_),
445 verbosity_(verbosity_default_),
446 outputStyle_(outputStyle_default_),
447 outputFreq_(outputFreq_default_),
448 adaptiveBlockSize_(adaptiveBlockSize_default_),
449 showMaxResNormOnly_(showMaxResNormOnly_default_),
450 isFlexible_(flexibleGmres_default_),
451 expResTest_(expResTest_default_),
452 orthoType_(orthoType_default_),
453 impResScale_(impResScale_default_),
454 expResScale_(expResScale_default_),
455 label_(label_default_),
461 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager.");
464 if ( !is_null(pl) ) {
471 template<
class ScalarType,
class MV,
class OP>
472 Teuchos::RCP<const Teuchos::ParameterList>
475 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
476 if (is_null(validPL)) {
477 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
478 pl->set(
"Convergence Tolerance", convtol_default_,
479 "The relative residual tolerance that needs to be achieved by the\n" 480 "iterative solver in order for the linear system to be declared converged." );
481 pl->set(
"Maximum Restarts", maxRestarts_default_,
482 "The maximum number of restarts allowed for each\n" 483 "set of RHS solved.");
485 "Maximum Iterations", maxIters_default_,
486 "The maximum number of block iterations allowed for each\n" 487 "set of RHS solved.");
488 pl->set(
"Num Blocks", numBlocks_default_,
489 "The maximum number of blocks allowed in the Krylov subspace\n" 490 "for each set of RHS solved.");
491 pl->set(
"Block Size", blockSize_default_,
492 "The number of vectors in each block. This number times the\n" 493 "number of blocks is the total Krylov subspace dimension.");
494 pl->set(
"Adaptive Block Size", adaptiveBlockSize_default_,
495 "Whether the solver manager should adapt the block size\n" 496 "based on the number of RHS to solve.");
497 pl->set(
"Verbosity", verbosity_default_,
498 "What type(s) of solver information should be outputted\n" 499 "to the output stream.");
500 pl->set(
"Output Style", outputStyle_default_,
501 "What style is used for the solver information outputted\n" 502 "to the output stream.");
503 pl->set(
"Output Frequency", outputFreq_default_,
504 "How often convergence information should be outputted\n" 505 "to the output stream.");
506 pl->set(
"Output Stream", outputStream_default_,
507 "A reference-counted pointer to the output stream where all\n" 508 "solver output is sent.");
509 pl->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
510 "When convergence information is printed, only show the maximum\n" 511 "relative residual norm when the block size is greater than one.");
512 pl->set(
"Flexible Gmres", flexibleGmres_default_,
513 "Whether the solver manager should use the flexible variant\n" 515 pl->set(
"Explicit Residual Test", expResTest_default_,
516 "Whether the explicitly computed residual should be used in the convergence test.");
517 pl->set(
"Implicit Residual Scaling", impResScale_default_,
518 "The type of scaling used in the implicit residual convergence test.");
519 pl->set(
"Explicit Residual Scaling", expResScale_default_,
520 "The type of scaling used in the explicit residual convergence test.");
521 pl->set(
"Timer Label", label_default_,
522 "The string to use as a prefix for the timer labels.");
524 pl->set(
"Orthogonalization", orthoType_default_,
525 "The type of orthogonalization to use: DGKS, ICGS, or IMGS.");
526 pl->set(
"Orthogonalization Constant",orthoKappa_default_,
527 "The constant used by DGKS orthogonalization to determine\n" 528 "whether another step of classical Gram-Schmidt is necessary.");
535 template<
class ScalarType,
class MV,
class OP>
540 if (params_ == Teuchos::null) {
548 if (params->isParameter(
"Maximum Restarts")) {
549 maxRestarts_ = params->get(
"Maximum Restarts",maxRestarts_default_);
552 params_->set(
"Maximum Restarts", maxRestarts_);
556 if (params->isParameter(
"Maximum Iterations")) {
557 maxIters_ = params->get(
"Maximum Iterations",maxIters_default_);
560 params_->set(
"Maximum Iterations", maxIters_);
561 if (maxIterTest_!=Teuchos::null)
562 maxIterTest_->setMaxIters( maxIters_ );
566 if (params->isParameter(
"Block Size")) {
567 blockSize_ = params->get(
"Block Size",blockSize_default_);
568 TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ <= 0, std::invalid_argument,
569 "Belos::BlockGmresSolMgr: \"Block Size\" must be strictly positive.");
572 params_->set(
"Block Size", blockSize_);
576 if (params->isParameter(
"Adaptive Block Size")) {
577 adaptiveBlockSize_ = params->get(
"Adaptive Block Size",adaptiveBlockSize_default_);
580 params_->set(
"Adaptive Block Size", adaptiveBlockSize_);
584 if (params->isParameter(
"Num Blocks")) {
585 numBlocks_ = params->get(
"Num Blocks",numBlocks_default_);
586 TEUCHOS_TEST_FOR_EXCEPTION(numBlocks_ <= 0, std::invalid_argument,
587 "Belos::BlockGmresSolMgr: \"Num Blocks\" must be strictly positive.");
590 params_->set(
"Num Blocks", numBlocks_);
594 if (params->isParameter(
"Timer Label")) {
595 std::string tempLabel = params->get(
"Timer Label", label_default_);
598 if (tempLabel != label_) {
600 params_->set(
"Timer Label", label_);
601 std::string solveLabel = label_ +
": BlockGmresSolMgr total solve time";
602 #ifdef BELOS_TEUCHOS_TIME_MONITOR 603 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
605 if (ortho_ != Teuchos::null) {
606 ortho_->setLabel( label_ );
612 if (params->isParameter(
"Flexible Gmres")) {
613 isFlexible_ = Teuchos::getParameter<bool>(*params,
"Flexible Gmres");
614 params_->set(
"Flexible Gmres", isFlexible_);
615 if (isFlexible_ && expResTest_) {
623 if (params->isParameter(
"Orthogonalization")) {
624 std::string tempOrthoType = params->get(
"Orthogonalization",orthoType_default_);
625 TEUCHOS_TEST_FOR_EXCEPTION( tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" && tempOrthoType !=
"IMGS",
626 std::invalid_argument,
627 "Belos::BlockGmresSolMgr: \"Orthogonalization\" must be either \"DGKS\", \"ICGS\", or \"IMGS\".");
628 if (tempOrthoType != orthoType_) {
629 orthoType_ = tempOrthoType;
631 if (orthoType_==
"DGKS") {
632 if (orthoKappa_ <= 0) {
640 else if (orthoType_==
"ICGS") {
643 else if (orthoType_==
"IMGS") {
650 if (params->isParameter(
"Orthogonalization Constant")) {
651 orthoKappa_ = params->get(
"Orthogonalization Constant",orthoKappa_default_);
654 params_->set(
"Orthogonalization Constant",orthoKappa_);
655 if (orthoType_==
"DGKS") {
656 if (orthoKappa_ > 0 && ortho_ != Teuchos::null) {
663 if (params->isParameter(
"Verbosity")) {
664 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
665 verbosity_ = params->get(
"Verbosity", verbosity_default_);
667 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
671 params_->set(
"Verbosity", verbosity_);
672 if (printer_ != Teuchos::null)
673 printer_->setVerbosity(verbosity_);
677 if (params->isParameter(
"Output Style")) {
678 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
679 outputStyle_ = params->get(
"Output Style", outputStyle_default_);
681 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
685 params_->set(
"Output Style", outputStyle_);
686 if (outputTest_ != Teuchos::null) {
692 if (params->isParameter(
"Output Stream")) {
693 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
696 params_->set(
"Output Stream", outputStream_);
697 if (printer_ != Teuchos::null)
698 printer_->setOStream( outputStream_ );
703 if (params->isParameter(
"Output Frequency")) {
704 outputFreq_ = params->get(
"Output Frequency", outputFreq_default_);
708 params_->set(
"Output Frequency", outputFreq_);
709 if (outputTest_ != Teuchos::null)
710 outputTest_->setOutputFrequency( outputFreq_ );
714 if (printer_ == Teuchos::null) {
719 if (params->isParameter(
"Convergence Tolerance")) {
720 convtol_ = params->get(
"Convergence Tolerance",convtol_default_);
723 params_->set(
"Convergence Tolerance", convtol_);
724 if (impConvTest_ != Teuchos::null)
725 impConvTest_->setTolerance( convtol_ );
726 if (expConvTest_ != Teuchos::null)
727 expConvTest_->setTolerance( convtol_ );
731 if (params->isParameter(
"Implicit Residual Scaling")) {
732 std::string tempImpResScale = Teuchos::getParameter<std::string>( *params,
"Implicit Residual Scaling" );
735 if (impResScale_ != tempImpResScale) {
737 impResScale_ = tempImpResScale;
740 params_->set(
"Implicit Residual Scaling", impResScale_);
741 if (impConvTest_ != Teuchos::null) {
745 catch (std::exception& e) {
753 if (params->isParameter(
"Explicit Residual Scaling")) {
754 std::string tempExpResScale = Teuchos::getParameter<std::string>( *params,
"Explicit Residual Scaling" );
757 if (expResScale_ != tempExpResScale) {
759 expResScale_ = tempExpResScale;
762 params_->set(
"Explicit Residual Scaling", expResScale_);
763 if (expConvTest_ != Teuchos::null) {
767 catch (std::exception& e) {
775 if (params->isParameter(
"Explicit Residual Test")) {
776 expResTest_ = Teuchos::getParameter<bool>( *params,
"Explicit Residual Test" );
779 params_->set(
"Explicit Residual Test", expResTest_);
780 if (expConvTest_ == Teuchos::null) {
786 if (params->isParameter(
"Show Maximum Residual Norm Only")) {
787 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,
"Show Maximum Residual Norm Only");
790 params_->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_);
791 if (impConvTest_ != Teuchos::null)
792 impConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
793 if (expConvTest_ != Teuchos::null)
794 expConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
798 if (ortho_ == Teuchos::null) {
799 if (orthoType_==
"DGKS") {
800 if (orthoKappa_ <= 0) {
808 else if (orthoType_==
"ICGS") {
811 else if (orthoType_==
"IMGS") {
815 TEUCHOS_TEST_FOR_EXCEPTION(orthoType_!=
"ICGS"&&orthoType_!=
"DGKS"&&orthoType_!=
"IMGS",std::logic_error,
816 "Belos::BlockGmresSolMgr(): Invalid orthogonalization type.");
821 if (timerSolve_ == Teuchos::null) {
822 std::string solveLabel = label_ +
": BlockGmresSolMgr total solve time";
823 #ifdef BELOS_TEUCHOS_TIME_MONITOR 824 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
833 template<
class ScalarType,
class MV,
class OP>
845 if (!Teuchos::is_null(problem_->getLeftPrec()) && !isFlexible_) {
852 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
853 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_ ) );
855 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
856 impConvTest_ = tmpImpConvTest;
859 Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
860 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_ ) );
861 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
863 tmpExpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
864 expConvTest_ = tmpExpConvTest;
867 convTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
873 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
874 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_ ) );
876 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
877 impConvTest_ = tmpImpConvTest;
882 Teuchos::RCP<StatusTestImpResNorm_t> tmpImpConvTest =
883 Teuchos::rcp(
new StatusTestImpResNorm_t( convtol_ ) );
885 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
886 impConvTest_ = tmpImpConvTest;
890 expConvTest_ = impConvTest_;
891 convTest_ = impConvTest_;
895 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
903 std::string solverDesc =
" Block Gmres ";
905 solverDesc =
"Flexible" + solverDesc;
906 outputTest_->setSolverDesc( solverDesc );
915 template<
class ScalarType,
class MV,
class OP>
925 Teuchos::BLAS<int,ScalarType> blas;
928 "Belos::BlockGmresSolMgr::solve(): Linear problem is not a valid object.");
931 "Belos::BlockGmresSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
935 "Belos::BlockGmresSolMgr::solve(): Linear problem does not have a preconditioner required for flexible GMRES, call setRightPrec().");
938 if (!isSTSet_ || (!expResTest_ && !Teuchos::is_null(problem_->getLeftPrec())) ) {
940 "Belos::BlockGmresSolMgr::solve(): Linear problem and requested status tests are incompatible.");
946 int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
948 std::vector<int> currIdx;
951 if ( adaptiveBlockSize_ ) {
952 blockSize_ = numCurrRHS;
953 currIdx.resize( numCurrRHS );
954 for (
int i=0; i<numCurrRHS; ++i)
955 { currIdx[i] = startPtr+i; }
959 currIdx.resize( blockSize_ );
960 for (
int i=0; i<numCurrRHS; ++i)
961 { currIdx[i] = startPtr+i; }
962 for (
int i=numCurrRHS; i<blockSize_; ++i)
967 problem_->setLSIndex( currIdx );
971 Teuchos::ParameterList plist;
972 plist.set(
"Block Size",blockSize_);
975 if (blockSize_*static_cast<ptrdiff_t>(numBlocks_) > dim) {
976 int tmpNumBlocks = 0;
978 tmpNumBlocks = dim / blockSize_;
980 tmpNumBlocks = ( dim - blockSize_) / blockSize_;
982 "Belos::BlockGmresSolMgr::solve(): Warning! Requested Krylov subspace dimension is larger than operator dimension!" 983 << std::endl <<
" The maximum number of blocks allowed for the Krylov subspace will be adjusted to " << tmpNumBlocks << std::endl;
984 plist.set(
"Num Blocks",tmpNumBlocks);
987 plist.set(
"Num Blocks",numBlocks_);
990 outputTest_->reset();
991 loaDetected_ =
false;
994 bool isConverged =
true;
999 Teuchos::RCP<GmresIteration<ScalarType,MV,OP> > block_gmres_iter;
1008 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1009 Teuchos::TimeMonitor slvtimer(*timerSolve_);
1012 while ( numRHS2Solve > 0 ) {
1015 if (blockSize_*numBlocks_ > dim) {
1016 int tmpNumBlocks = 0;
1017 if (blockSize_ == 1)
1018 tmpNumBlocks = dim / blockSize_;
1020 tmpNumBlocks = ( dim - blockSize_) / blockSize_;
1021 block_gmres_iter->setSize( blockSize_, tmpNumBlocks );
1024 block_gmres_iter->setSize( blockSize_, numBlocks_ );
1027 block_gmres_iter->resetNumIters();
1030 outputTest_->resetNumCalls();
1033 Teuchos::RCP<MV> V_0;
1036 if (currIdx[blockSize_-1] == -1) {
1037 V_0 =
MVT::Clone( *(problem_->getInitResVec()), blockSize_ );
1038 problem_->computeCurrResVec( &*V_0 );
1046 if (currIdx[blockSize_-1] == -1) {
1047 V_0 =
MVT::Clone( *(problem_->getInitPrecResVec()), blockSize_ );
1048 problem_->computeCurrPrecResVec( &*V_0 );
1051 V_0 =
MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1056 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > z_0 =
1057 Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1060 int rank = ortho_->normalize( *V_0, z_0 );
1062 "Belos::BlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors.");
1069 block_gmres_iter->initializeGmres(newstate);
1070 int numRestarts = 0;
1075 block_gmres_iter->iterate();
1082 if ( convTest_->getStatus() ==
Passed ) {
1083 if ( expConvTest_->getLOADetected() ) {
1085 loaDetected_ =
true;
1087 "Belos::BlockGmresSolMgr::solve(): Warning! Solver has experienced a loss of accuracy!" << std::endl;
1088 isConverged =
false;
1097 else if ( maxIterTest_->getStatus() ==
Passed ) {
1099 isConverged =
false;
1107 else if ( block_gmres_iter->getCurSubspaceDim() == block_gmres_iter->getMaxSubspaceDim() ) {
1109 if ( numRestarts >= maxRestarts_ ) {
1110 isConverged =
false;
1115 printer_->stream(
Debug) <<
" Performing restart number " << numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
1118 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1121 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1125 problem_->updateSolution( update,
true );
1134 problem_->computeCurrResVec( &*V_0 );
1136 problem_->computeCurrPrecResVec( &*V_0 );
1139 z_0 = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1142 rank = ortho_->normalize( *V_0, z_0 );
1144 "Belos::BlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors after restart.");
1150 block_gmres_iter->initializeGmres(newstate);
1162 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
1163 "Belos::BlockGmresSolMgr::solve(): Invalid return from BlockGmresIter::iterate().");
1168 if (blockSize_ != 1) {
1169 printer_->stream(
Errors) <<
"Error! Caught std::exception in BlockGmresIter::iterate() at iteration " 1170 << block_gmres_iter->getNumIters() << std::endl
1171 << e.what() << std::endl;
1172 if (convTest_->getStatus() !=
Passed)
1173 isConverged =
false;
1178 block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
1181 sTest_->checkStatus( &*block_gmres_iter );
1182 if (convTest_->getStatus() !=
Passed)
1183 isConverged =
false;
1187 catch (
const std::exception &e) {
1188 printer_->stream(
Errors) <<
"Error! Caught std::exception in BlockGmresIter::iterate() at iteration " 1189 << block_gmres_iter->getNumIters() << std::endl
1190 << e.what() << std::endl;
1199 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1200 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1202 if (update != Teuchos::null)
1207 if ( !Teuchos::is_null(expConvTest_->getSolution()) ) {
1208 Teuchos::RCP<MV> newX = expConvTest_->getSolution();
1209 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1213 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1214 problem_->updateSolution( update,
true );
1219 problem_->setCurrLS();
1222 startPtr += numCurrRHS;
1223 numRHS2Solve -= numCurrRHS;
1224 if ( numRHS2Solve > 0 ) {
1225 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1227 if ( adaptiveBlockSize_ ) {
1228 blockSize_ = numCurrRHS;
1229 currIdx.resize( numCurrRHS );
1230 for (
int i=0; i<numCurrRHS; ++i)
1231 { currIdx[i] = startPtr+i; }
1234 currIdx.resize( blockSize_ );
1235 for (
int i=0; i<numCurrRHS; ++i)
1236 { currIdx[i] = startPtr+i; }
1237 for (
int i=numCurrRHS; i<blockSize_; ++i)
1238 { currIdx[i] = -1; }
1241 problem_->setLSIndex( currIdx );
1244 currIdx.resize( numRHS2Solve );
1255 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1260 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1264 numIters_ = maxIterTest_->getNumIters();
1278 const std::vector<MagnitudeType>* pTestValues = NULL;
1280 pTestValues = expConvTest_->getTestValue();
1281 if (pTestValues == NULL || pTestValues->size() < 1) {
1282 pTestValues = impConvTest_->getTestValue();
1287 pTestValues = impConvTest_->getTestValue();
1289 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1290 "Belos::BlockGmresSolMgr::solve(): The implicit convergence test's " 1291 "getTestValue() method returned NULL. Please report this bug to the " 1292 "Belos developers.");
1293 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1294 "Belos::BlockGmresSolMgr::solve(): The implicit convergence test's " 1295 "getTestValue() method returned a vector of length zero. Please report " 1296 "this bug to the Belos developers.");
1301 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1304 if (!isConverged || loaDetected_) {
1311 template<
class ScalarType,
class MV,
class OP>
1314 std::ostringstream out;
1315 out <<
"\"Belos::BlockGmresSolMgr\": {";
1316 if (this->getObjectLabel () !=
"") {
1317 out <<
"Label: " << this->getObjectLabel () <<
", ";
1319 out <<
"Flexible: " << (isFlexible_ ?
"true" :
"false")
1320 <<
", Num Blocks: " << numBlocks_
1321 <<
", Maximum Iterations: " << maxIters_
1322 <<
", Maximum Restarts: " << maxRestarts_
1323 <<
", Convergence Tolerance: " << convtol_
1329 template<
class ScalarType,
class MV,
class OP>
1333 const Teuchos::EVerbosityLevel verbLevel)
const 1335 using Teuchos::TypeNameTraits;
1336 using Teuchos::VERB_DEFAULT;
1337 using Teuchos::VERB_NONE;
1338 using Teuchos::VERB_LOW;
1345 const Teuchos::EVerbosityLevel vl =
1346 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
1348 if (vl != VERB_NONE) {
1349 Teuchos::OSTab tab0 (out);
1351 out <<
"\"Belos::BlockGmresSolMgr\":" << endl;
1352 Teuchos::OSTab tab1 (out);
1353 out <<
"Template parameters:" << endl;
1355 Teuchos::OSTab tab2 (out);
1356 out <<
"ScalarType: " << TypeNameTraits<ScalarType>::name () << endl
1357 <<
"MV: " << TypeNameTraits<MV>::name () << endl
1358 <<
"OP: " << TypeNameTraits<OP>::name () << endl;
1360 if (this->getObjectLabel () !=
"") {
1361 out <<
"Label: " << this->getObjectLabel () << endl;
1363 out <<
"Flexible: " << (isFlexible_ ?
"true" :
"false") << endl
1364 <<
"Num Blocks: " << numBlocks_ << endl
1365 <<
"Maximum Iterations: " << maxIters_ << endl
1366 <<
"Maximum Restarts: " << maxRestarts_ << endl
1367 <<
"Convergence Tolerance: " << convtol_ << endl;
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
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...
Class which manages the output and verbosity of the Belos solvers.
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.
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.
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
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.
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 .
std::string description() const
Return a one-line description of this object.
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)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid 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.
This class implements the block flexible GMRES iteration, where a block Krylov subspace is constructe...
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 ...
int getNumIters() const
Get the iteration count for the most recent call to solve().
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.
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...
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...
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
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.
bool isLOADetected() const
Return whether a loss of accuracy was detected by this solver during the most current solve...
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the parameters the solver manager should use to solve the linear problem.