42 #ifndef BELOS_GCRODR_SOLMGR_HPP 43 #define BELOS_GCRODR_SOLMGR_HPP 63 #include "Teuchos_BLAS.hpp" 64 #include "Teuchos_LAPACK.hpp" 65 #include "Teuchos_as.hpp" 66 #ifdef BELOS_TEUCHOS_TIME_MONITOR 67 #include "Teuchos_TimeMonitor.hpp" 68 #endif // BELOS_TEUCHOS_TIME_MONITOR 157 template<
class ScalarType,
class MV,
class OP>
164 typedef Teuchos::ScalarTraits<ScalarType> SCT;
165 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
166 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
234 const Teuchos::RCP<Teuchos::ParameterList> &pl);
251 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const;
264 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
265 return Teuchos::tuple(timerSolve_);
297 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms );
308 if ((type &
Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem();
340 std::string description()
const;
350 void initializeStateStorage();
359 int getHarmonicVecs1(
int m,
360 const Teuchos::SerialDenseMatrix<int,ScalarType>& HH,
361 Teuchos::SerialDenseMatrix<int,ScalarType>& PP);
368 int getHarmonicVecs2(
int keff,
int m,
369 const Teuchos::SerialDenseMatrix<int,ScalarType>& HH,
370 const Teuchos::RCP<const MV>& VV,
371 Teuchos::SerialDenseMatrix<int,ScalarType>& PP);
374 void sort(std::vector<ScalarType>& dlist,
int n, std::vector<int>& iperm);
377 Teuchos::LAPACK<int,ScalarType> lapack;
380 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
383 Teuchos::RCP<OutputManager<ScalarType> > printer_;
384 Teuchos::RCP<std::ostream> outputStream_;
387 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
388 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
389 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
390 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > expConvTest_, impConvTest_;
391 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
396 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > ortho_;
399 Teuchos::RCP<Teuchos::ParameterList> params_;
402 static const MagnitudeType convTol_default_;
403 static const MagnitudeType orthoKappa_default_;
404 static const int maxRestarts_default_;
405 static const int maxIters_default_;
406 static const int numBlocks_default_;
407 static const int blockSize_default_;
408 static const int recycledBlocks_default_;
409 static const int verbosity_default_;
410 static const int outputStyle_default_;
411 static const int outputFreq_default_;
412 static const std::string impResScale_default_;
413 static const std::string expResScale_default_;
414 static const std::string label_default_;
415 static const std::string orthoType_default_;
416 static const Teuchos::RCP<std::ostream> outputStream_default_;
419 MagnitudeType convTol_, orthoKappa_, achievedTol_;
420 int maxRestarts_, maxIters_, numIters_;
421 int verbosity_, outputStyle_, outputFreq_;
422 std::string orthoType_;
423 std::string impResScale_, expResScale_;
430 int numBlocks_, recycledBlocks_;
441 Teuchos::RCP<MV> U_, C_;
444 Teuchos::RCP<MV> U1_, C1_;
447 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > H2_;
448 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > H_;
449 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B_;
450 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > PP_;
451 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > HP_;
452 std::vector<ScalarType> tau_;
453 std::vector<ScalarType> work_;
454 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > R_;
455 std::vector<int> ipiv_;
460 Teuchos::RCP<Teuchos::Time> timerSolve_;
466 bool builtRecycleSpace_;
471 template<
class ScalarType,
class MV,
class OP>
474 template<
class ScalarType,
class MV,
class OP>
477 template<
class ScalarType,
class MV,
class OP>
480 template<
class ScalarType,
class MV,
class OP>
483 template<
class ScalarType,
class MV,
class OP>
486 template<
class ScalarType,
class MV,
class OP>
489 template<
class ScalarType,
class MV,
class OP>
492 template<
class ScalarType,
class MV,
class OP>
495 template<
class ScalarType,
class MV,
class OP>
498 template<
class ScalarType,
class MV,
class OP>
501 template<
class ScalarType,
class MV,
class OP>
504 template<
class ScalarType,
class MV,
class OP>
507 template<
class ScalarType,
class MV,
class OP>
510 template<
class ScalarType,
class MV,
class OP>
513 template<
class ScalarType,
class MV,
class OP>
518 template<
class ScalarType,
class MV,
class OP>
525 template<
class ScalarType,
class MV,
class OP>
528 const Teuchos::RCP<Teuchos::ParameterList> &pl )
534 TEUCHOS_TEST_FOR_EXCEPTION(problem == Teuchos::null, std::invalid_argument,
535 "Belos::GCRODRSolMgr constructor: The solver manager's " 536 "constructor needs the linear problem argument 'problem' " 550 template<
class ScalarType,
class MV,
class OP>
552 outputStream_ = outputStream_default_;
553 convTol_ = convTol_default_;
554 orthoKappa_ = orthoKappa_default_;
555 maxRestarts_ = maxRestarts_default_;
556 maxIters_ = maxIters_default_;
557 numBlocks_ = numBlocks_default_;
558 recycledBlocks_ = recycledBlocks_default_;
559 verbosity_ = verbosity_default_;
560 outputStyle_ = outputStyle_default_;
561 outputFreq_ = outputFreq_default_;
562 orthoType_ = orthoType_default_;
563 impResScale_ = impResScale_default_;
564 expResScale_ = expResScale_default_;
565 label_ = label_default_;
567 builtRecycleSpace_ =
false;
583 template<
class ScalarType,
class MV,
class OP>
588 using Teuchos::isParameterType;
589 using Teuchos::getParameter;
591 using Teuchos::ParameterList;
592 using Teuchos::parameterList;
595 using Teuchos::rcp_dynamic_cast;
596 using Teuchos::rcpFromRef;
597 using Teuchos::Exceptions::InvalidParameter;
598 using Teuchos::Exceptions::InvalidParameterName;
599 using Teuchos::Exceptions::InvalidParameterType;
603 RCP<const ParameterList> defaultParams = getValidParameters();
621 if (params_.is_null()) {
622 params_ = parameterList (*defaultParams);
630 if (params_ != params) {
636 params_ = parameterList (*params);
671 params_->validateParametersAndSetDefaults (*defaultParams);
675 if (params->isParameter (
"Maximum Restarts")) {
676 maxRestarts_ = params->get(
"Maximum Restarts", maxRestarts_default_);
679 params_->set (
"Maximum Restarts", maxRestarts_);
683 if (params->isParameter (
"Maximum Iterations")) {
684 maxIters_ = params->get (
"Maximum Iterations", maxIters_default_);
687 params_->set (
"Maximum Iterations", maxIters_);
688 if (! maxIterTest_.is_null())
689 maxIterTest_->setMaxIters (maxIters_);
693 if (params->isParameter (
"Num Blocks")) {
694 numBlocks_ = params->get (
"Num Blocks", numBlocks_default_);
695 TEUCHOS_TEST_FOR_EXCEPTION(numBlocks_ <= 0, std::invalid_argument,
696 "Belos::GCRODRSolMgr: The \"Num Blocks\" parameter must " 697 "be strictly positive, but you specified a value of " 698 << numBlocks_ <<
".");
700 params_->set (
"Num Blocks", numBlocks_);
704 if (params->isParameter (
"Num Recycled Blocks")) {
705 recycledBlocks_ = params->get (
"Num Recycled Blocks",
706 recycledBlocks_default_);
707 TEUCHOS_TEST_FOR_EXCEPTION(recycledBlocks_ <= 0, std::invalid_argument,
708 "Belos::GCRODRSolMgr: The \"Num Recycled Blocks\" " 709 "parameter must be strictly positive, but you specified " 710 "a value of " << recycledBlocks_ <<
".");
711 TEUCHOS_TEST_FOR_EXCEPTION(recycledBlocks_ >= numBlocks_, std::invalid_argument,
712 "Belos::GCRODRSolMgr: The \"Num Recycled Blocks\" " 713 "parameter must be less than the \"Num Blocks\" " 714 "parameter, but you specified \"Num Recycled Blocks\" " 715 "= " << recycledBlocks_ <<
" and \"Num Blocks\" = " 716 << numBlocks_ <<
".");
718 params_->set(
"Num Recycled Blocks", recycledBlocks_);
724 if (params->isParameter (
"Timer Label")) {
725 std::string tempLabel = params->get (
"Timer Label", label_default_);
728 if (tempLabel != label_) {
730 params_->set (
"Timer Label", label_);
731 std::string solveLabel = label_ +
": GCRODRSolMgr total solve time";
732 #ifdef BELOS_TEUCHOS_TIME_MONITOR 733 timerSolve_ = Teuchos::TimeMonitor::getNewCounter (solveLabel);
735 if (ortho_ != Teuchos::null) {
736 ortho_->setLabel( label_ );
742 if (params->isParameter (
"Verbosity")) {
743 if (isParameterType<int> (*params,
"Verbosity")) {
744 verbosity_ = params->get (
"Verbosity", verbosity_default_);
746 verbosity_ = (int) getParameter<Belos::MsgType> (*params,
"Verbosity");
749 params_->set (
"Verbosity", verbosity_);
752 if (! printer_.is_null())
753 printer_->setVerbosity (verbosity_);
757 if (params->isParameter (
"Output Style")) {
758 if (isParameterType<int> (*params,
"Output Style")) {
759 outputStyle_ = params->get (
"Output Style", outputStyle_default_);
761 outputStyle_ = (int) getParameter<OutputType> (*params,
"Output Style");
765 params_->set (
"Output Style", outputStyle_);
783 if (params->isParameter (
"Output Stream")) {
785 outputStream_ = getParameter<RCP<std::ostream> > (*params,
"Output Stream");
786 }
catch (InvalidParameter&) {
787 outputStream_ = rcpFromRef (std::cout);
794 if (outputStream_.is_null()) {
795 outputStream_ = rcp (
new Teuchos::oblackholestream);
798 params_->set (
"Output Stream", outputStream_);
801 if (! printer_.is_null()) {
802 printer_->setOStream (outputStream_);
808 if (params->isParameter (
"Output Frequency")) {
809 outputFreq_ = params->get (
"Output Frequency", outputFreq_default_);
813 params_->set(
"Output Frequency", outputFreq_);
814 if (! outputTest_.is_null())
815 outputTest_->setOutputFrequency (outputFreq_);
822 if (printer_.is_null()) {
833 bool changedOrthoType =
false;
834 if (params->isParameter (
"Orthogonalization")) {
835 const std::string& tempOrthoType =
836 params->get (
"Orthogonalization", orthoType_default_);
839 std::ostringstream os;
840 os <<
"Belos::GCRODRSolMgr: Invalid orthogonalization name \"" 841 << tempOrthoType <<
"\". The following are valid options " 842 <<
"for the \"Orthogonalization\" name parameter: ";
844 throw std::invalid_argument (os.str());
846 if (tempOrthoType != orthoType_) {
847 changedOrthoType =
true;
848 orthoType_ = tempOrthoType;
850 params_->set (
"Orthogonalization", orthoType_);
866 RCP<ParameterList> orthoParams;
869 using Teuchos::sublist;
871 const std::string paramName (
"Orthogonalization Parameters");
874 orthoParams = sublist (params_, paramName,
true);
875 }
catch (InvalidParameter&) {
882 orthoParams = sublist (params_, paramName,
true);
885 TEUCHOS_TEST_FOR_EXCEPTION(orthoParams.is_null(), std::logic_error,
886 "Failed to get orthogonalization parameters. " 887 "Please report this bug to the Belos developers.");
892 if (ortho_.is_null() || changedOrthoType) {
898 label_, orthoParams);
906 typedef Teuchos::ParameterListAcceptor PLA;
907 RCP<PLA> pla = rcp_dynamic_cast<PLA> (ortho_);
913 label_, orthoParams);
915 pla->setParameterList (orthoParams);
927 if (params->isParameter (
"Orthogonalization Constant")) {
928 const MagnitudeType orthoKappa =
929 params->get (
"Orthogonalization Constant", orthoKappa_default_);
930 if (orthoKappa > 0) {
931 orthoKappa_ = orthoKappa;
933 params_->set(
"Orthogonalization Constant", orthoKappa_);
935 if (orthoType_ ==
"DGKS" && ! ortho_.is_null()) {
942 rcp_dynamic_cast<ortho_man_type>(ortho_)->setDepTol (orthoKappa_);
952 if (params->isParameter(
"Convergence Tolerance")) {
953 convTol_ = params->get (
"Convergence Tolerance", convTol_default_);
956 params_->set (
"Convergence Tolerance", convTol_);
957 if (! impConvTest_.is_null())
959 if (! expConvTest_.is_null())
960 expConvTest_->setTolerance (convTol_);
964 if (params->isParameter (
"Implicit Residual Scaling")) {
965 std::string tempImpResScale =
966 getParameter<std::string> (*params,
"Implicit Residual Scaling");
969 if (impResScale_ != tempImpResScale) {
971 impResScale_ = tempImpResScale;
974 params_->set(
"Implicit Residual Scaling", impResScale_);
984 if (! impConvTest_.is_null()) {
997 if (params->isParameter(
"Explicit Residual Scaling")) {
998 std::string tempExpResScale =
999 getParameter<std::string> (*params,
"Explicit Residual Scaling");
1002 if (expResScale_ != tempExpResScale) {
1004 expResScale_ = tempExpResScale;
1007 params_->set(
"Explicit Residual Scaling", expResScale_);
1010 if (! expConvTest_.is_null()) {
1016 expConvTest_ = null;
1027 if (maxIterTest_.is_null())
1032 if (impConvTest_.is_null()) {
1033 impConvTest_ = rcp (
new StatusTestResNorm_t (convTol_));
1039 if (expConvTest_.is_null()) {
1040 expConvTest_ = rcp (
new StatusTestResNorm_t (convTol_));
1041 expConvTest_->defineResForm (StatusTestResNorm_t::Explicit,
Belos::TwoNorm);
1047 if (convTest_.is_null()) {
1048 convTest_ = rcp (
new StatusTestCombo_t (StatusTestCombo_t::SEQ,
1056 sTest_ = rcp (
new StatusTestCombo_t (StatusTestCombo_t::OR,
1062 outputTest_ = stoFactory.
create (printer_, sTest_, outputFreq_,
1066 std::string solverDesc =
" GCRODR ";
1067 outputTest_->setSolverDesc( solverDesc );
1070 if (timerSolve_.is_null()) {
1071 std::string solveLabel = label_ +
": GCRODRSolMgr total solve time";
1072 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1073 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
1082 template<
class ScalarType,
class MV,
class OP>
1083 Teuchos::RCP<const Teuchos::ParameterList>
1086 using Teuchos::ParameterList;
1087 using Teuchos::parameterList;
1090 static RCP<const ParameterList> validPL;
1091 if (is_null(validPL)) {
1092 RCP<ParameterList> pl = parameterList ();
1095 pl->set(
"Convergence Tolerance", convTol_default_,
1096 "The relative residual tolerance that needs to be achieved by the\n" 1097 "iterative solver in order for the linear system to be declared converged.");
1098 pl->set(
"Maximum Restarts", maxRestarts_default_,
1099 "The maximum number of cycles allowed for each\n" 1100 "set of RHS solved.");
1101 pl->set(
"Maximum Iterations", maxIters_default_,
1102 "The maximum number of iterations allowed for each\n" 1103 "set of RHS solved.");
1107 pl->set(
"Block Size", blockSize_default_,
1108 "Block Size Parameter -- currently must be 1 for GCRODR");
1109 pl->set(
"Num Blocks", numBlocks_default_,
1110 "The maximum number of vectors allowed in the Krylov subspace\n" 1111 "for each set of RHS solved.");
1112 pl->set(
"Num Recycled Blocks", recycledBlocks_default_,
1113 "The maximum number of vectors in the recycled subspace." );
1114 pl->set(
"Verbosity", verbosity_default_,
1115 "What type(s) of solver information should be outputted\n" 1116 "to the output stream.");
1117 pl->set(
"Output Style", outputStyle_default_,
1118 "What style is used for the solver information outputted\n" 1119 "to the output stream.");
1120 pl->set(
"Output Frequency", outputFreq_default_,
1121 "How often convergence information should be outputted\n" 1122 "to the output stream.");
1123 pl->set(
"Output Stream", outputStream_default_,
1124 "A reference-counted pointer to the output stream where all\n" 1125 "solver output is sent.");
1126 pl->set(
"Implicit Residual Scaling", impResScale_default_,
1127 "The type of scaling used in the implicit residual convergence test.");
1128 pl->set(
"Explicit Residual Scaling", expResScale_default_,
1129 "The type of scaling used in the explicit residual convergence test.");
1130 pl->set(
"Timer Label", label_default_,
1131 "The string to use as a prefix for the timer labels.");
1135 pl->set(
"Orthogonalization", orthoType_default_,
1136 "The type of orthogonalization to use. Valid options: " +
1138 RCP<const ParameterList> orthoParams =
1140 pl->set (
"Orthogonalization Parameters", *orthoParams,
1141 "Parameters specific to the type of orthogonalization used.");
1143 pl->set(
"Orthogonalization Constant", orthoKappa_default_,
1144 "When using DGKS orthogonalization: the \"depTol\" constant, used " 1145 "to determine whether another step of classical Gram-Schmidt is " 1146 "necessary. Otherwise ignored.");
1153 template<
class ScalarType,
class MV,
class OP>
1156 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1159 Teuchos::RCP<const MV> rhsMV = problem_->getRHS();
1160 if (rhsMV == Teuchos::null) {
1167 TEUCHOS_TEST_FOR_EXCEPTION(static_cast<ptrdiff_t>(numBlocks_) > MVText::GetGlobalLength(*rhsMV),std::invalid_argument,
1168 "Belos::GCRODRSolMgr::initializeStateStorage(): Cannot generate a Krylov basis with dimension larger the operator!");
1171 if (U_ == Teuchos::null) {
1172 U_ = MVT::Clone( *rhsMV, recycledBlocks_+1 );
1176 if (MVT::GetNumberVecs(*U_) < recycledBlocks_+1) {
1177 Teuchos::RCP<const MV> tmp = U_;
1178 U_ = MVT::Clone( *tmp, recycledBlocks_+1 );
1183 if (C_ == Teuchos::null) {
1184 C_ = MVT::Clone( *rhsMV, recycledBlocks_+1 );
1188 if (MVT::GetNumberVecs(*C_) < recycledBlocks_+1) {
1189 Teuchos::RCP<const MV> tmp = C_;
1190 C_ = MVT::Clone( *tmp, recycledBlocks_+1 );
1195 if (V_ == Teuchos::null) {
1196 V_ = MVT::Clone( *rhsMV, numBlocks_+1 );
1200 if (MVT::GetNumberVecs(*V_) < numBlocks_+1) {
1201 Teuchos::RCP<const MV> tmp = V_;
1202 V_ = MVT::Clone( *tmp, numBlocks_+1 );
1207 if (U1_ == Teuchos::null) {
1208 U1_ = MVT::Clone( *rhsMV, recycledBlocks_+1 );
1212 if (MVT::GetNumberVecs(*U1_) < recycledBlocks_+1) {
1213 Teuchos::RCP<const MV> tmp = U1_;
1214 U1_ = MVT::Clone( *tmp, recycledBlocks_+1 );
1219 if (C1_ == Teuchos::null) {
1220 C1_ = MVT::Clone( *rhsMV, recycledBlocks_+1 );
1224 if (MVT::GetNumberVecs(*U1_) < recycledBlocks_+1) {
1225 Teuchos::RCP<const MV> tmp = C1_;
1226 C1_ = MVT::Clone( *tmp, recycledBlocks_+1 );
1231 if (r_ == Teuchos::null)
1232 r_ = MVT::Clone( *rhsMV, 1 );
1235 tau_.resize(recycledBlocks_+1);
1238 work_.resize(recycledBlocks_+1);
1241 ipiv_.resize(recycledBlocks_+1);
1244 if (H2_ == Teuchos::null)
1245 H2_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_+recycledBlocks_+2, numBlocks_+recycledBlocks_+1 ) );
1247 if ( (H2_->numRows() != numBlocks_+recycledBlocks_+2) || (H2_->numCols() != numBlocks_+recycledBlocks_+1) )
1248 H2_->reshape( numBlocks_+recycledBlocks_+2, numBlocks_+recycledBlocks_+1 );
1250 H2_->putScalar(zero);
1253 if (R_ == Teuchos::null)
1254 R_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( recycledBlocks_+1, recycledBlocks_+1 ) );
1256 if ( (R_->numRows() != recycledBlocks_+1) || (R_->numCols() != recycledBlocks_+1) )
1257 R_->reshape( recycledBlocks_+1, recycledBlocks_+1 );
1259 R_->putScalar(zero);
1262 if (PP_ == Teuchos::null)
1263 PP_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_+recycledBlocks_+2, recycledBlocks_+1 ) );
1265 if ( (PP_->numRows() != numBlocks_+recycledBlocks_+2) || (PP_->numCols() != recycledBlocks_+1) )
1266 PP_->reshape( numBlocks_+recycledBlocks_+2, recycledBlocks_+1 );
1270 if (HP_ == Teuchos::null)
1271 HP_ = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_+recycledBlocks_+2, numBlocks_+recycledBlocks_+1 ) );
1273 if ( (HP_->numRows() != numBlocks_+recycledBlocks_+2) || (HP_->numCols() != numBlocks_+recycledBlocks_+1) )
1274 HP_->reshape( numBlocks_+recycledBlocks_+2, numBlocks_+recycledBlocks_+1 );
1282 template<
class ScalarType,
class MV,
class OP>
1290 if (!isSet_) { setParameters( params_ ); }
1292 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1293 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1294 std::vector<int> index(numBlocks_+1);
1296 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null,
GCRODRSolMgrLinearProblemFailure,
"Belos::GCRODRSolMgr::solve(): Linear problem is not a valid object.");
1298 TEUCHOS_TEST_FOR_EXCEPTION(!problem_->isProblemSet(),
GCRODRSolMgrLinearProblemFailure,
"Belos::GCRODRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
1301 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
1302 std::vector<int> currIdx(1);
1306 problem_->setLSIndex( currIdx );
1309 ptrdiff_t dim = MVText::GetGlobalLength( *(problem_->getRHS()) );
1310 if (static_cast<ptrdiff_t>(numBlocks_) > dim) {
1311 numBlocks_ = Teuchos::as<int>(dim);
1313 "Warning! Requested Krylov subspace dimension is larger than operator dimension!" << std::endl <<
1314 " The maximum number of blocks allowed for the Krylov subspace will be adjusted to " << numBlocks_ << std::endl;
1315 params_->set(
"Num Blocks", numBlocks_);
1319 bool isConverged =
true;
1322 initializeStateStorage();
1326 Teuchos::ParameterList plist;
1328 plist.set(
"Num Blocks",numBlocks_);
1329 plist.set(
"Recycled Blocks",recycledBlocks_);
1334 RCP<GCRODRIter<ScalarType,MV,OP> > gcrodr_iter;
1337 int prime_iterations = 0;
1341 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1342 Teuchos::TimeMonitor slvtimer(*timerSolve_);
1345 while ( numRHS2Solve > 0 ) {
1348 builtRecycleSpace_ =
false;
1351 outputTest_->reset();
1359 "Belos::GCRODRSolMgr::solve(): Requested size of recycled subspace is not consistent with the current recycle subspace.");
1361 printer_->stream(
Debug) <<
" Now solving RHS index " << currIdx[0] <<
" using recycled subspace of dimension " << keff << std::endl << std::endl;
1364 for (
int ii=0; ii<keff; ++ii) { index[ii] = ii; }
1365 RCP<const MV> Utmp = MVT::CloneView( *U_, index );
1366 RCP<MV> Ctmp = MVT::CloneViewNonConst( *C_, index );
1367 problem_->apply( *Utmp, *Ctmp );
1369 RCP<MV> U1tmp = MVT::CloneViewNonConst( *U1_, index );
1373 Teuchos::SerialDenseMatrix<int,ScalarType> Rtmp( Teuchos::View, *R_, keff, keff );
1374 int rank = ortho_->normalize(*Ctmp, rcp(&Rtmp,
false));
1376 TEUCHOS_TEST_FOR_EXCEPTION(rank != keff,
GCRODRSolMgrOrthoFailure,
"Belos::GCRODRSolMgr::solve(): Failed to compute orthonormal basis for initial recycled subspace.");
1381 ipiv_.resize(Rtmp.numRows());
1382 lapack.GETRF(Rtmp.numRows(),Rtmp.numCols(),Rtmp.values(),Rtmp.stride(),&ipiv_[0],&info);
1383 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _GETRF failed to compute an LU factorization.");
1386 int lwork = Rtmp.numRows();
1387 work_.resize(lwork);
1388 lapack.GETRI(Rtmp.numRows(),Rtmp.values(),Rtmp.stride(),&ipiv_[0],&work_[0],lwork,&info);
1389 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _GETRI failed to invert triangular matrix.");
1392 MVT::MvTimesMatAddMv( one, *Utmp, Rtmp, zero, *U1tmp );
1397 for (
int ii=0; ii<keff; ++ii) { index[ii] = ii; }
1398 Ctmp = MVT::CloneViewNonConst( *C_, index );
1399 Utmp = MVT::CloneView( *U_, index );
1402 Teuchos::SerialDenseMatrix<int,ScalarType> Ctr(keff,1);
1403 problem_->computeCurrPrecResVec( &*r_ );
1404 MVT::MvTransMv( one, *Ctmp, *r_, Ctr );
1407 RCP<MV> update = MVT::Clone( *problem_->getCurrLHSVec(), 1 );
1408 MVT::MvInit( *update, 0.0 );
1409 MVT::MvTimesMatAddMv( one, *Utmp, Ctr, one, *update );
1410 problem_->updateSolution( update,
true );
1413 MVT::MvTimesMatAddMv( -one, *Ctmp, Ctr, one, *r_ );
1416 prime_iterations = 0;
1422 printer_->stream(
Debug) <<
" No recycled subspace available for RHS index " << currIdx[0] << std::endl << std::endl;
1424 Teuchos::ParameterList primeList;
1427 primeList.set(
"Num Blocks",numBlocks_);
1428 primeList.set(
"Recycled Blocks",0);
1431 RCP<GCRODRIter<ScalarType,MV,OP> > gcrodr_prime_iter;
1435 problem_->computeCurrPrecResVec( &*r_ );
1436 index.resize( 1 ); index[0] = 0;
1437 RCP<MV> v0 = MVT::CloneViewNonConst( *V_, index );
1438 MVT::SetBlock(*r_,index,*v0);
1442 index.resize( numBlocks_+1 );
1443 for (
int ii=0; ii<(numBlocks_+1); ++ii) { index[ii] = ii; }
1444 newstate.
V = MVT::CloneViewNonConst( *V_, index );
1445 newstate.
U = Teuchos::null;
1446 newstate.
C = Teuchos::null;
1447 newstate.
H = rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *H2_, numBlocks_+1, numBlocks_, recycledBlocks_+1, recycledBlocks_+1 ) );
1448 newstate.
B = Teuchos::null;
1450 gcrodr_prime_iter->initialize(newstate);
1453 bool primeConverged =
false;
1455 gcrodr_prime_iter->iterate();
1458 if ( convTest_->getStatus() ==
Passed ) {
1460 primeConverged =
true;
1465 gcrodr_prime_iter->updateLSQR( gcrodr_prime_iter->getCurSubspaceDim() );
1468 sTest_->checkStatus( &*gcrodr_prime_iter );
1469 if (convTest_->getStatus() ==
Passed)
1470 primeConverged =
true;
1472 catch (
const std::exception &e) {
1473 printer_->stream(
Errors) <<
"Error! Caught exception in GCRODRIter::iterate() at iteration " 1474 << gcrodr_prime_iter->getNumIters() << std::endl
1475 << e.what() << std::endl;
1479 prime_iterations = gcrodr_prime_iter->getNumIters();
1482 RCP<MV> update = gcrodr_prime_iter->getCurrentUpdate();
1483 problem_->updateSolution( update,
true );
1486 newstate = gcrodr_prime_iter->getState();
1494 if (recycledBlocks_ < p+1) {
1496 RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > PPtmp = rcp (
new Teuchos::SerialDenseMatrix<int,ScalarType> ( Teuchos::View, *PP_, p, recycledBlocks_+1 ) );
1498 keff = getHarmonicVecs1( p, *newstate.
H, *PPtmp );
1500 PPtmp = rcp (
new Teuchos::SerialDenseMatrix<int,ScalarType> ( Teuchos::View, *PP_, p, keff ) );
1503 for (
int ii=0; ii<keff; ++ii) { index[ii] = ii; }
1504 RCP<MV> Ctmp = MVT::CloneViewNonConst( *C_, index );
1505 RCP<MV> Utmp = MVT::CloneViewNonConst( *U_, index );
1506 RCP<MV> U1tmp = MVT::CloneViewNonConst( *U1_, index );
1508 for (
int ii=0; ii < p; ++ii) { index[ii] = ii; }
1509 RCP<const MV> Vtmp = MVT::CloneView( *V_, index );
1513 MVT::MvTimesMatAddMv( one, *Vtmp, *PPtmp, zero, *U1tmp );
1520 Teuchos::SerialDenseMatrix<int,ScalarType> Htmp( Teuchos::View, *H2_, p+1, p, recycledBlocks_+1,recycledBlocks_+1);
1521 Teuchos::SerialDenseMatrix<int,ScalarType> HPtmp( Teuchos::View, *HP_, p+1, keff );
1522 HPtmp.multiply( Teuchos::NO_TRANS, Teuchos::NO_TRANS, one, Htmp, *PPtmp, zero );
1527 lapack.GEQRF(HPtmp.numRows(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1528 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _GEQRF failed to compute a workspace size.");
1531 lwork = (int)work_[0];
1532 work_.resize(lwork);
1533 lapack.GEQRF(HPtmp.numRows(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1534 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _GEQRF failed to compute a QR factorization.");
1538 Teuchos::SerialDenseMatrix<int,ScalarType> Rtmp( Teuchos::View, *R_, keff, keff );
1539 for(
int ii=0;ii<keff;ii++) {
for(
int jj=ii;jj<keff;jj++) Rtmp(ii,jj) = HPtmp(ii,jj); }
1540 lapack.ORGQR(HPtmp.numRows(),HPtmp.numCols(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1541 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _ORGQR failed to construct the Q factor.");
1546 index.resize( p+1 );
1547 for (
int ii=0; ii < (p+1); ++ii) { index[ii] = ii; }
1548 Vtmp = MVT::CloneView( *V_, index );
1549 MVT::MvTimesMatAddMv( one, *Vtmp, HPtmp, zero, *Ctmp );
1556 ipiv_.resize(Rtmp.numRows());
1557 lapack.GETRF(Rtmp.numRows(),Rtmp.numCols(),Rtmp.values(),Rtmp.stride(),&ipiv_[0],&info);
1558 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _GETRF failed to compute an LU factorization.");
1561 lwork = Rtmp.numRows();
1562 work_.resize(lwork);
1563 lapack.GETRI(Rtmp.numRows(),Rtmp.values(),Rtmp.stride(),&ipiv_[0],&work_[0],lwork,&info);
1564 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _GETRI failed to invert triangular matrix.");
1567 MVT::MvTimesMatAddMv( one, *U1tmp, Rtmp, zero, *Utmp );
1569 printer_->stream(
Debug) <<
" Generated recycled subspace using RHS index " << currIdx[0] <<
" of dimension " << keff << std::endl << std::endl;
1574 if (primeConverged) {
1576 problem_->setCurrLS();
1580 if ( numRHS2Solve > 0 ) {
1584 problem_->setLSIndex( currIdx );
1587 currIdx.resize( numRHS2Solve );
1597 gcrodr_iter->setSize( keff, numBlocks_ );
1600 gcrodr_iter->resetNumIters(prime_iterations);
1603 outputTest_->resetNumCalls();
1606 problem_->computeCurrPrecResVec( &*r_ );
1607 index.resize( 1 ); index[0] = 0;
1608 RCP<MV> v0 = MVT::CloneViewNonConst( *V_, index );
1609 MVT::SetBlock(*r_,index,*v0);
1613 index.resize( numBlocks_+1 );
1614 for (
int ii=0; ii<(numBlocks_+1); ++ii) { index[ii] = ii; }
1615 newstate.
V = MVT::CloneViewNonConst( *V_, index );
1616 index.resize( keff );
1617 for (
int ii=0; ii<keff; ++ii) { index[ii] = ii; }
1618 newstate.
C = MVT::CloneViewNonConst( *C_, index );
1619 newstate.
U = MVT::CloneViewNonConst( *U_, index );
1620 newstate.
B = rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *H2_, keff, numBlocks_, 0, keff ) );
1621 newstate.
H = rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *H2_, numBlocks_+1, numBlocks_, keff, keff ) );
1623 gcrodr_iter->initialize(newstate);
1626 int numRestarts = 0;
1631 gcrodr_iter->iterate();
1638 if ( convTest_->getStatus() ==
Passed ) {
1647 else if ( maxIterTest_->getStatus() ==
Passed ) {
1649 isConverged =
false;
1657 else if ( gcrodr_iter->getCurSubspaceDim() == gcrodr_iter->getMaxSubspaceDim() ) {
1662 RCP<MV> update = gcrodr_iter->getCurrentUpdate();
1663 problem_->updateSolution( update,
true );
1665 buildRecycleSpace2(gcrodr_iter);
1667 printer_->stream(
Debug) <<
" Generated new recycled subspace using RHS index " << currIdx[0] <<
" of dimension " << keff << std::endl << std::endl;
1670 if ( numRestarts >= maxRestarts_ ) {
1671 isConverged =
false;
1676 printer_->stream(
Debug) <<
" Performing restart number " << numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
1679 problem_->computeCurrPrecResVec( &*r_ );
1680 index.resize( 1 ); index[0] = 0;
1681 RCP<MV> v00 = MVT::CloneViewNonConst( *V_, index );
1682 MVT::SetBlock(*r_,index,*v00);
1686 index.resize( numBlocks_+1 );
1687 for (
int ii=0; ii<(numBlocks_+1); ++ii) { index[ii] = ii; }
1688 restartState.
V = MVT::CloneViewNonConst( *V_, index );
1689 index.resize( keff );
1690 for (
int ii=0; ii<keff; ++ii) { index[ii] = ii; }
1691 restartState.
U = MVT::CloneViewNonConst( *U_, index );
1692 restartState.
C = MVT::CloneViewNonConst( *C_, index );
1693 restartState.
B = rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *H2_, keff, numBlocks_, 0, keff ) );
1694 restartState.
H = rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *H2_, numBlocks_+1, numBlocks_, keff, keff ) );
1696 gcrodr_iter->initialize(restartState);
1709 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Belos::GCRODRSolMgr::solve(): Invalid return from GCRODRIter::iterate().");
1714 gcrodr_iter->updateLSQR( gcrodr_iter->getCurSubspaceDim() );
1717 sTest_->checkStatus( &*gcrodr_iter );
1718 if (convTest_->getStatus() !=
Passed)
1719 isConverged =
false;
1722 catch (
const std::exception &e) {
1723 printer_->stream(
Errors) <<
"Error! Caught exception in GCRODRIter::iterate() at iteration " 1724 << gcrodr_iter->getNumIters() << std::endl
1725 << e.what() << std::endl;
1732 RCP<MV> update = gcrodr_iter->getCurrentUpdate();
1733 problem_->updateSolution( update,
true );
1736 problem_->setCurrLS();
1741 if (!builtRecycleSpace_) {
1742 buildRecycleSpace2(gcrodr_iter);
1743 printer_->stream(
Debug) <<
" Generated new recycled subspace using RHS index " << currIdx[0] <<
" of dimension " << keff << std::endl << std::endl;
1748 if ( numRHS2Solve > 0 ) {
1752 problem_->setLSIndex( currIdx );
1755 currIdx.resize( numRHS2Solve );
1766 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1771 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1775 numIters_ = maxIterTest_->getNumIters();
1787 const std::vector<MagnitudeType>* pTestValues = expConvTest_->getTestValue();
1788 if (pTestValues == NULL || pTestValues->size() < 1) {
1789 pTestValues = impConvTest_->getTestValue();
1791 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1792 "Belos::GCRODRSolMgr::solve(): The implicit convergence test's getTestValue() " 1793 "method returned NULL. Please report this bug to the Belos developers.");
1794 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1795 "Belos::GCRODRSolMgr::solve(): The implicit convergence test's getTestValue() " 1796 "method returned a vector of length zero. Please report this bug to the " 1797 "Belos developers.");
1802 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1812 template<
class ScalarType,
class MV,
class OP>
1815 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1816 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1818 std::vector<MagnitudeType> d(keff);
1819 std::vector<int> index(numBlocks_+1);
1831 for (
int ii=0; ii<keff; ++ii) { index[ii] = ii; }
1832 Teuchos::RCP<MV> Utmp = MVT::CloneViewNonConst( *U_, index );
1834 MVT::MvNorm( *Utmp, d );
1835 for (
int i=0; i<keff; ++i) {
1838 MVT::MvScale( *Utmp, d );
1842 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > H2tmp = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *H2_, p+keff+1, p+keff ) );
1845 for (
int i=0; i<keff; ++i) {
1846 (*H2tmp)(i,i) = d[i];
1853 Teuchos::SerialDenseMatrix<int,ScalarType> PPtmp( Teuchos::View, *PP_, p+keff, recycledBlocks_+1 );
1854 keff_new = getHarmonicVecs2( keff, p, *H2tmp, oldState.
V, PPtmp );
1861 Teuchos::RCP<MV> U1tmp;
1863 index.resize( keff );
1864 for (
int ii=0; ii<keff; ++ii) { index[ii] = ii; }
1865 Teuchos::RCP<const MV> Utmp = MVT::CloneView( *U_, index );
1866 index.resize( keff_new );
1867 for (
int ii=0; ii<keff_new; ++ii) { index[ii] = ii; }
1868 U1tmp = MVT::CloneViewNonConst( *U1_, index );
1869 Teuchos::SerialDenseMatrix<int,ScalarType> PPtmp( Teuchos::View, *PP_, keff, keff_new );
1870 MVT::MvTimesMatAddMv( one, *Utmp, PPtmp, zero, *U1tmp );
1876 for (
int ii=0; ii < p; ii++) { index[ii] = ii; }
1877 Teuchos::RCP<const MV> Vtmp = MVT::CloneView( *V_, index );
1878 Teuchos::SerialDenseMatrix<int,ScalarType> PPtmp( Teuchos::View, *PP_, p, keff_new, keff );
1879 MVT::MvTimesMatAddMv( one, *Vtmp, PPtmp, one, *U1tmp );
1883 Teuchos::SerialDenseMatrix<int,ScalarType> HPtmp( Teuchos::View, *HP_, p+keff+1, keff_new );
1885 Teuchos::SerialDenseMatrix<int,ScalarType> PPtmp( Teuchos::View, *PP_, p+keff, keff_new );
1886 HPtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,*H2tmp,PPtmp,zero);
1890 int info = 0, lwork = -1;
1891 tau_.resize(keff_new);
1892 lapack.GEQRF(HPtmp.numRows(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1893 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _GEQRF failed to compute a workspace size.");
1895 lwork = (int)work_[0];
1896 work_.resize(lwork);
1897 lapack.GEQRF(HPtmp.numRows(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1898 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _GEQRF failed to compute a QR factorization.");
1902 Teuchos::SerialDenseMatrix<int,ScalarType> Rtmp( Teuchos::View, *R_, keff_new, keff_new );
1903 for(
int i=0;i<keff_new;i++) {
for(
int j=i;j<keff_new;j++) Rtmp(i,j) = HPtmp(i,j); }
1904 lapack.ORGQR(HPtmp.numRows(),HPtmp.numCols(),HPtmp.numCols(),HPtmp.values(),HPtmp.stride(),&tau_[0],&work_[0],lwork,&info);
1905 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _ORGQR failed to construct the Q factor.");
1912 Teuchos::RCP<MV> C1tmp;
1915 for (
int i=0; i < keff; i++) { index[i] = i; }
1916 Teuchos::RCP<const MV> Ctmp = MVT::CloneView( *C_, index );
1917 index.resize(keff_new);
1918 for (
int i=0; i < keff_new; i++) { index[i] = i; }
1919 C1tmp = MVT::CloneViewNonConst( *C1_, index );
1920 Teuchos::SerialDenseMatrix<int,ScalarType> PPtmp( Teuchos::View, *HP_, keff, keff_new );
1921 MVT::MvTimesMatAddMv( one, *Ctmp, PPtmp, zero, *C1tmp );
1925 index.resize( p+1 );
1926 for (
int i=0; i < p+1; ++i) { index[i] = i; }
1927 Teuchos::RCP<const MV> Vtmp = MVT::CloneView( *V_, index );
1928 Teuchos::SerialDenseMatrix<int,ScalarType> PPtmp( Teuchos::View, *HP_, p+1, keff_new, keff, 0 );
1929 MVT::MvTimesMatAddMv( one, *Vtmp, PPtmp, one, *C1tmp );
1938 ipiv_.resize(Rtmp.numRows());
1939 lapack.GETRF(Rtmp.numRows(),Rtmp.numCols(),Rtmp.values(),Rtmp.stride(),&ipiv_[0],&info);
1940 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _GETRF failed to compute an LU factorization.");
1943 lwork = Rtmp.numRows();
1944 work_.resize(lwork);
1945 lapack.GETRI(Rtmp.numRows(),Rtmp.values(),Rtmp.stride(),&ipiv_[0],&work_[0],lwork,&info);
1946 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK _GETRI failed to compute an LU factorization.");
1949 index.resize(keff_new);
1950 for (
int i=0; i < keff_new; i++) { index[i] = i; }
1951 Teuchos::RCP<MV> Utmp = MVT::CloneViewNonConst( *U_, index );
1952 MVT::MvTimesMatAddMv( one, *U1tmp, Rtmp, zero, *Utmp );
1956 if (keff != keff_new) {
1958 gcrodr_iter->setSize( keff, numBlocks_ );
1960 Teuchos::SerialDenseMatrix<int,ScalarType> b1( Teuchos::View, *H2_, recycledBlocks_+2, 1, 0, recycledBlocks_ );
1968 template<
class ScalarType,
class MV,
class OP>
1970 const Teuchos::SerialDenseMatrix<int,ScalarType>& HH,
1971 Teuchos::SerialDenseMatrix<int,ScalarType>& PP) {
1973 bool xtraVec =
false;
1974 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1975 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1978 std::vector<MagnitudeType> wr(m), wi(m);
1981 Teuchos::SerialDenseMatrix<int,ScalarType> vr(m,m,
false);
1984 std::vector<MagnitudeType> w(m);
1987 std::vector<int> iperm(m);
1991 std::vector<ScalarType> work(lwork);
1997 builtRecycleSpace_ =
true;
2000 Teuchos::SerialDenseMatrix<int, ScalarType> HHt( HH,
Teuchos::TRANS );
2001 Teuchos::SerialDenseVector<int, ScalarType> e_m( m );
2003 lapack.GESV(m, 1, HHt.values(), HHt.stride(), &iperm[0], e_m.values(), e_m.stride(), &info);
2004 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK GESV failed to compute a solution.");
2007 ScalarType d = HH(m, m-1) * HH(m, m-1);
2008 Teuchos::SerialDenseMatrix<int, ScalarType> harmHH( HH );
2009 for( i=0; i<m; ++i )
2010 harmHH(i, m-1) += d * e_m[i];
2016 lapack.GEEV(
'N',
'V', m, harmHH.values(), harmHH.stride(), &wr[0], &wi[0],
2017 vl, ldvl, vr.values(), vr.stride(), &work[0], lwork, &info);
2018 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK GEEV failed to compute eigensolutions.");
2021 for( i=0; i<m; ++i )
2022 w[i] = Teuchos::ScalarTraits<ScalarType>::squareroot( wr[i]*wr[i] + wi[i]*wi[i] );
2025 this->sort(w, m, iperm);
2028 if (wi[iperm[recycledBlocks_-1]] != zero) {
2030 for ( i=0; i<recycledBlocks_; ++i ) {
2031 if (wi[iperm[i]] != zero)
2040 for( i=0; i<recycledBlocks_; ++i ) {
2041 for( j=0; j<m; j++ ) {
2042 PP(j,i) = vr(j,iperm[i]);
2047 if (wi[iperm[recycledBlocks_-1]] > 0) {
2048 for( j=0; j<m; ++j ) {
2049 PP(j,recycledBlocks_) = vr(j,iperm[recycledBlocks_-1]+1);
2053 for( j=0; j<m; ++j ) {
2054 PP(j,recycledBlocks_) = vr(j,iperm[recycledBlocks_-1]-1);
2061 return recycledBlocks_+1;
2063 return recycledBlocks_;
2067 template<
class ScalarType,
class MV,
class OP>
2069 const Teuchos::SerialDenseMatrix<int,ScalarType>& HH,
2070 const Teuchos::RCP<const MV>& VV,
2071 Teuchos::SerialDenseMatrix<int,ScalarType>& PP) {
2073 int m2 = HH.numCols();
2074 bool xtraVec =
false;
2075 ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
2076 ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
2077 std::vector<int> index;
2080 std::vector<ScalarType> wr(m2), wi(m2);
2083 std::vector<MagnitudeType> w(m2);
2086 Teuchos::SerialDenseMatrix<int,ScalarType> vr(m2,m2,
false);
2089 std::vector<int> iperm(m2);
2092 builtRecycleSpace_ =
true;
2097 Teuchos::SerialDenseMatrix<int,ScalarType> B(m2,m2,
false);
2102 Teuchos::SerialDenseMatrix<int,ScalarType> A_tmp( keffloc+m+1, keffloc+m );
2105 index.resize(keffloc);
2106 for (i=0; i<keffloc; ++i) { index[i] = i; }
2107 Teuchos::RCP<const MV> Ctmp = MVT::CloneView( *C_, index );
2108 Teuchos::RCP<const MV> Utmp = MVT::CloneView( *U_, index );
2109 Teuchos::SerialDenseMatrix<int,ScalarType> A11( Teuchos::View, A_tmp, keffloc, keffloc );
2110 MVT::MvTransMv( one, *Ctmp, *Utmp, A11 );
2113 Teuchos::SerialDenseMatrix<int,ScalarType> A21( Teuchos::View, A_tmp, m+1, keffloc, keffloc );
2115 for (i=0; i < m+1; i++) { index[i] = i; }
2116 Teuchos::RCP<const MV> Vp = MVT::CloneView( *VV, index );
2117 MVT::MvTransMv( one, *Vp, *Utmp, A21 );
2120 for( i=keffloc; i<keffloc+m; i++ ) {
2125 Teuchos::SerialDenseMatrix<int,ScalarType> A( m2, A_tmp.numCols() );
2126 A.multiply(
Teuchos::TRANS, Teuchos::NO_TRANS, one, HH, A_tmp, zero );
2134 char balanc=
'P', jobvl=
'N', jobvr=
'V', sense=
'N';
2135 int ld = A.numRows();
2137 int ldvl = ld, ldvr = ld;
2138 int info = 0,ilo = 0,ihi = 0;
2139 ScalarType abnrm = zero, bbnrm = zero;
2141 std::vector<ScalarType> beta(ld);
2142 std::vector<ScalarType> work(lwork);
2143 std::vector<MagnitudeType> lscale(ld), rscale(ld);
2144 std::vector<MagnitudeType> rconde(ld), rcondv(ld);
2145 std::vector<int> iwork(ld+6);
2147 lapack.GGEVX(balanc, jobvl, jobvr, sense, ld, A.values(), ld, B.values(), ld, &wr[0], &wi[0],
2148 &beta[0], vl, ldvl, vr.values(), ldvr, &ilo, &ihi, &lscale[0], &rscale[0],
2149 &abnrm, &bbnrm, &rconde[0], &rcondv[0], &work[0], lwork, &iwork[0], bwork, &info);
2150 TEUCHOS_TEST_FOR_EXCEPTION(info != 0,
GCRODRSolMgrLAPACKFailure,
"Belos::GCRODRSolMgr::solve(): LAPACK GGEVX failed to compute eigensolutions.");
2154 for( i=0; i<ld; i++ ) {
2155 w[i] = Teuchos::ScalarTraits<ScalarType>::squareroot( (wr[i]/beta[i])*(wr[i]/beta[i]) + (wi[i]/beta[i])*(wi[i]/beta[i]) );
2159 this->sort(w,ld,iperm);
2162 if (wi[iperm[ld-recycledBlocks_]] != zero) {
2164 for ( i=ld-recycledBlocks_; i<ld; i++ ) {
2165 if (wi[iperm[i]] != zero)
2174 for( i=0; i<recycledBlocks_; i++ ) {
2175 for( j=0; j<ld; j++ ) {
2176 PP(j,i) = vr(j,iperm[ld-recycledBlocks_+i]);
2181 if (wi[iperm[ld-recycledBlocks_]] > 0) {
2182 for( j=0; j<ld; j++ ) {
2183 PP(j,recycledBlocks_) = vr(j,iperm[ld-recycledBlocks_]+1);
2187 for( j=0; j<ld; j++ ) {
2188 PP(j,recycledBlocks_) = vr(j,iperm[ld-recycledBlocks_]-1);
2195 return recycledBlocks_+1;
2197 return recycledBlocks_;
2202 template<
class ScalarType,
class MV,
class OP>
2204 int l, r, j, i, flag;
2233 if (dlist[j] > dlist[j - 1]) j = j + 1;
2235 if (dlist[j - 1] > dK) {
2236 dlist[i - 1] = dlist[j - 1];
2237 iperm[i - 1] = iperm[j - 1];
2251 dlist[r] = dlist[0];
2252 iperm[r] = iperm[0];
2268 template<
class ScalarType,
class MV,
class OP>
2270 std::ostringstream oss;
2271 oss <<
"Belos::GCRODRSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<
">";
2273 oss <<
"Ortho Type='"<<orthoType_;
2274 oss <<
", Num Blocks=" <<numBlocks_;
2275 oss <<
", Num Recycle Blocks=" << recycledBlocks_;
2276 oss <<
", Max Restarts=" << maxRestarts_;
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.
std::string description() const
Method to return description of the block GMRES solver manager.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
GCRODRSolMgrLAPACKFailure(const std::string &what_arg)
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...
bool isLOADetected() const
Return whether a loss of accuracy was detected by this solver during the most current solve...
ScaleType
The type of scaling to use on the residual norm value.
Exception thrown to signal error in a status test during Belos::StatusTest::checkStatus().
GCRODRSolMgrLAPACKFailure is thrown when a nonzero value is retuned from an LAPACK call...
A factory class for generating StatusTestOutput objects.
Teuchos::RCP< const Teuchos::ParameterList > getDefaultParameters(const std::string &name) const
Default parameters for the given MatOrthoManager subclass.
An implementation of StatusTestResNorm using a family of residual norms.
GCRODRSolMgr()
Empty constructor for GCRODRSolMgr. This constructor takes no arguments and sets the default values f...
GCRODRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i.e.
GCRODRSolMgrRecyclingFailure(const std::string &what_arg)
This class implements the GCRODR iteration, where a single-std::vector Krylov subspace is constructed...
An extension of the MultiVecTraits class that adds a new vector length method.
Belos::StatusTest class for specifying a maximum number of iterations.
int curDim
The current dimension of the reduction.
A factory class for generating StatusTestOutput objects.
std::string validNamesString() const
List (as a string) of recognized MatOrthoManager names.
Teuchos::RCP< Belos::MatOrthoManager< Scalar, MV, OP > > makeMatOrthoManager(const std::string &ortho, const Teuchos::RCP< const OP > &M, const Teuchos::RCP< OutputManager< Scalar > > &outMan, const std::string &label, const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Return an instance of the specified MatOrthoManager subclass.
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.
GCRODRSolMgrOrthoFailure(const std::string &what_arg)
ResetType
How to reset the solver.
Pure virtual base class which describes the basic interface for a solver manager. ...
Teuchos::RCP< MV > V
The current Krylov basis.
bool isValidName(const std::string &name) const
Whether this factory recognizes the MatOrthoManager with the given name.
Teuchos::RCP< MV > U
The recycled subspace and its projection.
std::ostream & printValidNames(std::ostream &out) const
Print all recognized MatOrthoManager names to the given ostream.
A linear system to solve, and its associated information.
GCRODRSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate orthonorm...
Class which describes the linear problem to be solved by the iterative solver.
GCRODRIterOrthoFailure is thrown when the GCRODRIter object is unable to compute independent directio...
The Belos::GCRODRSolMgr provides a powerful and fully-featured solver manager over the GCRODR linear ...
virtual ~GCRODRSolMgr()
Destructor.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the parameters the solver manager should use to solve the linear problem.
ReturnType
Whether the Belos solve converged for all linear systems.
Belos concrete class for performing the GCRO-DR iteration.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Structure to contain pointers to GCRODRIter state variables.
GCRODRSolMgrRecyclingFailure is thrown when any problem occurs in using/creating the recycling subspa...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
int setTolerance(MagnitudeType tolerance)
Set the value of the tolerance.
GCRODRSolMgrLinearProblemFailure(const std::string &what_arg)
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.
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B
The projection of the Krylov subspace against the recycled subspace.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
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.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > H
The current Hessenberg matrix.
Parent class to all Belos exceptions.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get current linear problem being solved for in this object.
Belos header file which uses auto-configuration information to include necessary C++ headers...
Belos concrete class for performing the block, flexible GMRES iteration.
int getNumIters() const
Get the iteration count for the most recent call to solve().