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>
131 typedef Teuchos::ScalarTraits<ScalarType> SCT;
132 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
133 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
162 const Teuchos::RCP<Teuchos::ParameterList> &pl );
179 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const;
190 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
191 return Teuchos::tuple(timerSolve_);
227 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms );
268 std::string description()
const;
275 bool checkStatusTest();
278 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
281 Teuchos::RCP<OutputManager<ScalarType> > printer_;
282 Teuchos::RCP<std::ostream> outputStream_;
285 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
286 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
287 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
288 Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > expConvTest_, impConvTest_;
289 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
292 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > ortho_;
295 Teuchos::RCP<Teuchos::ParameterList> params_;
298 static const MagnitudeType convtol_default_;
299 static const MagnitudeType orthoKappa_default_;
300 static const int maxRestarts_default_;
301 static const int maxIters_default_;
302 static const bool adaptiveBlockSize_default_;
303 static const bool showMaxResNormOnly_default_;
304 static const bool flexibleGmres_default_;
305 static const bool expResTest_default_;
306 static const int blockSize_default_;
307 static const int numBlocks_default_;
308 static const int verbosity_default_;
309 static const int outputStyle_default_;
310 static const int outputFreq_default_;
311 static const std::string impResScale_default_;
312 static const std::string expResScale_default_;
313 static const std::string label_default_;
314 static const std::string orthoType_default_;
315 static const Teuchos::RCP<std::ostream> outputStream_default_;
318 MagnitudeType convtol_, orthoKappa_, achievedTol_;
319 int maxRestarts_, maxIters_, numIters_;
320 int blockSize_, numBlocks_, verbosity_, outputStyle_, outputFreq_;
321 bool adaptiveBlockSize_, showMaxResNormOnly_, isFlexible_, expResTest_;
322 std::string orthoType_;
323 std::string impResScale_, expResScale_;
327 Teuchos::RCP<Teuchos::Time> timerSolve_;
330 bool isSet_, isSTSet_;
336 template<
class ScalarType,
class MV,
class OP>
339 template<
class ScalarType,
class MV,
class OP>
342 template<
class ScalarType,
class MV,
class OP>
345 template<
class ScalarType,
class MV,
class OP>
348 template<
class ScalarType,
class MV,
class OP>
351 template<
class ScalarType,
class MV,
class OP>
354 template<
class ScalarType,
class MV,
class OP>
357 template<
class ScalarType,
class MV,
class OP>
360 template<
class ScalarType,
class MV,
class OP>
363 template<
class ScalarType,
class MV,
class OP>
366 template<
class ScalarType,
class MV,
class OP>
369 template<
class ScalarType,
class MV,
class OP>
372 template<
class ScalarType,
class MV,
class OP>
375 template<
class ScalarType,
class MV,
class OP>
378 template<
class ScalarType,
class MV,
class OP>
381 template<
class ScalarType,
class MV,
class OP>
384 template<
class ScalarType,
class MV,
class OP>
387 template<
class ScalarType,
class MV,
class OP>
392 template<
class ScalarType,
class MV,
class OP>
394 outputStream_(outputStream_default_),
395 convtol_(convtol_default_),
396 orthoKappa_(orthoKappa_default_),
397 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
398 maxRestarts_(maxRestarts_default_),
399 maxIters_(maxIters_default_),
401 blockSize_(blockSize_default_),
402 numBlocks_(numBlocks_default_),
403 verbosity_(verbosity_default_),
404 outputStyle_(outputStyle_default_),
405 outputFreq_(outputFreq_default_),
406 adaptiveBlockSize_(adaptiveBlockSize_default_),
407 showMaxResNormOnly_(showMaxResNormOnly_default_),
408 isFlexible_(flexibleGmres_default_),
409 expResTest_(expResTest_default_),
410 orthoType_(orthoType_default_),
411 impResScale_(impResScale_default_),
412 expResScale_(expResScale_default_),
413 label_(label_default_),
421 template<
class ScalarType,
class MV,
class OP>
424 const Teuchos::RCP<Teuchos::ParameterList> &pl) :
426 outputStream_(outputStream_default_),
427 convtol_(convtol_default_),
428 orthoKappa_(orthoKappa_default_),
429 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
430 maxRestarts_(maxRestarts_default_),
431 maxIters_(maxIters_default_),
433 blockSize_(blockSize_default_),
434 numBlocks_(numBlocks_default_),
435 verbosity_(verbosity_default_),
436 outputStyle_(outputStyle_default_),
437 outputFreq_(outputFreq_default_),
438 adaptiveBlockSize_(adaptiveBlockSize_default_),
439 showMaxResNormOnly_(showMaxResNormOnly_default_),
440 isFlexible_(flexibleGmres_default_),
441 expResTest_(expResTest_default_),
442 orthoType_(orthoType_default_),
443 impResScale_(impResScale_default_),
444 expResScale_(expResScale_default_),
445 label_(label_default_),
451 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager.");
454 if ( !is_null(pl) ) {
461 template<
class ScalarType,
class MV,
class OP>
462 Teuchos::RCP<const Teuchos::ParameterList>
465 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
466 if (is_null(validPL)) {
467 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
468 pl->set(
"Convergence Tolerance", convtol_default_,
469 "The relative residual tolerance that needs to be achieved by the\n" 470 "iterative solver in order for the linear system to be declared converged." );
471 pl->set(
"Maximum Restarts", maxRestarts_default_,
472 "The maximum number of restarts allowed for each\n" 473 "set of RHS solved.");
475 "Maximum Iterations", maxIters_default_,
476 "The maximum number of block iterations allowed for each\n" 477 "set of RHS solved.");
478 pl->set(
"Num Blocks", numBlocks_default_,
479 "The maximum number of blocks allowed in the Krylov subspace\n" 480 "for each set of RHS solved.");
481 pl->set(
"Block Size", blockSize_default_,
482 "The number of vectors in each block. This number times the\n" 483 "number of blocks is the total Krylov subspace dimension.");
484 pl->set(
"Adaptive Block Size", adaptiveBlockSize_default_,
485 "Whether the solver manager should adapt the block size\n" 486 "based on the number of RHS to solve.");
487 pl->set(
"Verbosity", verbosity_default_,
488 "What type(s) of solver information should be outputted\n" 489 "to the output stream.");
490 pl->set(
"Output Style", outputStyle_default_,
491 "What style is used for the solver information outputted\n" 492 "to the output stream.");
493 pl->set(
"Output Frequency", outputFreq_default_,
494 "How often convergence information should be outputted\n" 495 "to the output stream.");
496 pl->set(
"Output Stream", outputStream_default_,
497 "A reference-counted pointer to the output stream where all\n" 498 "solver output is sent.");
499 pl->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
500 "When convergence information is printed, only show the maximum\n" 501 "relative residual norm when the block size is greater than one.");
502 pl->set(
"Flexible Gmres", flexibleGmres_default_,
503 "Whether the solver manager should use the flexible variant\n" 505 pl->set(
"Explicit Residual Test", expResTest_default_,
506 "Whether the explicitly computed residual should be used in the convergence test.");
507 pl->set(
"Implicit Residual Scaling", impResScale_default_,
508 "The type of scaling used in the implicit residual convergence test.");
509 pl->set(
"Explicit Residual Scaling", expResScale_default_,
510 "The type of scaling used in the explicit residual convergence test.");
511 pl->set(
"Timer Label", label_default_,
512 "The string to use as a prefix for the timer labels.");
514 pl->set(
"Orthogonalization", orthoType_default_,
515 "The type of orthogonalization to use: DGKS, ICGS, or IMGS.");
516 pl->set(
"Orthogonalization Constant",orthoKappa_default_,
517 "The constant used by DGKS orthogonalization to determine\n" 518 "whether another step of classical Gram-Schmidt is necessary.");
525 template<
class ScalarType,
class MV,
class OP>
530 if (params_ == Teuchos::null) {
538 if (params->isParameter(
"Maximum Restarts")) {
539 maxRestarts_ = params->get(
"Maximum Restarts",maxRestarts_default_);
542 params_->set(
"Maximum Restarts", maxRestarts_);
546 if (params->isParameter(
"Maximum Iterations")) {
547 maxIters_ = params->get(
"Maximum Iterations",maxIters_default_);
550 params_->set(
"Maximum Iterations", maxIters_);
551 if (maxIterTest_!=Teuchos::null)
552 maxIterTest_->setMaxIters( maxIters_ );
556 if (params->isParameter(
"Block Size")) {
557 blockSize_ = params->get(
"Block Size",blockSize_default_);
558 TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ <= 0, std::invalid_argument,
559 "Belos::BlockGmresSolMgr: \"Block Size\" must be strictly positive.");
562 params_->set(
"Block Size", blockSize_);
566 if (params->isParameter(
"Adaptive Block Size")) {
567 adaptiveBlockSize_ = params->get(
"Adaptive Block Size",adaptiveBlockSize_default_);
570 params_->set(
"Adaptive Block Size", adaptiveBlockSize_);
574 if (params->isParameter(
"Num Blocks")) {
575 numBlocks_ = params->get(
"Num Blocks",numBlocks_default_);
576 TEUCHOS_TEST_FOR_EXCEPTION(numBlocks_ <= 0, std::invalid_argument,
577 "Belos::BlockGmresSolMgr: \"Num Blocks\" must be strictly positive.");
580 params_->set(
"Num Blocks", numBlocks_);
584 if (params->isParameter(
"Timer Label")) {
585 std::string tempLabel = params->get(
"Timer Label", label_default_);
588 if (tempLabel != label_) {
590 params_->set(
"Timer Label", label_);
591 std::string solveLabel = label_ +
": BlockGmresSolMgr total solve time";
592 #ifdef BELOS_TEUCHOS_TIME_MONITOR 593 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
595 if (ortho_ != Teuchos::null) {
596 ortho_->setLabel( label_ );
602 if (params->isParameter(
"Flexible Gmres")) {
603 isFlexible_ = Teuchos::getParameter<bool>(*params,
"Flexible Gmres");
604 params_->set(
"Flexible Gmres", isFlexible_);
605 if (isFlexible_ && expResTest_) {
613 if (params->isParameter(
"Orthogonalization")) {
614 std::string tempOrthoType = params->get(
"Orthogonalization",orthoType_default_);
615 TEUCHOS_TEST_FOR_EXCEPTION( tempOrthoType !=
"DGKS" && tempOrthoType !=
"ICGS" && tempOrthoType !=
"IMGS",
616 std::invalid_argument,
617 "Belos::BlockGmresSolMgr: \"Orthogonalization\" must be either \"DGKS\", \"ICGS\", or \"IMGS\".");
618 if (tempOrthoType != orthoType_) {
619 orthoType_ = tempOrthoType;
621 if (orthoType_==
"DGKS") {
622 if (orthoKappa_ <= 0) {
630 else if (orthoType_==
"ICGS") {
633 else if (orthoType_==
"IMGS") {
640 if (params->isParameter(
"Orthogonalization Constant")) {
641 orthoKappa_ = params->get(
"Orthogonalization Constant",orthoKappa_default_);
644 params_->set(
"Orthogonalization Constant",orthoKappa_);
645 if (orthoType_==
"DGKS") {
646 if (orthoKappa_ > 0 && ortho_ != Teuchos::null) {
653 if (params->isParameter(
"Verbosity")) {
654 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
655 verbosity_ = params->get(
"Verbosity", verbosity_default_);
657 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
661 params_->set(
"Verbosity", verbosity_);
662 if (printer_ != Teuchos::null)
663 printer_->setVerbosity(verbosity_);
667 if (params->isParameter(
"Output Style")) {
668 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
669 outputStyle_ = params->get(
"Output Style", outputStyle_default_);
671 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
675 params_->set(
"Output Style", outputStyle_);
676 if (outputTest_ != Teuchos::null) {
682 if (params->isParameter(
"Output Stream")) {
683 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
686 params_->set(
"Output Stream", outputStream_);
687 if (printer_ != Teuchos::null)
688 printer_->setOStream( outputStream_ );
693 if (params->isParameter(
"Output Frequency")) {
694 outputFreq_ = params->get(
"Output Frequency", outputFreq_default_);
698 params_->set(
"Output Frequency", outputFreq_);
699 if (outputTest_ != Teuchos::null)
700 outputTest_->setOutputFrequency( outputFreq_ );
704 if (printer_ == Teuchos::null) {
709 if (params->isParameter(
"Convergence Tolerance")) {
710 convtol_ = params->get(
"Convergence Tolerance",convtol_default_);
713 params_->set(
"Convergence Tolerance", convtol_);
714 if (impConvTest_ != Teuchos::null)
715 impConvTest_->setTolerance( convtol_ );
716 if (expConvTest_ != Teuchos::null)
717 expConvTest_->setTolerance( convtol_ );
721 if (params->isParameter(
"Implicit Residual Scaling")) {
722 std::string tempImpResScale = Teuchos::getParameter<std::string>( *params,
"Implicit Residual Scaling" );
725 if (impResScale_ != tempImpResScale) {
727 impResScale_ = tempImpResScale;
730 params_->set(
"Implicit Residual Scaling", impResScale_);
731 if (impConvTest_ != Teuchos::null) {
735 catch (std::exception& e) {
743 if (params->isParameter(
"Explicit Residual Scaling")) {
744 std::string tempExpResScale = Teuchos::getParameter<std::string>( *params,
"Explicit Residual Scaling" );
747 if (expResScale_ != tempExpResScale) {
749 expResScale_ = tempExpResScale;
752 params_->set(
"Explicit Residual Scaling", expResScale_);
753 if (expConvTest_ != Teuchos::null) {
757 catch (std::exception& e) {
765 if (params->isParameter(
"Explicit Residual Test")) {
766 expResTest_ = Teuchos::getParameter<bool>( *params,
"Explicit Residual Test" );
769 params_->set(
"Explicit Residual Test", expResTest_);
770 if (expConvTest_ == Teuchos::null) {
776 if (params->isParameter(
"Show Maximum Residual Norm Only")) {
777 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,
"Show Maximum Residual Norm Only");
780 params_->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_);
781 if (impConvTest_ != Teuchos::null)
782 impConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
783 if (expConvTest_ != Teuchos::null)
784 expConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
788 if (ortho_ == Teuchos::null) {
789 if (orthoType_==
"DGKS") {
790 if (orthoKappa_ <= 0) {
798 else if (orthoType_==
"ICGS") {
801 else if (orthoType_==
"IMGS") {
805 TEUCHOS_TEST_FOR_EXCEPTION(orthoType_!=
"ICGS"&&orthoType_!=
"DGKS"&&orthoType_!=
"IMGS",std::logic_error,
806 "Belos::BlockGmresSolMgr(): Invalid orthogonalization type.");
811 if (timerSolve_ == Teuchos::null) {
812 std::string solveLabel = label_ +
": BlockGmresSolMgr total solve time";
813 #ifdef BELOS_TEUCHOS_TIME_MONITOR 814 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
823 template<
class ScalarType,
class MV,
class OP>
835 if (!Teuchos::is_null(problem_->getLeftPrec()) && !isFlexible_) {
842 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
843 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_ ) );
845 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
846 impConvTest_ = tmpImpConvTest;
849 Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
850 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_ ) );
851 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
853 tmpExpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
854 expConvTest_ = tmpExpConvTest;
857 convTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
863 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
864 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_ ) );
866 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
867 impConvTest_ = tmpImpConvTest;
872 Teuchos::RCP<StatusTestImpResNorm_t> tmpImpConvTest =
873 Teuchos::rcp(
new StatusTestImpResNorm_t( convtol_ ) );
875 tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
876 impConvTest_ = tmpImpConvTest;
880 expConvTest_ = impConvTest_;
881 convTest_ = impConvTest_;
885 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
893 std::string solverDesc =
" Block Gmres ";
895 solverDesc =
"Flexible" + solverDesc;
896 outputTest_->setSolverDesc( solverDesc );
905 template<
class ScalarType,
class MV,
class OP>
915 Teuchos::BLAS<int,ScalarType> blas;
918 "Belos::BlockGmresSolMgr::solve(): Linear problem is not a valid object.");
921 "Belos::BlockGmresSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
925 "Belos::BlockGmresSolMgr::solve(): Linear problem does not have a preconditioner required for flexible GMRES, call setRightPrec().");
928 if (!isSTSet_ || (!expResTest_ && !Teuchos::is_null(problem_->getLeftPrec())) ) {
930 "Belos::BlockGmresSolMgr::solve(): Linear problem and requested status tests are incompatible.");
936 int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
938 std::vector<int> currIdx;
941 if ( adaptiveBlockSize_ ) {
942 blockSize_ = numCurrRHS;
943 currIdx.resize( numCurrRHS );
944 for (
int i=0; i<numCurrRHS; ++i)
945 { currIdx[i] = startPtr+i; }
949 currIdx.resize( blockSize_ );
950 for (
int i=0; i<numCurrRHS; ++i)
951 { currIdx[i] = startPtr+i; }
952 for (
int i=numCurrRHS; i<blockSize_; ++i)
957 problem_->setLSIndex( currIdx );
961 Teuchos::ParameterList plist;
962 plist.set(
"Block Size",blockSize_);
965 if (blockSize_*static_cast<ptrdiff_t>(numBlocks_) > dim) {
966 int tmpNumBlocks = 0;
968 tmpNumBlocks = dim / blockSize_;
970 tmpNumBlocks = ( dim - blockSize_) / blockSize_;
972 "Belos::BlockGmresSolMgr::solve(): Warning! Requested Krylov subspace dimension is larger than operator dimension!" 973 << std::endl <<
" The maximum number of blocks allowed for the Krylov subspace will be adjusted to " << tmpNumBlocks << std::endl;
974 plist.set(
"Num Blocks",tmpNumBlocks);
977 plist.set(
"Num Blocks",numBlocks_);
980 outputTest_->reset();
981 loaDetected_ =
false;
984 bool isConverged =
true;
989 Teuchos::RCP<GmresIteration<ScalarType,MV,OP> > block_gmres_iter;
998 #ifdef BELOS_TEUCHOS_TIME_MONITOR 999 Teuchos::TimeMonitor slvtimer(*timerSolve_);
1002 while ( numRHS2Solve > 0 ) {
1005 if (blockSize_*numBlocks_ > dim) {
1006 int tmpNumBlocks = 0;
1007 if (blockSize_ == 1)
1008 tmpNumBlocks = dim / blockSize_;
1010 tmpNumBlocks = ( dim - blockSize_) / blockSize_;
1011 block_gmres_iter->setSize( blockSize_, tmpNumBlocks );
1014 block_gmres_iter->setSize( blockSize_, numBlocks_ );
1017 block_gmres_iter->resetNumIters();
1020 outputTest_->resetNumCalls();
1023 Teuchos::RCP<MV> V_0;
1026 if (currIdx[blockSize_-1] == -1) {
1027 V_0 =
MVT::Clone( *(problem_->getInitResVec()), blockSize_ );
1028 problem_->computeCurrResVec( &*V_0 );
1036 if (currIdx[blockSize_-1] == -1) {
1037 V_0 =
MVT::Clone( *(problem_->getInitPrecResVec()), blockSize_ );
1038 problem_->computeCurrPrecResVec( &*V_0 );
1041 V_0 =
MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1046 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > z_0 =
1047 Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1050 int rank = ortho_->normalize( *V_0, z_0 );
1052 "Belos::BlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors.");
1059 block_gmres_iter->initializeGmres(newstate);
1060 int numRestarts = 0;
1065 block_gmres_iter->iterate();
1072 if ( convTest_->getStatus() ==
Passed ) {
1073 if ( expConvTest_->getLOADetected() ) {
1075 loaDetected_ =
true;
1077 "Belos::BlockGmresSolMgr::solve(): Warning! Solver has experienced a loss of accuracy!" << std::endl;
1078 isConverged =
false;
1087 else if ( maxIterTest_->getStatus() ==
Passed ) {
1089 isConverged =
false;
1097 else if ( block_gmres_iter->getCurSubspaceDim() == block_gmres_iter->getMaxSubspaceDim() ) {
1099 if ( numRestarts >= maxRestarts_ ) {
1100 isConverged =
false;
1105 printer_->stream(
Debug) <<
" Performing restart number " << numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
1108 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1111 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1115 problem_->updateSolution( update,
true );
1124 problem_->computeCurrResVec( &*V_0 );
1126 problem_->computeCurrPrecResVec( &*V_0 );
1129 z_0 = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1132 rank = ortho_->normalize( *V_0, z_0 );
1134 "Belos::BlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors after restart.");
1140 block_gmres_iter->initializeGmres(newstate);
1152 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
1153 "Belos::BlockGmresSolMgr::solve(): Invalid return from BlockGmresIter::iterate().");
1158 if (blockSize_ != 1) {
1159 printer_->stream(
Errors) <<
"Error! Caught std::exception in BlockGmresIter::iterate() at iteration " 1160 << block_gmres_iter->getNumIters() << std::endl
1161 << e.what() << std::endl;
1162 if (convTest_->getStatus() !=
Passed)
1163 isConverged =
false;
1168 block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
1171 sTest_->checkStatus( &*block_gmres_iter );
1172 if (convTest_->getStatus() !=
Passed)
1173 isConverged =
false;
1177 catch (
const std::exception &e) {
1178 printer_->stream(
Errors) <<
"Error! Caught std::exception in BlockGmresIter::iterate() at iteration " 1179 << block_gmres_iter->getNumIters() << std::endl
1180 << e.what() << std::endl;
1189 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1190 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1192 if (update != Teuchos::null)
1197 if ( !Teuchos::is_null(expConvTest_->getSolution()) ) {
1198 Teuchos::RCP<MV> newX = expConvTest_->getSolution();
1199 Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1203 Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1204 problem_->updateSolution( update,
true );
1209 problem_->setCurrLS();
1212 startPtr += numCurrRHS;
1213 numRHS2Solve -= numCurrRHS;
1214 if ( numRHS2Solve > 0 ) {
1215 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1217 if ( adaptiveBlockSize_ ) {
1218 blockSize_ = numCurrRHS;
1219 currIdx.resize( numCurrRHS );
1220 for (
int i=0; i<numCurrRHS; ++i)
1221 { currIdx[i] = startPtr+i; }
1224 currIdx.resize( blockSize_ );
1225 for (
int i=0; i<numCurrRHS; ++i)
1226 { currIdx[i] = startPtr+i; }
1227 for (
int i=numCurrRHS; i<blockSize_; ++i)
1228 { currIdx[i] = -1; }
1231 problem_->setLSIndex( currIdx );
1234 currIdx.resize( numRHS2Solve );
1245 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1250 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1254 numIters_ = maxIterTest_->getNumIters();
1268 const std::vector<MagnitudeType>* pTestValues = NULL;
1270 pTestValues = expConvTest_->getTestValue();
1271 if (pTestValues == NULL || pTestValues->size() < 1) {
1272 pTestValues = impConvTest_->getTestValue();
1277 pTestValues = impConvTest_->getTestValue();
1279 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1280 "Belos::BlockGmresSolMgr::solve(): The implicit convergence test's " 1281 "getTestValue() method returned NULL. Please report this bug to the " 1282 "Belos developers.");
1283 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1284 "Belos::BlockGmresSolMgr::solve(): The implicit convergence test's " 1285 "getTestValue() method returned a vector of length zero. Please report " 1286 "this bug to the Belos developers.");
1291 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1294 if (!isConverged || loaDetected_) {
1301 template<
class ScalarType,
class MV,
class OP>
1304 std::ostringstream oss;
1305 oss <<
"Belos::BlockGmresSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<
">";
1308 oss <<
"Variant=\'Flexible\', ";
1310 oss <<
"Ortho Type='"<<orthoType_<<
"\', Block Size=" <<blockSize_;
1311 oss <<
", Num Blocks=" <<numBlocks_<<
", Max Restarts=" << maxRestarts_;
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.
An extension of the MultiVecTraits class that adds a new vector length method.
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
Method to return description of the block GMRES solver manager.
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.
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 ...
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...
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...
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.