42 #ifndef BELOS_RCG_SOLMGR_HPP
43 #define BELOS_RCG_SOLMGR_HPP
67 #ifdef BELOS_TEUCHOS_TIME_MONITOR
117 template<
class ScalarType,
class MV,
class OP>
187 return Teuchos::tuple(timerSolve_);
277 void sort(std::vector<ScalarType>& dlist,
int n, std::vector<int>& iperm);
280 void initializeStateStorage();
299 static const MagnitudeType convtol_default_;
300 static const int maxIters_default_;
301 static const int blockSize_default_;
302 static const int numBlocks_default_;
303 static const int recycleBlocks_default_;
304 static const bool showMaxResNormOnly_default_;
305 static const int verbosity_default_;
306 static const int outputStyle_default_;
307 static const int outputFreq_default_;
308 static const std::string label_default_;
316 MagnitudeType convtol_;
322 MagnitudeType achievedTol_;
330 int numBlocks_, recycleBlocks_;
331 bool showMaxResNormOnly_;
332 int verbosity_, outputStyle_, outputFreq_;
407 template<
class ScalarType,
class MV,
class OP>
408 const typename RCGSolMgr<ScalarType,MV,OP>::MagnitudeType RCGSolMgr<ScalarType,MV,OP>::convtol_default_ = 1e-8;
410 template<
class ScalarType,
class MV,
class OP>
411 const int RCGSolMgr<ScalarType,MV,OP>::maxIters_default_ = 1000;
413 template<
class ScalarType,
class MV,
class OP>
414 const int RCGSolMgr<ScalarType,MV,OP>::numBlocks_default_ = 25;
416 template<
class ScalarType,
class MV,
class OP>
417 const int RCGSolMgr<ScalarType,MV,OP>::blockSize_default_ = 1;
419 template<
class ScalarType,
class MV,
class OP>
420 const int RCGSolMgr<ScalarType,MV,OP>::recycleBlocks_default_ = 3;
422 template<
class ScalarType,
class MV,
class OP>
423 const bool RCGSolMgr<ScalarType,MV,OP>::showMaxResNormOnly_default_ =
false;
425 template<
class ScalarType,
class MV,
class OP>
426 const int RCGSolMgr<ScalarType,MV,OP>::verbosity_default_ =
Belos::Errors;
428 template<
class ScalarType,
class MV,
class OP>
429 const int RCGSolMgr<ScalarType,MV,OP>::outputStyle_default_ =
Belos::General;
431 template<
class ScalarType,
class MV,
class OP>
432 const int RCGSolMgr<ScalarType,MV,OP>::outputFreq_default_ = -1;
434 template<
class ScalarType,
class MV,
class OP>
435 const std::string RCGSolMgr<ScalarType,MV,OP>::label_default_ =
"Belos";
437 template<
class ScalarType,
class MV,
class OP>
441 template<
class ScalarType,
class MV,
class OP>
447 template<
class ScalarType,
class MV,
class OP>
463 template<
class ScalarType,
class MV,
class OP>
466 outputStream_ = outputStream_default_;
467 convtol_ = convtol_default_;
468 maxIters_ = maxIters_default_;
469 numBlocks_ = numBlocks_default_;
470 recycleBlocks_ = recycleBlocks_default_;
471 verbosity_ = verbosity_default_;
472 outputStyle_= outputStyle_default_;
473 outputFreq_= outputFreq_default_;
474 showMaxResNormOnly_ = showMaxResNormOnly_default_;
475 label_ = label_default_;
486 Alpha_ = Teuchos::null;
487 Beta_ = Teuchos::null;
489 Delta_ = Teuchos::null;
490 UTAU_ = Teuchos::null;
491 LUUTAU_ = Teuchos::null;
492 ipiv_ = Teuchos::null;
493 AUTAU_ = Teuchos::null;
494 rTz_old_ = Teuchos::null;
499 DeltaL2_ = Teuchos::null;
500 AU1TUDeltaL2_ = Teuchos::null;
501 AU1TAU1_ = Teuchos::null;
502 AU1TU1_ = Teuchos::null;
503 AU1TAP_ = Teuchos::null;
506 APTAP_ = Teuchos::null;
507 U1Y1_ = Teuchos::null;
508 PY2_ = Teuchos::null;
509 AUTAP_ = Teuchos::null;
510 AU1TU_ = Teuchos::null;
514 template<
class ScalarType,
class MV,
class OP>
518 if (params_ == Teuchos::null) {
527 maxIters_ = params->
get(
"Maximum Iterations",maxIters_default_);
530 params_->set(
"Maximum Iterations", maxIters_);
531 if (maxIterTest_!=Teuchos::null)
532 maxIterTest_->setMaxIters( maxIters_ );
537 numBlocks_ = params->
get(
"Num Blocks",numBlocks_default_);
539 "Belos::RCGSolMgr: \"Num Blocks\" must be strictly positive.");
542 params_->set(
"Num Blocks", numBlocks_);
547 recycleBlocks_ = params->
get(
"Num Recycled Blocks",recycleBlocks_default_);
549 "Belos::RCGSolMgr: \"Num Recycled Blocks\" must be strictly positive.");
552 "Belos::RCGSolMgr: \"Num Recycled Blocks\" must be less than \"Num Blocks\".");
555 params_->set(
"Num Recycled Blocks", recycleBlocks_);
560 std::string tempLabel = params->
get(
"Timer Label", label_default_);
563 if (tempLabel != label_) {
565 params_->set(
"Timer Label", label_);
566 std::string solveLabel = label_ +
": RCGSolMgr total solve time";
567 #ifdef BELOS_TEUCHOS_TIME_MONITOR
575 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
576 verbosity_ = params->
get(
"Verbosity", verbosity_default_);
578 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
582 params_->set(
"Verbosity", verbosity_);
583 if (printer_ != Teuchos::null)
584 printer_->setVerbosity(verbosity_);
589 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
590 outputStyle_ = params->
get(
"Output Style", outputStyle_default_);
592 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
596 params_->set(
"Output Style", outputStyle_);
597 outputTest_ = Teuchos::null;
602 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
605 params_->set(
"Output Stream", outputStream_);
606 if (printer_ != Teuchos::null)
607 printer_->setOStream( outputStream_ );
613 outputFreq_ = params->
get(
"Output Frequency", outputFreq_default_);
617 params_->set(
"Output Frequency", outputFreq_);
618 if (outputTest_ != Teuchos::null)
619 outputTest_->setOutputFrequency( outputFreq_ );
623 if (printer_ == Teuchos::null) {
632 if (params->
isParameter(
"Convergence Tolerance")) {
633 convtol_ = params->
get(
"Convergence Tolerance",convtol_default_);
636 params_->set(
"Convergence Tolerance", convtol_);
637 if (convTest_ != Teuchos::null)
638 convTest_->setTolerance( convtol_ );
641 if (params->
isParameter(
"Show Maximum Residual Norm Only")) {
642 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,
"Show Maximum Residual Norm Only");
645 params_->set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_);
646 if (convTest_ != Teuchos::null)
647 convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
653 if (maxIterTest_ == Teuchos::null)
657 if (convTest_ == Teuchos::null)
658 convTest_ =
Teuchos::rcp(
new StatusTestResNorm_t( convtol_, 1 ) );
660 if (sTest_ == Teuchos::null)
661 sTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
663 if (outputTest_ == Teuchos::null) {
671 std::string solverDesc =
" Recycling CG ";
672 outputTest_->setSolverDesc( solverDesc );
676 if (timerSolve_ == Teuchos::null) {
677 std::string solveLabel = label_ +
": RCGSolMgr total solve time";
678 #ifdef BELOS_TEUCHOS_TIME_MONITOR
688 template<
class ScalarType,
class MV,
class OP>
697 pl->
set(
"Convergence Tolerance", convtol_default_,
698 "The relative residual tolerance that needs to be achieved by the\n"
699 "iterative solver in order for the linear system to be declared converged.");
700 pl->
set(
"Maximum Iterations", maxIters_default_,
701 "The maximum number of block iterations allowed for each\n"
702 "set of RHS solved.");
703 pl->
set(
"Block Size", blockSize_default_,
704 "Block Size Parameter -- currently must be 1 for RCG");
705 pl->
set(
"Num Blocks", numBlocks_default_,
706 "The length of a cycle (and this max number of search vectors kept)\n");
707 pl->
set(
"Num Recycled Blocks", recycleBlocks_default_,
708 "The number of vectors in the recycle subspace.");
709 pl->
set(
"Verbosity", verbosity_default_,
710 "What type(s) of solver information should be outputted\n"
711 "to the output stream.");
712 pl->
set(
"Output Style", outputStyle_default_,
713 "What style is used for the solver information outputted\n"
714 "to the output stream.");
715 pl->
set(
"Output Frequency", outputFreq_default_,
716 "How often convergence information should be outputted\n"
717 "to the output stream.");
718 pl->
set(
"Output Stream", outputStream_default_,
719 "A reference-counted pointer to the output stream where all\n"
720 "solver output is sent.");
721 pl->
set(
"Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
722 "When convergence information is printed, only show the maximum\n"
723 "relative residual norm when the block size is greater than one.");
724 pl->
set(
"Timer Label", label_default_,
725 "The string to use as a prefix for the timer labels.");
733 template<
class ScalarType,
class MV,
class OP>
738 if (rhsMV == Teuchos::null) {
746 "Belos::RCGSolMgr::initializeStateStorage(): Cannot generate a Krylov basis with dimension larger the operator!");
749 if (P_ == Teuchos::null) {
750 P_ = MVT::Clone( *rhsMV, numBlocks_+2 );
754 if (MVT::GetNumberVecs(*P_) < numBlocks_+2) {
756 P_ = MVT::Clone( *tmp, numBlocks_+2 );
761 if (Ap_ == Teuchos::null)
762 Ap_ = MVT::Clone( *rhsMV, 1 );
765 if (r_ == Teuchos::null)
766 r_ = MVT::Clone( *rhsMV, 1 );
769 if (z_ == Teuchos::null)
770 z_ = MVT::Clone( *rhsMV, 1 );
773 if (U_ == Teuchos::null) {
774 U_ = MVT::Clone( *rhsMV, recycleBlocks_ );
778 if (MVT::GetNumberVecs(*U_) < recycleBlocks_) {
780 U_ = MVT::Clone( *tmp, recycleBlocks_ );
785 if (AU_ == Teuchos::null) {
786 AU_ = MVT::Clone( *rhsMV, recycleBlocks_ );
790 if (MVT::GetNumberVecs(*AU_) < recycleBlocks_) {
792 AU_ = MVT::Clone( *tmp, recycleBlocks_ );
797 if (U1_ == Teuchos::null) {
798 U1_ = MVT::Clone( *rhsMV, recycleBlocks_ );
802 if (MVT::GetNumberVecs(*U1_) < recycleBlocks_) {
804 U1_ = MVT::Clone( *tmp, recycleBlocks_ );
809 if (Alpha_ == Teuchos::null)
812 if ( (Alpha_->numRows() != numBlocks_) || (Alpha_->numCols() != 1) )
813 Alpha_->reshape( numBlocks_, 1 );
817 if (Beta_ == Teuchos::null)
820 if ( (Beta_->numRows() != (numBlocks_+1)) || (Beta_->numCols() != 1) )
821 Beta_->reshape( numBlocks_ + 1, 1 );
825 if (D_ == Teuchos::null)
828 if ( (D_->numRows() != numBlocks_) || (D_->numCols() != 1) )
829 D_->reshape( numBlocks_, 1 );
833 if (Delta_ == Teuchos::null)
836 if ( (Delta_->numRows() != recycleBlocks_) || (Delta_->numCols() != (numBlocks_ + 1)) )
837 Delta_->reshape( recycleBlocks_, numBlocks_ + 1 );
841 if (UTAU_ == Teuchos::null)
844 if ( (UTAU_->numRows() != recycleBlocks_) || (UTAU_->numCols() != recycleBlocks_) )
845 UTAU_->reshape( recycleBlocks_, recycleBlocks_ );
849 if (LUUTAU_ == Teuchos::null)
852 if ( (LUUTAU_->numRows() != recycleBlocks_) || (LUUTAU_->numCols() != recycleBlocks_) )
853 LUUTAU_->reshape( recycleBlocks_, recycleBlocks_ );
857 if (ipiv_ == Teuchos::null)
858 ipiv_ =
Teuchos::rcp(
new std::vector<int>(recycleBlocks_) );
860 if ( (
int)ipiv_->size() != recycleBlocks_ )
861 ipiv_->resize(recycleBlocks_);
865 if (AUTAU_ == Teuchos::null)
868 if ( (AUTAU_->numRows() != recycleBlocks_) || (AUTAU_->numCols() != recycleBlocks_) )
869 AUTAU_->reshape( recycleBlocks_, recycleBlocks_ );
873 if (rTz_old_ == Teuchos::null)
876 if ( (rTz_old_->numRows() != 1) || (rTz_old_->numCols() != 1) )
877 rTz_old_->reshape( 1, 1 );
881 if (F_ == Teuchos::null)
884 if ( (F_->numRows() != (numBlocks_+recycleBlocks_)) || (F_->numCols() != numBlocks_+recycleBlocks_) )
885 F_->reshape( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ );
889 if (G_ == Teuchos::null)
892 if ( (G_->numRows() != (numBlocks_+recycleBlocks_)) || (G_->numCols() != numBlocks_+recycleBlocks_) )
893 G_->reshape( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ );
897 if (Y_ == Teuchos::null)
900 if ( (Y_->numRows() != (numBlocks_+recycleBlocks_)) || (Y_->numCols() != numBlocks_+recycleBlocks_) )
901 Y_->reshape( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ );
905 if (L2_ == Teuchos::null)
908 if ( (L2_->numRows() != (numBlocks_+1)) || (L2_->numCols() != numBlocks_) )
909 L2_->reshape( numBlocks_+1, numBlocks_ );
913 if (DeltaL2_ == Teuchos::null)
916 if ( (DeltaL2_->numRows() != (recycleBlocks_)) || (DeltaL2_->numCols() != (numBlocks_) ) )
917 DeltaL2_->reshape( recycleBlocks_, numBlocks_ );
921 if (AU1TUDeltaL2_ == Teuchos::null)
924 if ( (AU1TUDeltaL2_->numRows() != (recycleBlocks_)) || (AU1TUDeltaL2_->numCols() != (numBlocks_) ) )
925 AU1TUDeltaL2_->reshape( recycleBlocks_, numBlocks_ );
929 if (AU1TAU1_ == Teuchos::null)
932 if ( (AU1TAU1_->numRows() != (recycleBlocks_)) || (AU1TAU1_->numCols() != (recycleBlocks_) ) )
933 AU1TAU1_->reshape( recycleBlocks_, recycleBlocks_ );
937 if (GY_ == Teuchos::null)
940 if ( (GY_->numRows() != (numBlocks_ + recycleBlocks_)) || (GY_->numCols() != (recycleBlocks_) ) )
941 GY_->reshape( numBlocks_+recycleBlocks_, recycleBlocks_ );
945 if (AU1TU1_ == Teuchos::null)
948 if ( (AU1TU1_->numRows() != (recycleBlocks_)) || (AU1TU1_->numCols() != (recycleBlocks_) ) )
949 AU1TU1_->reshape( recycleBlocks_, recycleBlocks_ );
953 if (FY_ == Teuchos::null)
956 if ( (FY_->numRows() != (numBlocks_ + recycleBlocks_)) || (FY_->numCols() != (recycleBlocks_) ) )
957 FY_->reshape( numBlocks_+recycleBlocks_, recycleBlocks_ );
961 if (AU1TAP_ == Teuchos::null)
964 if ( (AU1TAP_->numRows() != (recycleBlocks_)) || (AU1TAP_->numCols() != (numBlocks_) ) )
965 AU1TAP_->reshape( recycleBlocks_, numBlocks_ );
969 if (APTAP_ == Teuchos::null)
972 if ( (APTAP_->numRows() != (numBlocks_)) || (APTAP_->numCols() != (numBlocks_) ) )
973 APTAP_->reshape( numBlocks_, numBlocks_ );
977 if (U1Y1_ == Teuchos::null) {
978 U1Y1_ = MVT::Clone( *rhsMV, recycleBlocks_ );
982 if (MVT::GetNumberVecs(*U1Y1_) < recycleBlocks_) {
984 U1Y1_ = MVT::Clone( *tmp, recycleBlocks_ );
989 if (PY2_ == Teuchos::null) {
990 PY2_ = MVT::Clone( *rhsMV, recycleBlocks_ );
994 if (MVT::GetNumberVecs(*PY2_) < recycleBlocks_) {
996 PY2_ = MVT::Clone( *tmp, recycleBlocks_ );
1001 if (AUTAP_ == Teuchos::null)
1004 if ( (AUTAP_->numRows() != (recycleBlocks_)) || (AUTAP_->numCols() != (numBlocks_) ) )
1005 AUTAP_->reshape( recycleBlocks_, numBlocks_ );
1009 if (AU1TU_ == Teuchos::null)
1012 if ( (AU1TU_->numRows() != (recycleBlocks_)) || (AU1TU_->numCols() != (recycleBlocks_) ) )
1013 AU1TU_->reshape( recycleBlocks_, recycleBlocks_ );
1020 template<
class ScalarType,
class MV,
class OP>
1024 std::vector<int> index(recycleBlocks_);
1035 setParameters(Teuchos::parameterList(*getValidParameters()));
1039 "Belos::RCGSolMgr::solve(): Linear problem is not a valid object.");
1041 "Belos::RCGSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
1044 "Belos::RCGSolMgr::solve(): RCG does not support split preconditioning, only set left or right preconditioner.");
1048 if (problem_->getLeftPrec() != Teuchos::null) {
1049 precObj = Teuchos::rcp_const_cast<OP>(problem_->getLeftPrec());
1051 else if (problem_->getRightPrec() != Teuchos::null) {
1052 precObj = Teuchos::rcp_const_cast<OP>(problem_->getRightPrec());
1056 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
1057 std::vector<int> currIdx(1);
1061 problem_->setLSIndex( currIdx );
1064 ptrdiff_t dim = MVText::GetGlobalLength( *(problem_->getRHS()) );
1065 if (numBlocks_ > dim) {
1066 numBlocks_ = Teuchos::asSafe<int>(dim);
1067 params_->set(
"Num Blocks", numBlocks_);
1069 "Warning! Requested Krylov subspace dimension is larger than operator dimension!" << std::endl <<
1070 " The maximum number of blocks allowed for the Krylov subspace will be adjusted to " << numBlocks_ << std::endl;
1074 initializeStateStorage();
1078 plist.
set(
"Num Blocks",numBlocks_);
1079 plist.
set(
"Recycled Blocks",recycleBlocks_);
1082 outputTest_->reset();
1085 bool isConverged =
true;
1089 index.resize(recycleBlocks_);
1090 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1092 index.resize(recycleBlocks_);
1093 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1096 problem_->applyOp( *Utmp, *AUtmp );
1099 MVT::MvTransMv( one, *Utmp, *AUtmp, UTAUtmp );
1102 if ( precObj != Teuchos::null ) {
1103 index.resize(recycleBlocks_);
1104 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1105 index.resize(recycleBlocks_);
1106 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1108 OPT::Apply( *precObj, *AUtmp, *PCAU );
1109 MVT::MvTransMv( one, *AUtmp, *PCAU, AUTAUtmp );
1111 MVT::MvTransMv( one, *AUtmp, *AUtmp, AUTAUtmp );
1123 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1127 while ( numRHS2Solve > 0 ) {
1130 if (printer_->isVerbosity(
Debug ) ) {
1131 if (existU_) printer_->print(
Debug,
"Using recycle space generated from previous call to solve()." );
1132 else printer_->print(
Debug,
"No recycle space exists." );
1136 rcg_iter->resetNumIters();
1139 rcg_iter->setSize( recycleBlocks_, numBlocks_ );
1142 outputTest_->resetNumCalls();
1151 problem_->computeCurrResVec( &*r_ );
1157 index.resize(recycleBlocks_);
1158 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1160 MVT::MvTransMv( one, *Utmp, *r_, Utr );
1163 LUUTAUtmp.
assign(UTAUtmp);
1167 "Belos::RCGSolMgr::solve(): LAPACK GESV failed to compute a solution.");
1170 MVT::MvTimesMatAddMv( one, *Utmp, Utr, one, *problem_->getCurrLHSVec() );
1173 index.resize(recycleBlocks_);
1174 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1176 MVT::MvTimesMatAddMv( -one, *AUtmp, Utr, one, *r_ );
1179 if ( precObj != Teuchos::null ) {
1180 OPT::Apply( *precObj, *r_, *z_ );
1186 MVT::MvTransMv( one, *r_, *z_, *rTz_old_ );
1191 index.resize(recycleBlocks_);
1192 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1194 MVT::MvTransMv( one, *AUtmp, *z_, mu );
1200 "Belos::RCGSolMgr::solve(): LAPACK GETRS failed to compute a solution.");
1205 MVT::MvAddMv(one,*z_,zero,*z_,*Ptmp);
1206 MVT::MvTimesMatAddMv( -one, *U_, mu, one, *Ptmp );
1212 MVT::MvAddMv(one,*z_,zero,*z_,*Ptmp);
1219 index.resize( numBlocks_+1 );
1220 for (
int ii=0; ii<(numBlocks_+1); ++ii) { index[ii] = ii; }
1221 newstate.
P = MVT::CloneViewNonConst( *P_, index );
1222 index.resize( recycleBlocks_ );
1223 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1224 newstate.
U = MVT::CloneViewNonConst( *U_, index );
1225 index.resize( recycleBlocks_ );
1226 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1227 newstate.
AU = MVT::CloneViewNonConst( *AU_, index );
1238 newstate.
existU = existU_;
1239 newstate.
ipiv = ipiv_;
1242 rcg_iter->initialize(newstate);
1248 rcg_iter->iterate();
1255 if ( convTest_->getStatus() ==
Passed ) {
1264 else if ( maxIterTest_->getStatus() ==
Passed ) {
1266 isConverged =
false;
1274 else if ( rcg_iter->getCurSubspaceDim() == rcg_iter->getMaxSubspaceDim() ) {
1279 if (recycleBlocks_ > 0) {
1290 for (
int ii=0;ii<numBlocks_;ii++) {
1291 Gtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii,0));
1293 Gtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1294 Gtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1296 Ftmp(ii,ii) = Dtmp(ii,0);
1301 getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1304 index.resize( numBlocks_ );
1305 for (
int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii; }
1307 index.resize( recycleBlocks_ );
1308 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1310 MVT::MvTimesMatAddMv( one, *Ptmp, Ytmp, zero, *U1tmp );
1330 ScalarType alphatmp = -1.0 / Alphatmp(numBlocks_-1,0);
1331 for (
int ii=0; ii<recycleBlocks_; ++ii) {
1332 AU1TAPtmp(ii,0) = Ytmp(numBlocks_-1,ii) * alphatmp;
1340 lastBeta = numBlocks_-1;
1349 AU1TAPtmp.
scale(Dtmp(0,0));
1355 for (
int ii=0; ii<numBlocks_; ii++) {
1356 APTAPtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii+1,0));
1358 APTAPtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1359 APTAPtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1374 for(
int ii=0;ii<numBlocks_;ii++) {
1375 F22(ii,ii) = Dtmp(ii,0);
1388 for (
int ii=0;ii<recycleBlocks_;++ii)
1389 for (
int jj=0;jj<numBlocks_;++jj)
1390 G21(jj,ii) = G12(ii,jj);
1395 getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1398 index.resize( numBlocks_ );
1399 for (
int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii+1; }
1401 index.resize( recycleBlocks_ );
1402 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1405 index.resize( recycleBlocks_ );
1406 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1408 index.resize( recycleBlocks_ );
1409 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1412 MVT::MvTimesMatAddMv( one, *Ptmp, Y2, zero, *PY2tmp );
1413 MVT::MvTimesMatAddMv( one, *U1tmp, Y1, zero, *U1Y1tmp );
1414 MVT::MvAddMv(one,*U1Y1tmp, one, *PY2tmp, *U1tmp);
1426 ScalarType alphatmp = -1.0 / Alphatmp(numBlocks_-1,0);
1427 for (
int ii=0; ii<recycleBlocks_; ++ii) {
1428 AU1TAPtmp(ii,0) = Ytmp(numBlocks_+recycleBlocks_-1,ii) * alphatmp;
1438 lastp = numBlocks_+1;
1439 lastBeta = numBlocks_;
1450 for (
int ii=0; ii<numBlocks_; ii++) {
1451 APTAPtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii,0));
1453 APTAPtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1454 APTAPtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1460 for(
int ii=0;ii<numBlocks_;ii++) {
1461 L2tmp(ii,ii) = 1./Alphatmp(ii,0);
1462 L2tmp(ii+1,ii) = -1./Alphatmp(ii,0);
1483 for(
int ii=0;ii<numBlocks_;ii++) {
1484 F22(ii,ii) = Dtmp(ii,0);
1497 for (
int ii=0;ii<recycleBlocks_;++ii)
1498 for (
int jj=0;jj<numBlocks_;++jj)
1499 G21(jj,ii) = G12(ii,jj);
1504 getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1507 index.resize( recycleBlocks_ );
1508 for (
int ii=0; ii<(recycleBlocks_); ++ii) { index[ii] = ii; }
1510 index.resize( numBlocks_ );
1511 for (
int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii; }
1513 index.resize( recycleBlocks_ );
1514 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1517 index.resize( recycleBlocks_ );
1518 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1521 index.resize( recycleBlocks_ );
1522 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1524 MVT::MvTimesMatAddMv( one, *Ptmp, Y2, zero, *PY2tmp );
1525 MVT::MvTimesMatAddMv( one, *Utmp, Y1, zero, *UY1tmp );
1526 MVT::MvAddMv(one,*UY1tmp, one, *PY2tmp, *U1tmp);
1544 AU1TUtmp.
assign(UTAUtmp);
1547 dold = Dtmp(numBlocks_-1,0);
1554 lastBeta = numBlocks_-1;
1561 for (
int ii=0; ii<numBlocks_; ii++) {
1562 APTAPtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii+1,0));
1564 APTAPtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1565 APTAPtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1570 for(
int ii=0;ii<numBlocks_;ii++) {
1571 L2tmp(ii,ii) = 1./Alphatmp(ii,0);
1572 L2tmp(ii+1,ii) = -1./Alphatmp(ii,0);
1588 ScalarType val = dold * (-Betatmp(0,0)/Alphatmp(0,0));
1589 for(
int ii=0;ii<recycleBlocks_;ii++) {
1590 AU1TAPtmp(ii,0) += Y2(numBlocks_-1,ii)*val;
1596 AU1TUtmp.
assign(Y1TAU1TU);
1606 for(
int ii=0;ii<numBlocks_;ii++) {
1607 F22(ii,ii) = Dtmp(ii,0);
1620 for (
int ii=0;ii<recycleBlocks_;++ii)
1621 for (
int jj=0;jj<numBlocks_;++jj)
1622 G21(jj,ii) = G12(ii,jj);
1627 getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1630 index.resize( numBlocks_ );
1631 for (
int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii+1; }
1633 index.resize( recycleBlocks_ );
1634 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1636 index.resize( recycleBlocks_ );
1637 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1639 index.resize( recycleBlocks_ );
1640 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1642 MVT::MvTimesMatAddMv( one, *Ptmp, Y2, zero, *PY2tmp );
1643 MVT::MvTimesMatAddMv( one, *U1tmp, Y1, zero, *U1Y1tmp );
1644 MVT::MvAddMv(one,*U1Y1tmp, one, *PY2tmp, *U1tmp);
1659 dold = Dtmp(numBlocks_-1,0);
1662 lastp = numBlocks_+1;
1663 lastBeta = numBlocks_;
1673 index[0] = lastp-1; index[1] = lastp;
1675 index[0] = 0; index[1] = 1;
1676 MVT::SetBlock(*Ptmp2,index,*P_);
1679 (*Beta_)(0,0) = (*Beta_)(lastBeta,0);
1689 newstate.
P = Teuchos::null;
1690 index.resize( numBlocks_+1 );
1691 for (
int ii=0; ii<(numBlocks_+1); ++ii) { index[ii] = ii+1; }
1692 newstate.
P = MVT::CloneViewNonConst( *P_, index );
1694 newstate.
Beta = Teuchos::null;
1697 newstate.
Delta = Teuchos::null;
1703 rcg_iter->initialize(newstate);
1716 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
1717 "Belos::RCGSolMgr::solve(): Invalid return from RCGIter::iterate().");
1720 catch (
const std::exception &e) {
1721 printer_->stream(
Errors) <<
"Error! Caught std::exception in RCGIter::iterate() at iteration "
1722 << rcg_iter->getNumIters() << std::endl
1723 << e.what() << std::endl;
1729 problem_->setCurrLS();
1733 if ( numRHS2Solve > 0 ) {
1736 problem_->setLSIndex( currIdx );
1739 currIdx.resize( numRHS2Solve );
1745 index.resize(recycleBlocks_);
1746 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1747 MVT::SetBlock(*U1_,index,*U_);
1750 if (numRHS2Solve > 0) {
1752 newstate.
P = Teuchos::null;
1753 newstate.
Ap = Teuchos::null;
1754 newstate.
r = Teuchos::null;
1755 newstate.
z = Teuchos::null;
1756 newstate.
U = Teuchos::null;
1757 newstate.
AU = Teuchos::null;
1758 newstate.
Alpha = Teuchos::null;
1759 newstate.
Beta = Teuchos::null;
1760 newstate.
D = Teuchos::null;
1761 newstate.
Delta = Teuchos::null;
1762 newstate.
LUUTAU = Teuchos::null;
1763 newstate.
ipiv = Teuchos::null;
1764 newstate.
rTz_old = Teuchos::null;
1767 index.resize(recycleBlocks_);
1768 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1770 index.resize(recycleBlocks_);
1771 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1774 problem_->applyOp( *Utmp, *AUtmp );
1777 MVT::MvTransMv( one, *Utmp, *AUtmp, UTAUtmp );
1780 if ( precObj != Teuchos::null ) {
1781 index.resize(recycleBlocks_);
1782 for (
int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1783 index.resize(recycleBlocks_);
1784 for (
int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1786 OPT::Apply( *precObj, *AUtmp, *LeftPCAU );
1787 MVT::MvTransMv( one, *AUtmp, *LeftPCAU, AUTAUtmp );
1789 MVT::MvTransMv( one, *AUtmp, *AUtmp, AUTAUtmp );
1802 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1811 numIters_ = maxIterTest_->getNumIters();
1815 using Teuchos::rcp_dynamic_cast;
1818 const std::vector<MagnitudeType>* pTestValues =
1819 rcp_dynamic_cast<conv_test_type>(convTest_)->getTestValue();
1821 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1822 "Belos::RCGSolMgr::solve(): The convergence test's getTestValue() "
1823 "method returned NULL. Please report this bug to the Belos developers.");
1825 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1826 "Belos::RCGSolMgr::solve(): The convergence test's getTestValue() "
1827 "method returned a vector of length zero. Please report this bug to the "
1828 "Belos developers.");
1833 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1843 template<
class ScalarType,
class MV,
class OP>
1854 std::vector<MagnitudeType> w(n);
1857 std::vector<int> iperm(n);
1864 std::vector<ScalarType> work(1);
1872 lapack.
SYGV(itype, jobz, uplo, n, G2.values(), G2.stride(), F2.values(), F2.stride(), &w[0], &work[0], lwork, &info);
1874 "Belos::RCGSolMgr::solve(): LAPACK SYGV failed to query optimal work size.");
1875 lwork = (int)work[0];
1877 lapack.
SYGV(itype, jobz, uplo, n, G2.values(), G2.stride(), F2.values(), F2.stride(), &w[0], &work[0], lwork, &info);
1879 "Belos::RCGSolMgr::solve(): LAPACK SYGV failed to compute eigensolutions.");
1883 this->sort(w,n,iperm);
1886 for(
int i=0; i<recycleBlocks_; i++ ) {
1887 for(
int j=0; j<n; j++ ) {
1888 Y(j,i) = G2(j,iperm[i]);
1895 template<
class ScalarType,
class MV,
class OP>
1896 void RCGSolMgr<ScalarType,MV,OP>::sort(std::vector<ScalarType>& dlist,
int n, std::vector<int>& iperm)
1898 int l, r, j, i, flag;
1927 if (dlist[j] > dlist[j - 1]) j = j + 1;
1929 if (dlist[j - 1] > dK) {
1930 dlist[i - 1] = dlist[j - 1];
1931 iperm[i - 1] = iperm[j - 1];
1944 dlist[r] = dlist[0];
1945 iperm[r] = iperm[0];
1960 template<
class ScalarType,
class MV,
class OP>
1963 std::ostringstream oss;
ScalarType * values() const
Teuchos::RCP< MV > r
The current residual.
Collection of types and exceptions used within the Belos solvers.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > rTz_old
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
Teuchos::RCP< MV > P
The current Krylov basis.
Teuchos::RCP< std::vector< int > > ipiv
Data from LU factorization of U^T A U.
Class which manages the output and verbosity of the Belos solvers.
void SYGV(const OrdinalType itype, const char JOBZ, const char UPLO, const OrdinalType n, ScalarType *A, const OrdinalType lda, ScalarType *B, const OrdinalType ldb, ScalarType *W, ScalarType *WORK, const OrdinalType lwork, OrdinalType *info) const
bool is_null(const boost::shared_ptr< T > &p)
RCGSolMgrRecyclingFailure is thrown when any problem occurs in using/creating the recycling subspace...
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
Teuchos::RCP< MV > U
The recycled subspace and its image.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > LUUTAU
The LU factorization of the matrix U^T A U.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
A factory class for generating StatusTestOutput objects.
The Belos::RCGSolMgr provides a powerful and fully-featured solver manager over the RCG (Recycling Co...
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Beta
This class implements the RCG iteration, where a single-std::vector Krylov subspace is constructed...
void GETRS(const char TRANS, const OrdinalType n, const OrdinalType nrhs, const ScalarType *A, const OrdinalType lda, const OrdinalType *IPIV, ScalarType *B, const OrdinalType ldb, OrdinalType *info) const
An implementation of StatusTestResNorm using a family of residual norms.
int scale(const ScalarType alpha)
An extension of the MultiVecTraits class that adds a new vector length method.
Belos::StatusTest class for specifying a maximum number of iterations.
static std::string name()
std::string description() const
Method to return description of the RCG solver manager.
int getNumIters() const
Get the iteration count for the most recent call to solve().
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the parameters the solver manager should use to solve the linear problem.
A factory class for generating StatusTestOutput objects.
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
RCGSolMgrLinearProblemFailure(const std::string &what_arg)
RCGSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i.e.
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="")
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
bool isParameter(const std::string &name) const
Structure to contain pointers to RCGIter state variables.
Belos concrete class for performing the RCG iteration.
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class...
A Belos::StatusTest class for specifying a maximum number of iterations.
ResetType
How to reset the solver.
bool existU
Flag to indicate the recycle space should be used.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Pure virtual base class which describes the basic interface for a solver manager. ...
Teuchos::RCP< MV > z
The current preconditioned residual.
Teuchos::RCP< MV > Ap
A times current search vector.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
bool isLOADetected() const
Return whether a loss of accuracy was detected by this solver during the most current solve...
RCGSolMgr()
Empty constructor for RCGSolMgr. This constructor takes no arguments and sets the default values for ...
ReturnType
Whether the Belos solve converged for all linear systems.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Iterated Classical Gram-Schmidt (ICGS) implementation of the Belos::OrthoManager class.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Alpha
Coefficients arising in RCG iteration.
OrdinalType numCols() const
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
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.
virtual ~RCGSolMgr()
Destructor.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
int curDim
The current dimension of the reduction.
RCGSolMgrLAPACKFailure(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.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > D
Parent class to all Belos exceptions.
void GESV(const OrdinalType n, const OrdinalType nrhs, ScalarType *A, const OrdinalType lda, OrdinalType *IPIV, ScalarType *B, const OrdinalType ldb, OrdinalType *info) const
RCGSolMgrRecyclingFailure(const std::string &what_arg)
Belos header file which uses auto-configuration information to include necessary C++ headers...
RCGSolMgrLAPACKFailure is thrown when a nonzero value is retuned from an LAPACK call.
SerialDenseMatrix< OrdinalType, ScalarType > & assign(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Delta
Solutions to local least-squares problems.
OrdinalType stride() const