45 #ifndef BELOS_BLOCK_GCRODR_SOLMGR_HPP 46 #define BELOS_BLOCK_GCRODR_SOLMGR_HPP 62 #include "Teuchos_BLAS.hpp" 63 #include "Teuchos_LAPACK.hpp" 64 #include "Teuchos_as.hpp" 65 #ifdef BELOS_TEUCHOS_TIME_MONITOR 66 #include "Teuchos_TimeMonitor.hpp" 67 #endif // BELOS_TEUCHOS_TIME_MONITOR 126 template<
class ScalarType,
class MV,
class OP>
133 typedef Teuchos::ScalarTraits<ScalarType> SCT;
134 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
135 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
136 typedef Teuchos::ScalarTraits<MagnitudeType> SMT;
138 typedef Teuchos::SerialDenseMatrix<int,ScalarType> SDM;
139 typedef Teuchos::SerialDenseVector<int,ScalarType> SDV;
178 const Teuchos::RCP<Teuchos::ParameterList> &pl);
188 std::string description()
const;
202 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const;
220 TEUCHOS_TEST_FOR_EXCEPTION(problem.is_null(), std::invalid_argument,
221 "Belos::BlockGCRODRSolMgr::setProblem: The input LinearProblem cannot be null.");
224 if (! problem->isProblemSet()) {
225 const bool success = problem->setProblem();
226 TEUCHOS_TEST_FOR_EXCEPTION(success, std::runtime_error,
227 "Belos::BlockGCRODRSolMgr::setProblem: Calling the input LinearProblem's setProblem() method failed. This likely means that the " 228 "LinearProblem has a missing (null) matrix A, solution vector X, or right-hand side vector B. Please set these items in the LinearProblem and try again.");
235 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms );
250 problem_->setProblem();
288 void initializeStateStorage();
306 int getHarmonicVecsKryl (
int m,
const SDM& HH, SDM& PP);
311 int getHarmonicVecsAugKryl (
int keff,
314 const Teuchos::RCP<const MV>& VV,
318 void sort (std::vector<ScalarType>& dlist,
int n, std::vector<int>& iperm);
321 Teuchos::LAPACK<int,ScalarType> lapack;
324 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
327 Teuchos::RCP<OutputManager<ScalarType> > printer_;
328 Teuchos::RCP<std::ostream> outputStream_;
331 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
332 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
333 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
334 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > expConvTest_, impConvTest_;
335 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
338 ortho_factory_type orthoFactory_;
345 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > ortho_;
348 Teuchos::RCP<Teuchos::ParameterList> params_;
360 mutable Teuchos::RCP<const Teuchos::ParameterList> defaultParams_;
363 static const bool adaptiveBlockSize_default_;
364 static const std::string recycleMethod_default_;
367 MagnitudeType convTol_, orthoKappa_;
368 int blockSize_, maxRestarts_, maxIters_, numIters_;
369 int verbosity_, outputStyle_, outputFreq_;
370 bool adaptiveBlockSize_;
371 std::string orthoType_, recycleMethod_;
372 std::string impResScale_, expResScale_;
380 int numBlocks_, recycledBlocks_;
391 Teuchos::RCP<MV> U_, C_;
394 Teuchos::RCP<MV> U1_, C1_;
397 Teuchos::RCP<SDM > G_;
398 Teuchos::RCP<SDM > H_;
399 Teuchos::RCP<SDM > B_;
400 Teuchos::RCP<SDM > PP_;
401 Teuchos::RCP<SDM > HP_;
402 std::vector<ScalarType> tau_;
403 std::vector<ScalarType> work_;
404 Teuchos::RCP<SDM > F_;
405 std::vector<int> ipiv_;
408 Teuchos::RCP<Teuchos::Time> timerSolve_;
417 bool builtRecycleSpace_;
423 template<
class ScalarType,
class MV,
class OP>
426 template<
class ScalarType,
class MV,
class OP>
433 template<
class ScalarType,
class MV,
class OP>
439 template<
class ScalarType,
class MV,
class OP>
442 const Teuchos::RCP<Teuchos::ParameterList> &pl ) {
447 TEUCHOS_TEST_FOR_EXCEPTION(problem.is_null(), std::invalid_argument,
448 "Belos::BlockGCRODR constructor: The solver manager's constructor needs " 449 "the linear problem argument 'problem' to be nonnull.");
459 template<
class ScalarType,
class MV,
class OP>
461 adaptiveBlockSize_ = adaptiveBlockSize_default_;
462 recycleMethod_ = recycleMethod_default_;
464 loaDetected_ =
false;
465 builtRecycleSpace_ =
false;
536 template<
class ScalarType,
class MV,
class OP>
538 std::ostringstream oss;
539 oss <<
"Belos::BlockGCRODRSolMgr<" << SCT::name() <<
", ...>";
541 oss <<
"Ortho Type='"<<orthoType_ ;
542 oss <<
", Num Blocks=" <<numBlocks_;
543 oss <<
", Block Size=" <<blockSize_;
544 oss <<
", Num Recycle Blocks=" << recycledBlocks_;
545 oss <<
", Max Restarts=" << maxRestarts_;
550 template<
class ScalarType,
class MV,
class OP>
551 Teuchos::RCP<const Teuchos::ParameterList>
553 using Teuchos::ParameterList;
554 using Teuchos::parameterList;
556 using Teuchos::rcpFromRef;
558 if (defaultParams_.is_null()) {
559 RCP<ParameterList> pl = parameterList ();
561 const MagnitudeType convTol = SMT::squareroot (SCT::magnitude (SCT::eps()));
562 const int maxRestarts = 1000;
563 const int maxIters = 5000;
564 const int blockSize = 2;
565 const int numBlocks = 100;
566 const int numRecycledBlocks = 25;
569 const int outputFreq = 1;
570 RCP<std::ostream> outputStream = rcpFromRef (std::cout);
571 const std::string impResScale (
"Norm of Preconditioned Initial Residual");
572 const std::string expResScale (
"Norm of Initial Residual");
573 const std::string timerLabel (
"Belos");
574 const std::string orthoType (
"DGKS");
575 RCP<const ParameterList> orthoParams = orthoFactory_.getDefaultParameters (orthoType);
582 const MagnitudeType orthoKappa = -SCT::one();
585 pl->set (
"Convergence Tolerance", convTol,
586 "The tolerance that the solver needs to achieve in order for " 587 "the linear system(s) to be declared converged. The meaning " 588 "of this tolerance depends on the convergence test details.");
589 pl->set(
"Maximum Restarts", maxRestarts,
590 "The maximum number of restart cycles (not counting the first) " 591 "allowed for each set of right-hand sides solved.");
592 pl->set(
"Maximum Iterations", maxIters,
593 "The maximum number of iterations allowed for each set of " 594 "right-hand sides solved.");
595 pl->set(
"Block Size", blockSize,
596 "How many linear systems to solve at once.");
597 pl->set(
"Num Blocks", numBlocks,
598 "The maximum number of blocks allowed in the Krylov subspace " 599 "for each set of right-hand sides solved. This includes the " 600 "initial block. Total Krylov basis storage, not counting the " 601 "recycled subspace, is \"Num Blocks\" times \"Block Size\".");
602 pl->set(
"Num Recycled Blocks", numRecycledBlocks,
603 "The maximum number of vectors in the recycled subspace." );
604 pl->set(
"Verbosity", verbosity,
605 "What type(s) of solver information should be written " 606 "to the output stream.");
607 pl->set(
"Output Style", outputStyle,
608 "What style is used for the solver information to write " 609 "to the output stream.");
610 pl->set(
"Output Frequency", outputFreq,
611 "How often convergence information should be written " 612 "to the output stream.");
613 pl->set(
"Output Stream", outputStream,
614 "A reference-counted pointer to the output stream where all " 615 "solver output is sent.");
616 pl->set(
"Implicit Residual Scaling", impResScale,
617 "The type of scaling used in the implicit residual convergence test.");
618 pl->set(
"Explicit Residual Scaling", expResScale,
619 "The type of scaling used in the explicit residual convergence test.");
620 pl->set(
"Timer Label", timerLabel,
621 "The string to use as a prefix for the timer labels.");
623 pl->set(
"Orthogonalization", orthoType,
624 "The orthogonalization method to use. Valid options: " +
625 orthoFactory_.validNamesString());
626 pl->set (
"Orthogonalization Parameters", *orthoParams,
627 "Sublist of parameters specific to the orthogonalization method to use.");
628 pl->set(
"Orthogonalization Constant", orthoKappa,
629 "When using DGKS orthogonalization: the \"depTol\" constant, used " 630 "to determine whether another step of classical Gram-Schmidt is " 631 "necessary. Otherwise ignored. Nonpositive values are ignored.");
634 return defaultParams_;
637 template<
class ScalarType,
class MV,
class OP>
641 using Teuchos::isParameterType;
642 using Teuchos::getParameter;
644 using Teuchos::ParameterList;
645 using Teuchos::parameterList;
648 using Teuchos::rcp_dynamic_cast;
649 using Teuchos::rcpFromRef;
650 using Teuchos::Exceptions::InvalidParameter;
651 using Teuchos::Exceptions::InvalidParameterName;
652 using Teuchos::Exceptions::InvalidParameterType;
655 RCP<const ParameterList> defaultParams = getValidParameters();
657 if (params.is_null()) {
662 params_ = parameterList (*defaultParams);
674 params->validateParametersAndSetDefaults (*defaultParams);
690 const int maxRestarts = params_->get<
int> (
"Maximum Restarts");
691 TEUCHOS_TEST_FOR_EXCEPTION(maxRestarts <= 0, std::invalid_argument,
692 "Belos::BlockGCRODRSolMgr: The \"Maximum Restarts\" parameter " 693 "must be nonnegative, but you specified a negative value of " 694 << maxRestarts <<
".");
696 const int maxIters = params_->get<
int> (
"Maximum Iterations");
697 TEUCHOS_TEST_FOR_EXCEPTION(maxIters <= 0, std::invalid_argument,
698 "Belos::BlockGCRODRSolMgr: The \"Maximum Iterations\" parameter " 699 "must be positive, but you specified a nonpositive value of " 702 const int numBlocks = params_->get<
int> (
"Num Blocks");
703 TEUCHOS_TEST_FOR_EXCEPTION(numBlocks <= 0, std::invalid_argument,
704 "Belos::BlockGCRODRSolMgr: The \"Num Blocks\" parameter must be " 705 "positive, but you specified a nonpositive value of " << numBlocks
708 const int blockSize = params_->get<
int> (
"Block Size");
709 TEUCHOS_TEST_FOR_EXCEPTION(blockSize <= 0, std::invalid_argument,
710 "Belos::BlockGCRODRSolMgr: The \"Block Size\" parameter must be " 711 "positive, but you specified a nonpositive value of " << blockSize
714 const int recycledBlocks = params_->get<
int> (
"Num Recycled Blocks");
715 TEUCHOS_TEST_FOR_EXCEPTION(recycledBlocks <= 0, std::invalid_argument,
716 "Belos::BlockGCRODRSolMgr: The \"Num Recycled Blocks\" parameter must " 717 "be positive, but you specified a nonpositive value of " 718 << recycledBlocks <<
".");
719 TEUCHOS_TEST_FOR_EXCEPTION(recycledBlocks >= numBlocks,
720 std::invalid_argument,
"Belos::BlockGCRODRSolMgr: The \"Num Recycled " 721 "Blocks\" parameter must be less than the \"Num Blocks\" parameter, " 722 "but you specified \"Num Recycled Blocks\" = " << recycledBlocks
723 <<
" and \"Num Blocks\" = " << numBlocks <<
".");
727 maxRestarts_ = maxRestarts;
728 maxIters_ = maxIters;
729 numBlocks_ = numBlocks;
730 blockSize_ = blockSize;
731 recycledBlocks_ = recycledBlocks;
738 std::string tempLabel = params_->get<std::string> (
"Timer Label");
739 const bool labelChanged = (tempLabel != label_);
741 #ifdef BELOS_TEUCHOS_TIME_MONITOR 742 std::string solveLabel = label_ +
": BlockGCRODRSolMgr total solve time";
743 if (timerSolve_.is_null()) {
745 timerSolve_ = Teuchos::TimeMonitor::getNewCounter (solveLabel);
746 }
else if (labelChanged) {
752 Teuchos::TimeMonitor::clearCounter (solveLabel);
753 timerSolve_ = Teuchos::TimeMonitor::getNewCounter (solveLabel);
755 #endif // BELOS_TEUCHOS_TIME_MONITOR 761 if (params_->isParameter (
"Verbosity")) {
762 if (isParameterType<int> (*params_,
"Verbosity")) {
763 verbosity_ = params_->get<
int> (
"Verbosity");
766 verbosity_ = (int) getParameter<MsgType> (*params_,
"Verbosity");
773 if (params_->isParameter (
"Output Style")) {
774 if (isParameterType<int> (*params_,
"Output Style")) {
775 outputStyle_ = params_->get<
int> (
"Output Style");
778 outputStyle_ = (int) getParameter<OutputType> (*params_,
"Output Style");
806 if (params_->isParameter (
"Output Stream")) {
808 outputStream_ = getParameter<RCP<std::ostream> > (*params_,
"Output Stream");
810 catch (InvalidParameter&) {
811 outputStream_ = rcpFromRef (std::cout);
818 if (outputStream_.is_null()) {
819 outputStream_ = rcp (
new Teuchos::oblackholestream);
823 outputFreq_ = params_->get<
int> (
"Output Frequency");
826 if (! outputTest_.is_null()) {
827 outputTest_->setOutputFrequency (outputFreq_);
835 if (printer_.is_null()) {
838 printer_->setVerbosity (verbosity_);
839 printer_->setOStream (outputStream_);
848 bool changedOrthoType =
false;
849 if (params_->isParameter (
"Orthogonalization")) {
850 const std::string& tempOrthoType =
851 params_->get<std::string> (
"Orthogonalization");
853 if (! orthoFactory_.isValidName (tempOrthoType)) {
854 std::ostringstream os;
855 os <<
"Belos::BlockGCRODRSolMgr: Invalid orthogonalization name \"" 856 << tempOrthoType <<
"\". The following are valid options " 857 <<
"for the \"Orthogonalization\" name parameter: ";
858 orthoFactory_.printValidNames (os);
859 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument, os.str());
861 if (tempOrthoType != orthoType_) {
862 changedOrthoType =
true;
863 orthoType_ = tempOrthoType;
880 RCP<ParameterList> orthoParams = sublist (params,
"Orthogonalization Parameters",
true);
881 TEUCHOS_TEST_FOR_EXCEPTION(orthoParams.is_null(), std::logic_error,
882 "Failed to get orthogonalization parameters. " 883 "Please report this bug to the Belos developers.");
909 ortho_ = orthoFactory_.makeMatOrthoManager (orthoType_, null, printer_,
910 label_, orthoParams);
920 bool gotValidOrthoKappa =
false;
921 if (params_->isParameter (
"Orthogonalization Constant")) {
922 const MagnitudeType orthoKappa =
923 params_->get<MagnitudeType> (
"Orthogonalization Constant");
924 if (orthoKappa > 0) {
925 orthoKappa_ = orthoKappa;
926 gotValidOrthoKappa =
true;
928 if (orthoType_ ==
"DGKS" && ! ortho_.is_null()) {
934 rcp_dynamic_cast<ortho_man_type>(ortho_)->setDepTol (orthoKappa_);
944 convTol_ = params_->get<MagnitudeType> (
"Convergence Tolerance");
945 if (! impConvTest_.is_null()) {
948 if (! expConvTest_.is_null()) {
949 expConvTest_->setTolerance (convTol_);
953 if (params_->isParameter (
"Implicit Residual Scaling")) {
954 std::string tempImpResScale =
955 getParameter<std::string> (*params_,
"Implicit Residual Scaling");
958 if (impResScale_ != tempImpResScale) {
960 impResScale_ = tempImpResScale;
962 if (! impConvTest_.is_null()) {
975 if (params_->isParameter(
"Explicit Residual Scaling")) {
976 std::string tempExpResScale =
977 getParameter<std::string> (*params_,
"Explicit Residual Scaling");
980 if (expResScale_ != tempExpResScale) {
982 expResScale_ = tempExpResScale;
984 if (! expConvTest_.is_null()) {
1002 if (maxIterTest_.is_null()) {
1005 maxIterTest_->setMaxIters (maxIters_);
1010 if (impConvTest_.is_null()) {
1011 impConvTest_ = rcp (
new StatusTestResNorm_t (convTol_));
1017 if (expConvTest_.is_null()) {
1018 expConvTest_ = rcp (
new StatusTestResNorm_t (convTol_));
1019 expConvTest_->defineResForm (StatusTestResNorm_t::Explicit,
Belos::TwoNorm);
1025 if (convTest_.is_null()) {
1026 convTest_ = rcp (
new StatusTestCombo_t (StatusTestCombo_t::SEQ,
1034 sTest_ = rcp (
new StatusTestCombo_t (StatusTestCombo_t::OR,
1035 maxIterTest_, convTest_));
1039 outputTest_ = stoFactory.
create (printer_, sTest_, outputFreq_,
1043 std::string solverDesc =
"Block GCRODR ";
1044 outputTest_->setSolverDesc (solverDesc);
1051 template<
class ScalarType,
class MV,
class OP>
1056 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1059 Teuchos::RCP<const MV> rhsMV = problem_->getRHS();
1062 int KrylSpaDim = (numBlocks_ - 1) * blockSize_;
1065 int augSpaDim = KrylSpaDim + recycledBlocks_ + 1;
1068 int augSpaImgDim = KrylSpaDim + blockSize_ + recycledBlocks_+1;
1092 if (U_ == Teuchos::null) {
1093 U_ = MVT::Clone( *rhsMV, recycledBlocks_+1 );
1097 if (MVT::GetNumberVecs(*U_) < recycledBlocks_+1) {
1098 Teuchos::RCP<const MV> tmp = U_;
1099 U_ = MVT::Clone( *tmp, recycledBlocks_+1 );
1104 if (C_ == Teuchos::null) {
1105 C_ = MVT::Clone( *rhsMV, recycledBlocks_+1 );
1109 if (MVT::GetNumberVecs(*C_) < recycledBlocks_+1) {
1110 Teuchos::RCP<const MV> tmp = C_;
1111 C_ = MVT::Clone( *tmp, recycledBlocks_+1 );
1116 if (U1_ == Teuchos::null) {
1117 U1_ = MVT::Clone( *rhsMV, recycledBlocks_+1 );
1121 if (MVT::GetNumberVecs(*U1_) < recycledBlocks_+1) {
1122 Teuchos::RCP<const MV> tmp = U1_;
1123 U1_ = MVT::Clone( *tmp, recycledBlocks_+1 );
1128 if (C1_ == Teuchos::null) {
1129 C1_ = MVT::Clone( *rhsMV, recycledBlocks_+1 );
1133 if (MVT::GetNumberVecs(*U1_) < recycledBlocks_+1) {
1134 Teuchos::RCP<const MV> tmp = C1_;
1135 C1_ = MVT::Clone( *tmp, recycledBlocks_+1 );
1140 if (R_ == Teuchos::null){
1141 R_ = MVT::Clone( *rhsMV, blockSize_ );
1147 if (G_ == Teuchos::null){
1148 G_ = Teuchos::rcp(
new SDM( augSpaImgDim, augSpaDim ) );
1151 if ( (G_->numRows() != augSpaImgDim) || (G_->numCols() != augSpaDim) )
1153 G_->reshape( augSpaImgDim, augSpaDim );
1155 G_->putScalar(zero);
1159 if (H_ == Teuchos::null){
1160 H_ = Teuchos::rcp (
new SDM ( Teuchos::View, *G_, KrylSpaDim + blockSize_, KrylSpaDim, recycledBlocks_+1 ,recycledBlocks_+1 ) );
1164 if (F_ == Teuchos::null){
1165 F_ = Teuchos::rcp(
new SDM( recycledBlocks_+1, recycledBlocks_+1 ) );
1168 if ( (F_->numRows() != recycledBlocks_+1) || (F_->numCols() != recycledBlocks_+1) ){
1169 F_->reshape( recycledBlocks_+1, recycledBlocks_+1 );
1172 F_->putScalar(zero);
1175 if (PP_ == Teuchos::null){
1176 PP_ = Teuchos::rcp(
new SDM( augSpaImgDim, recycledBlocks_+1 ) );
1179 if ( (PP_->numRows() != augSpaImgDim) || (PP_->numCols() != recycledBlocks_+1) ){
1180 PP_->reshape( augSpaImgDim, recycledBlocks_+1 );
1185 if (HP_ == Teuchos::null)
1186 HP_ = Teuchos::rcp(
new SDM( augSpaImgDim, augSpaDim ) );
1188 if ( (HP_->numRows() != augSpaImgDim) || (HP_->numCols() != augSpaDim) ){
1189 HP_->reshape( augSpaImgDim, augSpaDim );
1194 tau_.resize(recycledBlocks_+1);
1197 work_.resize(recycledBlocks_+1);
1200 ipiv_.resize(recycledBlocks_+1);
1204 template<
class ScalarType,
class MV,
class OP>
1207 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1208 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1211 int p = block_gmres_iter->getState().curDim;
1212 std::vector<int> index(keff);
1216 SDM HH(Teuchos::Copy, *H_, p+blockSize_, p);
1217 if(recycledBlocks_ >= p + blockSize_){
1221 for (
int ii=0; ii < p; ++ii) index[ii] = ii;
1222 Teuchos::RCP<MV> Utmp = MVT::CloneViewNonConst( *U_, index );
1223 MVT::SetBlock(*V_, index, *Utmp);
1228 Teuchos::RCP<SDM > PPtmp = rcp (
new SDM ( Teuchos::View, *PP_, p, recycledBlocks_+1 ) );
1229 if(recycleMethod_ ==
"harmvecs"){
1230 keff = getHarmonicVecsKryl(p, HH, *PPtmp);
1231 printer_->stream(
Debug) <<
"keff = " << keff << std::endl;
1234 PPtmp = rcp (
new SDM ( Teuchos::View, *PP_, p, keff ) );
1237 for (
int ii=0; ii<keff; ++ii) index[ii] = ii;
1238 Teuchos::RCP<MV> Ctmp = MVT::CloneViewNonConst( *C_, index );
1239 Teuchos::RCP<MV> Utmp = MVT::CloneViewNonConst( *U_, index );
1240 Teuchos::RCP<MV> U1tmp = MVT::CloneViewNonConst( *U1_, index );
1242 for (
int ii=0; ii < p; ++ii) index[ii] = ii;
1243 Teuchos::RCP<const MV> Vtmp = MVT::CloneView( *V_, index );
1247 MVT::MvTimesMatAddMv( one, *Vtmp, *PPtmp, zero, *U1tmp );
1250 SDM HPtmp( Teuchos::View, *HP_, p+blockSize_, keff );
1251 HPtmp.multiply( Teuchos::NO_TRANS, Teuchos::NO_TRANS, one, *H_, *PPtmp, zero );
1255 lapack.GEQRF(HPtmp.numRows(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1256 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK _GEQRF failed to compute a workspace size.");
1259 lwork = (int)work_[0];
1260 work_.resize(lwork);
1261 lapack.GEQRF(HPtmp.numRows(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1262 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK _GEQRF failed to compute a QR factorization.");
1266 SDM Rtmp( Teuchos::View, *F_, keff, keff );
1267 for(
int ii=0;ii<keff;ii++) {
for(
int jj=ii;jj<keff;jj++) Rtmp(ii,jj) = HPtmp(ii,jj); }
1268 lapack.ORGQR(HPtmp.numRows(),HPtmp.numCols(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1269 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK _ORGQR failed to construct the Q factor.");
1273 index.resize( p+blockSize_ );
1274 for (
int ii=0; ii < (p+blockSize_); ++ii) { index[ii] = ii; }
1275 Vtmp = MVT::CloneView( *V_, index );
1276 MVT::MvTimesMatAddMv( one, *Vtmp, HPtmp, zero, *Ctmp );
1283 ipiv_.resize(Rtmp.numRows());
1284 lapack.GETRF(Rtmp.numRows(),Rtmp.numCols(),Rtmp.values(),Rtmp.stride(),&ipiv_[0],&info);
1285 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _GETRF failed to compute an LU factorization.");
1287 lwork = Rtmp.numRows();
1288 work_.resize(lwork);
1289 lapack.GETRI(Rtmp.numRows(),Rtmp.values(),Rtmp.stride(),&ipiv_[0],&work_[0],lwork,&info);
1292 MVT::MvTimesMatAddMv( one, *U1tmp, Rtmp, zero, *Utmp );
1298 template<
class ScalarType,
class MV,
class OP>
1300 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1301 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1303 std::vector<MagnitudeType> d(keff);
1304 std::vector<int> index(numBlocks_+1);
1313 if(recycledBlocks_ >= keff + p){
1316 for (
int ii=0; ii < p; ++ii) { index[ii] = keff+ii; }
1317 Teuchos::RCP<MV> Utmp = MVT::CloneViewNonConst( *U_, index );
1318 for (
int ii=0; ii < p; ++ii) { index[ii] =ii; }
1319 MVT::SetBlock(*V_, index, *Utmp);
1326 for (
int ii=0; ii<keff; ++ii) { index[ii] = ii; }
1327 Teuchos::RCP<MV> Utmp = MVT::CloneViewNonConst( *U_, index );
1329 MVT::MvNorm( *Utmp, d );
1330 for (
int i=0; i<keff; ++i)
1332 MVT::MvScale( *Utmp, d );
1337 Teuchos::RCP<SDM> Gtmp = Teuchos::rcp(
new SDM( Teuchos::View, *G_, p+keff, p+keff-blockSize_ ) );
1340 for (
int i=0; i<keff; ++i)
1341 (*Gtmp)(i,i) = d[i];
1348 SDM PPtmp( Teuchos::View, *PP_, p+keff-blockSize_, recycledBlocks_+1 );
1349 keff_new = getHarmonicVecsAugKryl( keff, p-blockSize_, *Gtmp, oldState.
V, PPtmp );
1356 Teuchos::RCP<MV> U1tmp;
1358 index.resize( keff );
1359 for (
int ii=0; ii<keff; ++ii) { index[ii] = ii; }
1360 Teuchos::RCP<const MV> Utmp = MVT::CloneView( *U_, index );
1361 index.resize( keff_new );
1362 for (
int ii=0; ii<keff_new; ++ii) { index[ii] = ii; }
1363 U1tmp = MVT::CloneViewNonConst( *U1_, index );
1364 SDM PPtmp( Teuchos::View, *PP_, keff, keff_new );
1365 MVT::MvTimesMatAddMv( one, *Utmp, PPtmp, zero, *U1tmp );
1370 index.resize(p-blockSize_);
1371 for (
int ii=0; ii < p-blockSize_; ii++) { index[ii] = ii; }
1372 Teuchos::RCP<const MV> Vtmp = MVT::CloneView( *V_, index );
1373 SDM PPtmp( Teuchos::View, *PP_, p-blockSize_, keff_new, keff );
1374 MVT::MvTimesMatAddMv( one, *Vtmp, PPtmp, one, *U1tmp );
1378 SDM HPtmp( Teuchos::View, *HP_, p+keff, keff_new );
1380 SDM PPtmp( Teuchos::View, *PP_, p-blockSize_+keff, keff_new );
1381 HPtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,*Gtmp,PPtmp,zero);
1385 int info = 0, lwork = -1;
1386 tau_.resize(keff_new);
1387 lapack.GEQRF(HPtmp.numRows(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1388 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK _GEQRF failed to compute a workspace size.");
1390 lwork = (int)work_[0];
1391 work_.resize(lwork);
1392 lapack.GEQRF(HPtmp.numRows(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1393 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK _GEQRF failed to compute a QR factorization.");
1397 SDM Ftmp( Teuchos::View, *F_, keff_new, keff_new );
1398 for(
int i=0;i<keff_new;i++) {
for(
int j=i;j<keff_new;j++) Ftmp(i,j) = HPtmp(i,j); }
1399 lapack.ORGQR(HPtmp.numRows(),HPtmp.numCols(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1400 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK _ORGQR failed to construct the Q factor.");
1407 Teuchos::RCP<MV> C1tmp;
1410 for (
int i=0; i < keff; i++) { index[i] = i; }
1411 Teuchos::RCP<const MV> Ctmp = MVT::CloneView( *C_, index );
1412 index.resize(keff_new);
1413 for (
int i=0; i < keff_new; i++) { index[i] = i; }
1414 C1tmp = MVT::CloneViewNonConst( *C1_, index );
1415 SDM PPtmp( Teuchos::View, *HP_, keff, keff_new );
1416 MVT::MvTimesMatAddMv( one, *Ctmp, PPtmp, zero, *C1tmp );
1421 for (
int i=0; i < p; ++i) { index[i] = i; }
1422 Teuchos::RCP<const MV> Vtmp = MVT::CloneView( *V_, index );
1423 SDM PPtmp( Teuchos::View, *HP_, p, keff_new, keff, 0 );
1424 MVT::MvTimesMatAddMv( one, *Vtmp, PPtmp, one, *C1tmp );
1433 ipiv_.resize(Ftmp.numRows());
1434 lapack.GETRF(Ftmp.numRows(),Ftmp.numCols(),Ftmp.values(),Ftmp.stride(),&ipiv_[0],&info);
1435 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK _GETRF failed to compute an LU factorization.");
1438 lwork = Ftmp.numRows();
1439 work_.resize(lwork);
1440 lapack.GETRI(Ftmp.numRows(),Ftmp.values(),Ftmp.stride(),&ipiv_[0],&work_[0],lwork,&info);
1441 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK _GETRI failed to compute an LU factorization.");
1444 index.resize(keff_new);
1445 for (
int i=0; i < keff_new; i++) { index[i] = i; }
1446 Teuchos::RCP<MV> Utmp = MVT::CloneViewNonConst( *U_, index );
1447 MVT::MvTimesMatAddMv( one, *U1tmp, Ftmp, zero, *Utmp );
1452 if (keff != keff_new) {
1454 block_gcrodr_iter->setSize( keff, numBlocks_ );
1456 SDM b1( Teuchos::View, *G_, recycledBlocks_+2, 1, 0, recycledBlocks_ );
1462 template<
class ScalarType,
class MV,
class OP>
1465 int m2 = GG.numCols();
1466 bool xtraVec =
false;
1467 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1468 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1469 std::vector<int> index;
1472 std::vector<ScalarType> wr(m2), wi(m2);
1475 std::vector<MagnitudeType> w(m2);
1478 SDM vr(m2,m2,
false);
1481 std::vector<int> iperm(m2);
1484 builtRecycleSpace_ =
true;
1494 SDM A_tmp( keff+m+blockSize_, keff+m );
1499 for (
int i=0; i<keff; ++i) { index[i] = i; }
1500 Teuchos::RCP<const MV> Ctmp = MVT::CloneView( *C_, index );
1501 Teuchos::RCP<const MV> Utmp = MVT::CloneView( *U_, index );
1502 SDM A11( Teuchos::View, A_tmp, keff, keff );
1503 MVT::MvTransMv( one, *Ctmp, *Utmp, A11 );
1506 SDM A21( Teuchos::View, A_tmp, m+blockSize_, keff, keff );
1507 index.resize(m+blockSize_);
1508 for (i=0; i < m+blockSize_; i++) { index[i] = i; }
1509 Teuchos::RCP<const MV> Vp = MVT::CloneView( *VV, index );
1510 MVT::MvTransMv( one, *Vp, *Utmp, A21 );
1513 for( i=keff; i<keff+m; i++)
1517 SDM A( m2, A_tmp.numCols() );
1518 A.multiply(
Teuchos::TRANS, Teuchos::NO_TRANS, one, GG, A_tmp, zero );
1526 char balanc=
'P', jobvl=
'N', jobvr=
'V', sense=
'N';
1527 int ld = A.numRows();
1529 int ldvl = ld, ldvr = ld;
1530 int info = 0,ilo = 0,ihi = 0;
1531 ScalarType abnrm = zero, bbnrm = zero;
1533 std::vector<ScalarType> beta(ld);
1534 std::vector<ScalarType> work(lwork);
1535 std::vector<MagnitudeType> lscale(ld), rscale(ld);
1536 std::vector<MagnitudeType> rconde(ld), rcondv(ld);
1537 std::vector<int> iwork(ld+6);
1539 lapack.GGEVX(balanc, jobvl, jobvr, sense, ld, A.values(), ld, B.values(), ld, &wr[0], &wi[0],
1540 &beta[0], vl, ldvl, vr.values(), ldvr, &ilo, &ihi, &lscale[0], &rscale[0],
1541 &abnrm, &bbnrm, &rconde[0], &rcondv[0], &work[0], lwork, &iwork[0], bwork, &info);
1542 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK GGEVX failed to compute eigensolutions.");
1546 for( i=0; i<ld; i++ )
1547 w[i] = Teuchos::ScalarTraits<ScalarType>::squareroot( (wr[i]/beta[i])*(wr[i]/beta[i]) + (wi[i]/beta[i])*(wi[i]/beta[i]) );
1549 this->sort(w,ld,iperm);
1552 if (wi[iperm[ld-recycledBlocks_]] != zero) {
1554 for ( i=ld-recycledBlocks_; i<ld; i++ )
1555 if (wi[iperm[i]] != zero) countImag++;
1557 if (countImag % 2) xtraVec =
true;
1562 for( i=0; i<recycledBlocks_; i++ )
1563 for( j=0; j<ld; j++ )
1564 PP(j,i) = vr(j,iperm[ld-recycledBlocks_+i]);
1567 if (wi[iperm[ld-recycledBlocks_]] > 0) {
1568 for( j=0; j<ld; j++ )
1569 PP(j,recycledBlocks_) = vr(j,iperm[ld-recycledBlocks_]+1);
1572 for( j=0; j<ld; j++ )
1573 PP(j,recycledBlocks_) = vr(j,iperm[ld-recycledBlocks_]-1);
1579 return recycledBlocks_+1;
1581 return recycledBlocks_;
1585 template<
class ScalarType,
class MV,
class OP>
1587 bool xtraVec =
false;
1588 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1589 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1592 std::vector<MagnitudeType> wr(m), wi(m);
1598 std::vector<MagnitudeType> w(m);
1601 std::vector<int> iperm(m);
1605 std::vector<ScalarType> work(lwork);
1611 builtRecycleSpace_ =
true;
1615 Teuchos::RCP<SDM> harmRitzMatrix = rcp(
new SDM( m, blockSize_));
1618 for(
int i=0; i<=blockSize_-1; i++) (*harmRitzMatrix)[blockSize_-1-i][harmRitzMatrix->numRows()-1-i] = 1;
1621 lapack.GESV(m, blockSize_, HHt.values(), HHt.stride(), &iperm[0], harmRitzMatrix->values(), harmRitzMatrix->stride(), &info);
1623 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK GESV failed to compute a solution.");
1627 Teuchos::SerialDenseMatrix<int, ScalarType> H_lbl(Teuchos::View, HH, blockSize_, blockSize_, (HH).numRows()-blockSize_, (HH).numCols()-blockSize_ );
1628 Teuchos::SerialDenseMatrix<int, ScalarType> H_lbl_t( H_lbl,
Teuchos::TRANS );
1633 Teuchos::RCP<SDM> Htemp = Teuchos::null;
1634 Htemp = Teuchos::rcp(
new SDM(H_lbl_t.numRows(), H_lbl_t.numCols()));
1635 Htemp -> multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, one, H_lbl_t, H_lbl, zero);
1636 H_lbl_t.assign(*Htemp);
1638 Htemp = Teuchos::rcp(
new SDM(harmRitzMatrix -> numRows(), harmRitzMatrix -> numCols()));
1639 Htemp -> multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, one, *harmRitzMatrix, H_lbl_t, zero);
1640 harmRitzMatrix -> assign(*Htemp);
1643 int harmColIndex, HHColIndex;
1644 Htemp = Teuchos::rcp(
new SDM(Teuchos::Copy,HH,HH.numRows()-blockSize_,HH.numCols()));
1645 for(
int i = 0; i<blockSize_; i++){
1646 harmColIndex = harmRitzMatrix -> numCols() - i -1;
1648 for(
int j=0; j<m; j++) (*Htemp)[HHColIndex][j] += (*harmRitzMatrix)[harmColIndex][j];
1650 harmRitzMatrix = Htemp;
1658 lapack.GEEV(
'N',
'V', m, harmRitzMatrix -> values(), harmRitzMatrix -> stride(), &wr[0], &wi[0],
1659 vl, ldvl, vr.values(), vr.stride(), &work[0], lwork, &info);
1660 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK GEEV failed to compute eigensolutions.");
1663 for(
int i=0; i<m; ++i ) w[i] = Teuchos::ScalarTraits<ScalarType>::squareroot( wr[i]*wr[i] + wi[i]*wi[i] );
1665 this->sort(w, m, iperm);
1668 if (wi[iperm[recycledBlocks_-1]] != zero) {
1670 for (
int i=0; i<recycledBlocks_; ++i )
1671 if (wi[iperm[i]] != zero) countImag++;
1673 if (countImag % 2) xtraVec =
true;
1677 for(
int i=0; i<recycledBlocks_; ++i )
1678 for(
int j=0; j<m; j++ )
1679 PP(j,i) = vr(j,iperm[i]);
1682 if (wi[iperm[recycledBlocks_-1]] > 0) {
1683 for(
int j=0; j<m; ++j )
1684 PP(j,recycledBlocks_) = vr(j,iperm[recycledBlocks_-1]+1);
1687 for(
int j=0; j<m; ++j )
1688 PP(j,recycledBlocks_) = vr(j,iperm[recycledBlocks_-1]-1);
1694 printer_->stream(
Debug) <<
"Recycled " << recycledBlocks_+1 <<
" vectors" << std::endl;
1695 return recycledBlocks_+1;
1697 printer_->stream(
Debug) <<
"Recycled " << recycledBlocks_ <<
" vectors" << std::endl;
1698 return recycledBlocks_;
1704 template<
class ScalarType,
class MV,
class OP>
1706 int l, r, j, i, flag;
1733 if (dlist[j] > dlist[j - 1]) j = j + 1;
1734 if (dlist[j - 1] > dK) {
1735 dlist[i - 1] = dlist[j - 1];
1736 iperm[i - 1] = iperm[j - 1];
1749 dlist[r] = dlist[0];
1750 iperm[r] = iperm[0];
1764 template<
class ScalarType,
class MV,
class OP>
1768 using Teuchos::rcp_const_cast;
1772 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1773 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1774 std::vector<int> index(numBlocks_+1);
1790 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
1791 int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1795 std::vector<int> currIdx;
1797 if ( adaptiveBlockSize_ ) {
1798 blockSize_ = numCurrRHS;
1799 currIdx.resize( numCurrRHS );
1800 for (
int i=0; i<numCurrRHS; ++i)
1801 currIdx[i] = startPtr+i;
1804 currIdx.resize( blockSize_ );
1805 for (
int i=0; i<numCurrRHS; ++i)
1806 currIdx[i] = startPtr+i;
1807 for (
int i=numCurrRHS; i<blockSize_; ++i)
1812 problem_->setLSIndex( currIdx );
1818 loaDetected_ =
false;
1821 bool isConverged =
true;
1824 initializeStateStorage();
1827 Teuchos::ParameterList plist;
1829 while (numRHS2Solve > 0){
1833 int prime_iterations;
1839 printer_->stream(
Debug) <<
" Now solving RHS index " << currIdx[0] <<
" using recycled subspace of dimension " << keff << std::endl << std::endl;
1843 for (
int ii=0; ii<keff; ++ii) { index[ii] = ii; }
1844 RCP<const MV> Utmp = MVT::CloneView( *U_, index );
1845 RCP<MV> Ctmp = MVT::CloneViewNonConst( *C_, index );
1846 problem_->apply( *Utmp, *Ctmp );
1848 RCP<MV> U1tmp = MVT::CloneViewNonConst( *U1_, index );
1852 SDM Ftmp( Teuchos::View, *F_, keff, keff );
1853 int rank = ortho_->normalize(*Ctmp, rcp(&Ftmp,
false));
1855 TEUCHOS_TEST_FOR_EXCEPTION(rank != keff,
BlockGCRODRSolMgrOrthoFailure,
"Belos::BlockGCRODRSolMgr::solve(): Failed to compute orthonormal basis for initial recycled subspace.");
1860 ipiv_.resize(Ftmp.numRows());
1861 lapack.GETRF(Ftmp.numRows(),Ftmp.numCols(),Ftmp.values(),Ftmp.stride(),&ipiv_[0],&info);
1862 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK _GETRF failed to compute an LU factorization.");
1865 int lwork = Ftmp.numRows();
1866 work_.resize(lwork);
1867 lapack.GETRI(Ftmp.numRows(),Ftmp.values(),Ftmp.stride(),&ipiv_[0],&work_[0],lwork,&info);
1868 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
BlockGCRODRSolMgrLAPACKFailure,
"Belos::BlockGCRODRSolMgr::solve(): LAPACK _GETRI failed to invert triangular matrix.");
1871 MVT::MvTimesMatAddMv( one, *Utmp, Ftmp, zero, *U1tmp );
1876 for (
int ii=0; ii<keff; ++ii) { index[ii] = ii; }
1877 Ctmp = MVT::CloneViewNonConst( *C_, index );
1878 Utmp = MVT::CloneView( *U_, index );
1881 SDM Ctr(keff,blockSize_);
1882 problem_->computeCurrPrecResVec( &*R_ );
1883 MVT::MvTransMv( one, *Ctmp, *R_, Ctr );
1886 RCP<MV> update = MVT::Clone( *problem_->getCurrLHSVec(), blockSize_ );
1887 MVT::MvInit( *update, 0.0 );
1888 MVT::MvTimesMatAddMv( one, *Utmp, Ctr, one, *update );
1889 problem_->updateSolution( update,
true );
1892 MVT::MvTimesMatAddMv( -one, *Ctmp, Ctr, one, *R_ );
1895 prime_iterations = 0;
1900 if (V_ == Teuchos::null) {
1902 Teuchos::RCP<const MV> rhsMV = problem_->getRHS();
1903 V_ = MVT::Clone( *rhsMV, (numBlocks_+1)*blockSize_ );
1907 if (MVT::GetNumberVecs(*V_) < (numBlocks_+1)*blockSize_ ) {
1908 Teuchos::RCP<const MV> tmp = V_;
1909 V_ = MVT::Clone( *tmp, (numBlocks_+1)*blockSize_ );
1914 printer_->stream(
Debug) <<
" No recycled subspace available for RHS index " << std::endl << std::endl;
1916 Teuchos::ParameterList primeList;
1919 primeList.set(
"Num Blocks",numBlocks_-1);
1920 primeList.set(
"Block Size",blockSize_);
1921 primeList.set(
"Recycled Blocks",0);
1922 primeList.set(
"Keep Hessenberg",
true);
1923 primeList.set(
"Initialize Hessenberg",
true);
1925 ptrdiff_t dim = MVText::GetGlobalLength( *(problem_->getRHS()) );
1926 if (blockSize_*static_cast<ptrdiff_t>(numBlocks_) > dim) {
1927 ptrdiff_t tmpNumBlocks = 0;
1928 if (blockSize_ == 1)
1929 tmpNumBlocks = dim / blockSize_;
1931 tmpNumBlocks = ( dim - blockSize_) / blockSize_;
1932 printer_->stream(
Warnings) <<
"Belos::BlockGmresSolMgr::solve(): Warning! Requested Krylov subspace dimension is larger than operator dimension!" 1933 << std::endl <<
"The maximum number of blocks allowed for the Krylov subspace will be adjusted to " << tmpNumBlocks << std::endl;
1934 primeList.set(
"Num Blocks",Teuchos::as<int>(tmpNumBlocks));
1938 primeList.set(
"Num Blocks",numBlocks_-1);
1941 Teuchos::RCP<BlockGmresIter<ScalarType,MV,OP> > block_gmres_iter;
1945 block_gmres_iter->setSize( blockSize_, numBlocks_-1 );
1948 Teuchos::RCP<MV> V_0;
1949 if (currIdx[blockSize_-1] == -1) {
1950 V_0 = MVT::Clone( *(problem_->getInitPrecResVec()), blockSize_ );
1951 problem_->computeCurrPrecResVec( &*V_0 );
1954 V_0 = MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1958 Teuchos::RCP<SDM > z_0 = Teuchos::rcp(
new SDM( blockSize_, blockSize_ ) );
1961 int rank = ortho_->normalize( *V_0, z_0 );
1969 block_gmres_iter->initializeGmres(newstate);
1971 bool primeConverged =
false;
1974 printer_->stream(
Debug) <<
" Preparing to Iterate!!!!" << std::endl << std::endl;
1975 block_gmres_iter->iterate();
1980 if ( convTest_->getStatus() ==
Passed ) {
1981 printer_->stream(
Debug) <<
"We converged during the prime the pump stage" << std::endl << std::endl;
1982 primeConverged = !(expConvTest_->getLOADetected());
1983 if ( expConvTest_->getLOADetected() ) {
1985 loaDetected_ =
true;
1986 printer_->stream(
Warnings) <<
"Belos::BlockGmresSolMgr::solve(): Warning! Solver has experienced a loss of accuracy!" << std::endl;
1992 else if( maxIterTest_->getStatus() ==
Passed ) {
1994 primeConverged =
false;
2000 printer_->stream(
Debug) <<
" We did not converge on priming cycle of Block GMRES. Therefore we recycle and restart. " << std::endl << std::endl;
2005 if (blockSize_ != 1) {
2006 printer_->stream(
Errors) <<
"Error! Caught std::exception in BlockGmresIter::iterate() at iteration " 2007 << block_gmres_iter->getNumIters() << std::endl
2008 << e.what() << std::endl;
2009 if (convTest_->getStatus() !=
Passed)
2010 primeConverged =
false;
2014 block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
2016 sTest_->checkStatus( &*block_gmres_iter );
2017 if (convTest_->getStatus() !=
Passed)
2018 isConverged =
false;
2021 catch (
const std::exception &e) {
2022 printer_->stream(
Errors) <<
"Error! Caught std::exception in BlockGmresIter::iterate() at iteration " 2023 << block_gmres_iter->getNumIters() << std::endl
2024 << e.what() << std::endl;
2029 prime_iterations = block_gmres_iter->getNumIters();
2032 RCP<MV> update = block_gmres_iter->getCurrentUpdate();
2033 problem_->updateSolution( update,
true );
2037 problem_->computeCurrPrecResVec( &*R_ );
2040 newstate = block_gmres_iter->getState();
2042 H_->assign(*(newstate.
H));
2051 V_ = rcp_const_cast<MV>(newstate.
V);
2052 newstate.
V.release();
2054 buildRecycleSpaceKryl(keff, block_gmres_iter);
2055 printer_->stream(
Debug) <<
"Generated recycled subspace using RHS index " << currIdx[0] <<
" of dimension " << keff << std::endl << std::endl;
2059 if (primeConverged) {
2080 problem_->setCurrLS();
2083 startPtr += numCurrRHS;
2084 numRHS2Solve -= numCurrRHS;
2085 if ( numRHS2Solve > 0 ) {
2086 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
2087 if ( adaptiveBlockSize_ ) {
2088 blockSize_ = numCurrRHS;
2089 currIdx.resize( numCurrRHS );
2090 for (
int i=0; i<numCurrRHS; ++i) currIdx[i] = startPtr+i;
2093 currIdx.resize( blockSize_ );
2094 for (
int i=0; i<numCurrRHS; ++i) currIdx[i] = startPtr+i;
2095 for (
int i=numCurrRHS; i<blockSize_; ++i) currIdx[i] = -1;
2098 problem_->setLSIndex( currIdx );
2101 currIdx.resize( numRHS2Solve );
2111 Teuchos::ParameterList blockgcrodrList;
2112 blockgcrodrList.set(
"Num Blocks",numBlocks_);
2113 blockgcrodrList.set(
"Block Size",blockSize_);
2114 blockgcrodrList.set(
"Recycled Blocks",keff);
2116 Teuchos::RCP<BlockGCRODRIter<ScalarType,MV,OP> > block_gcrodr_iter;
2120 index.resize( blockSize_ );
2121 for(
int ii = 0; ii < blockSize_; ii++) index[ii] = ii;
2122 Teuchos::RCP<MV> V0 = MVT::CloneViewNonConst( *V_, index );
2125 MVT::Assign(*R_,*V0);
2128 for(
int i=0; i < keff; i++){ index[i] = i;};
2129 B_ = rcp(
new SDM(Teuchos::View, *G_, keff, numBlocks_*blockSize_, 0, keff));
2130 H_ = rcp(
new SDM(Teuchos::View, *G_, (numBlocks_-1)*blockSize_ + blockSize_, (numBlocks_-1)*blockSize_, keff ,keff ));
2134 newstate.
U = MVT::CloneViewNonConst(*U_, index);
2135 newstate.
C = MVT::CloneViewNonConst(*C_, index);
2137 newstate.
curDim = blockSize_;
2138 block_gcrodr_iter -> initialize(newstate);
2140 int numRestarts = 0;
2144 block_gcrodr_iter -> iterate();
2149 if( convTest_->getStatus() ==
Passed ) {
2157 else if(maxIterTest_->getStatus() ==
Passed ){
2159 isConverged =
false;
2166 else if (block_gcrodr_iter->getCurSubspaceDim() == block_gcrodr_iter->getMaxSubspaceDim()){
2171 Teuchos::RCP<MV> update = block_gcrodr_iter->getCurrentUpdate();
2172 problem_->updateSolution(update,
true);
2173 buildRecycleSpaceAugKryl(block_gcrodr_iter);
2175 printer_->stream(
Debug) <<
" Generated new recycled subspace using RHS index " << currIdx[0] <<
" of dimension " << keff << std::endl << std::endl;
2177 if(numRestarts >= maxRestarts_) {
2178 isConverged =
false;
2184 printer_ -> stream(
Debug) <<
" Performing restart number " << numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
2187 problem_->computeCurrPrecResVec( &*R_ );
2188 index.resize( blockSize_ );
2189 for (
int ii=0; ii<blockSize_; ++ii) index[ii] = ii;
2190 Teuchos::RCP<MV> V0 = MVT::CloneViewNonConst( *V_, index );
2191 MVT::SetBlock(*R_,index,*V0);
2195 index.resize( numBlocks_*blockSize_ );
2196 for (
int ii=0; ii<(numBlocks_*blockSize_); ++ii) index[ii] = ii;
2197 restartState.
V = MVT::CloneViewNonConst( *V_, index );
2198 index.resize( keff );
2199 for (
int ii=0; ii<keff; ++ii) index[ii] = ii;
2200 restartState.
U = MVT::CloneViewNonConst( *U_, index );
2201 restartState.
C = MVT::CloneViewNonConst( *C_, index );
2202 B_ = rcp(
new SDM(Teuchos::View, *G_, keff, (numBlocks_-1)*blockSize_, 0, keff));
2203 H_ = rcp(
new SDM(Teuchos::View, *G_, numBlocks_*blockSize_, (numBlocks_-1)*blockSize_, keff ,keff ));
2204 restartState.
B = B_;
2205 restartState.
H = H_;
2206 restartState.
curDim = blockSize_;
2207 block_gcrodr_iter->initialize(restartState);
2216 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Belos::BlockGCRODRSolMgr::solve(): Invalid return from BlockGCRODRIter::iterate().");
2222 block_gcrodr_iter->updateLSQR( block_gcrodr_iter->getCurSubspaceDim() );
2224 sTest_->checkStatus( &*block_gcrodr_iter );
2225 if (convTest_->getStatus() !=
Passed) isConverged =
false;
2228 catch(
const std::exception &e){
2229 printer_->stream(
Errors) <<
"Error! Caught exception in BlockGCRODRIter::iterate() at iteration " 2230 << block_gcrodr_iter->getNumIters() << std::endl
2231 << e.what() << std::endl;
2238 Teuchos::RCP<MV> update = block_gcrodr_iter->getCurrentUpdate();
2239 problem_->updateSolution( update,
true );
2258 problem_->setCurrLS();
2261 startPtr += numCurrRHS;
2262 numRHS2Solve -= numCurrRHS;
2263 if ( numRHS2Solve > 0 ) {
2264 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
2265 if ( adaptiveBlockSize_ ) {
2266 blockSize_ = numCurrRHS;
2267 currIdx.resize( numCurrRHS );
2268 for (
int i=0; i<numCurrRHS; ++i) currIdx[i] = startPtr+i;
2271 currIdx.resize( blockSize_ );
2272 for (
int i=0; i<numCurrRHS; ++i) currIdx[i] = startPtr+i;
2273 for (
int i=numCurrRHS; i<blockSize_; ++i) currIdx[i] = -1;
2276 problem_->setLSIndex( currIdx );
2279 currIdx.resize( numRHS2Solve );
2283 if (!builtRecycleSpace_) {
2284 buildRecycleSpaceAugKryl(block_gcrodr_iter);
2285 printer_->stream(
Debug) <<
" Generated new recycled subspace using RHS index " << currIdx[0] <<
" of dimension " << keff << std::endl << std::endl;
2293 #ifdef BELOS_TEUCHOS_TIME_MONITOR 2296 if (verbosity_ &
TimingDetails) Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
2299 numIters_ = maxIterTest_->getNumIters();
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Collection of types and exceptions used within the Belos solvers.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get current linear problem being solved for in this object.
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.
Structure to contain pointers to BlockGCRODRIter state variables.
virtual ~BlockGCRODRSolMgr()
Destructor.
int getNumIters() const
Get the iteration count for the most recent call to solve().
ScaleType
The type of scaling to use on the residual norm value.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B
The projection of the Krylov subspace against the recycled subspace *.
Exception thrown to signal error in a status test during Belos::StatusTest::checkStatus().
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
This class implements the block GMRES iteration, where a block Krylov subspace is constructed...
Teuchos::RCP< const MV > V
The current Krylov basis.
BlockGCRODRIterOrthoFailure is thrown when the BlockGCRODRIter object is unable to compute independen...
Thrown when the linear problem was not set up correctly.
A factory class for generating StatusTestOutput objects.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the parameters the solver should use to solve the linear problem.
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > z
The current right-hand side of the least squares system RY = Z.
An implementation of StatusTestResNorm using a family of residual norms.
Structure to contain pointers to GmresIteration state variables.
An extension of the MultiVecTraits class that adds a new vector length method.
Belos::StatusTest class for specifying a maximum number of iterations.
BlockGCRODRSolMgrRecyclingFailure(const std::string &what_arg)
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType.
Thrown if any problem occurs in using or creating the recycle subspace.
A factory class for generating StatusTestOutput objects.
Teuchos::RCP< MV > V
The current Krylov basis.
BlockGCRODRSolMgrOrthoFailure(const std::string &what_arg)
int curDim
The current dimension of the reduction.
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
A Belos::StatusTest class for specifying a maximum number of iterations.
ResetType
How to reset the solver.
BlockGCRODRSolMgrLAPACKFailure(const std::string &what_arg)
A solver manager for the Block GCRO-DR (Block Recycling GMRES) linear solver.
Pure virtual base class which describes the basic interface for a solver manager. ...
int curDim
The current dimension of the reduction.
Belos concrete class for performing the block GCRO-DR (block GMRES with recycling) iteration...
BlockGCRODRSolMgr()
Default constructor.
A linear system to solve, and its associated information.
std::string description() const
A description of the Block GCRODR solver manager.
Class which describes the linear problem to be solved by the iterative solver.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem to solve on the next call to solve().
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 ...
Thrown when the solution manager was unable to orthogonalize the basis vectors.
Teuchos::RCP< MV > U
The recycled subspace and its projection.
Belos concrete class for performing the block GMRES iteration.
Implementation of the Block GCRO-DR (Block Recycling GMRES) iteration.
int setTolerance(MagnitudeType tolerance)
Set the value of the tolerance.
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.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > H
The current Hessenberg matrix.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
A class for extending the status testing capabilities of Belos via logical combinations.
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
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...
BlockGCRODRSolMgrLinearProblemFailure(const std::string &what_arg)
ReturnType solve()
Solve the current linear problem.
Thrown when an LAPACK call fails.
Belos concrete class for performing the block, flexible GMRES iteration.
bool isLOADetected() const
Whether a loss of accuracy was detected during the most recent solve.
OutputType
Style of output used to display status test information.
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > H
The current Hessenberg matrix.