94 typedef Teuchos::ScalarTraits<ScalarType> SCT;
95 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
96 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
129 Teuchos::ParameterList &
pl );
155 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
156 return Teuchos::tuple(_timerSolve, _timerRestarting, _timerLocking);
208 Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > problem_;
210 std::string whch_, ortho_;
212 MagnitudeType convtol_, locktol_;
215 bool relconvtol_, rellocktol_;
216 int blockSize_, numBlocks_, numIters_;
220 int numRestartBlocks_;
221 enum ResType convNorm_, lockNorm_;
223 Teuchos::RCP<Teuchos::Time> _timerSolve, _timerRestarting, _timerLocking;
225 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > globalTest_;
226 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > lockingTest_;
227 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > debugTest_;
229 Teuchos::RCP<OutputManager<ScalarType> > printer_;
237 Teuchos::ParameterList &
pl ) :
241 convtol_(MT::
prec()),
251 inSituRestart_(
false),
262 TEUCHOS_TEST_FOR_EXCEPTION(problem_->getInitVec() == Teuchos::null,std::invalid_argument,
"Problem does not contain initial vectors to clone from.");
267 whch_ =
pl.get(
"Which",whch_);
268 TEUCHOS_TEST_FOR_EXCEPTION(whch_ !=
"SM" && whch_ !=
"LM" && whch_ !=
"SR" && whch_ !=
"LR",std::invalid_argument,
"Invalid sorting string.");
271 ortho_ =
pl.get(
"Orthogonalization",ortho_);
272 if (ortho_ !=
"DGKS" && ortho_ !=
"SVQB") {
277 convtol_ =
pl.get(
"Convergence Tolerance",convtol_);
278 relconvtol_ =
pl.get(
"Relative Convergence Tolerance",relconvtol_);
279 strtmp =
pl.get(
"Convergence Norm",std::string(
"2"));
281 convNorm_ = RES_2NORM;
284 convNorm_ = RES_ORTH;
288 "Anasazi::BlockDavidsonSolMgr: Invalid Convergence Norm.");
292 useLocking_ =
pl.get(
"Use Locking",useLocking_);
293 rellocktol_ =
pl.get(
"Relative Locking Tolerance",rellocktol_);
295 locktol_ = convtol_/10;
296 locktol_ =
pl.get(
"Locking Tolerance",locktol_);
297 strtmp =
pl.get(
"Locking Norm",std::string(
"2"));
299 lockNorm_ = RES_2NORM;
302 lockNorm_ = RES_ORTH;
306 "Anasazi::BlockDavidsonSolMgr: Invalid Locking Norm.");
310 maxRestarts_ =
pl.get(
"Maximum Restarts",maxRestarts_);
313 blockSize_ =
pl.get(
"Block Size",problem_->getNEV());
315 "Anasazi::BlockDavidsonSolMgr: \"Block Size\" must be strictly positive.");
316 numBlocks_ =
pl.get(
"Num Blocks",2);
318 "Anasazi::BlockDavidsonSolMgr: \"Num Blocks\" must be >= 1.");
322 maxLocked_ =
pl.get(
"Max Locked",problem_->getNEV());
327 if (maxLocked_ == 0) {
331 "Anasazi::BlockDavidsonSolMgr: \"Max Locked\" must be positive.");
333 std::invalid_argument,
334 "Anasazi::BlockDavidsonSolMgr: Not enough storage space for requested number of eigenpairs.");
336 std::invalid_argument,
337 "Anasazi::BlockDavidsonSolMgr: Potentially impossible orthogonality requests. Reduce basis size or locking size.");
340 lockQuorum_ =
pl.get(
"Locking Quorum",lockQuorum_);
342 std::invalid_argument,
343 "Anasazi::BlockDavidsonSolMgr: \"Locking Quorum\" must be strictly positive.");
347 numRestartBlocks_ =
pl.get(
"Num Restart Blocks",numRestartBlocks_);
349 "Anasazi::BlockDavidsonSolMgr: \"Num Restart Blocks\" must be strictly positive.");
351 "Anasazi::BlockDavidsonSolMgr: \"Num Restart Blocks\" must be strictly less than \"Num Blocks\".");
354 if (
pl.isParameter(
"In Situ Restarting")) {
355 if (Teuchos::isParameterType<bool>(
pl,
"In Situ Restarting")) {
356 inSituRestart_ =
pl.get(
"In Situ Restarting",inSituRestart_);
358 inSituRestart_ = ( Teuchos::getParameter<int>(
pl,
"In Situ Restarting") != 0 );
365 int osProc =
pl.get(
"Output Processor", 0);
368 Teuchos::RCP<Teuchos::FancyOStream>
osp;
371 if (
pl.isParameter(
"Output Stream")) {
372 osp = Teuchos::getParameter<Teuchos::RCP<Teuchos::FancyOStream> >(
pl,
"Output Stream");
380 if (
pl.isParameter(
"Verbosity")) {
381 if (Teuchos::isParameterType<int>(
pl,
"Verbosity")) {
384 verbosity = (
int)Teuchos::getParameter<Anasazi::MsgType>(
pl,
"Verbosity");
399 const int nev = problem_->getNEV();
402 Teuchos::RCP<Teuchos::FancyOStream>
403 out = Teuchos::getFancyOStream(Teuchos::rcpFromRef(printer_->stream(
Debug)));
404 out->setShowAllFrontMatter(
false).setShowProcRank(
true);
405 *
out <<
"Entering Anasazi::BlockDavidsonSolMgr::solve()\n";
416 Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
convtest;
417 if (globalTest_ == Teuchos::null) {
423 Teuchos::RCP<StatusTestWithOrdering<ScalarType,MV,OP> >
ordertest
426 Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
locktest;
428 if (lockingTest_ == Teuchos::null) {
436 Teuchos::Array<Teuchos::RCP<StatusTest<ScalarType,MV,OP> > >
alltests;
439 if (debugTest_ != Teuchos::null)
alltests.push_back(debugTest_);
441 Teuchos::RCP<StatusTestCombo<ScalarType,MV,OP> >
combotest
444 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> >
outputtest;
445 if ( printer_->isVerbosity(
Debug) ) {
454 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> >
ortho;
455 if (ortho_==
"SVQB") {
457 }
else if (ortho_==
"DGKS") {
460 TEUCHOS_TEST_FOR_EXCEPTION(ortho_!=
"SVQB"&&ortho_!=
"DGKS",std::logic_error,
"Anasazi::BlockDavidsonSolMgr::solve(): Invalid orthogonalization type.");
465 Teuchos::ParameterList
plist;
466 plist.set(
"Block Size",blockSize_);
467 plist.set(
"Num Blocks",numBlocks_);
471 Teuchos::RCP<BlockDavidson<ScalarType,MV,OP> >
bd_solver
474 Teuchos::RCP< const MV >
probauxvecs = problem_->getAuxVecs();
490 if (maxLocked_ > 0) {
491 lockvecs = MVT::Clone(*problem_->getInitVec(),maxLocked_);
493 std::vector<MagnitudeType>
lockvals;
542 if (inSituRestart_ ==
false) {
544 if (useLocking_==
true || maxRestarts_ > 0) {
545 workMV = MVT::Clone(*problem_->getInitVec(),(numBlocks_-1)*blockSize_);
558 if (maxRestarts_ > 0) {
559 workMV = MVT::Clone(*problem_->getInitVec(),1);
567 const ScalarType ONE = SCT::one();
568 const ScalarType ZERO = SCT::zero();
569 Teuchos::LAPACK<int,ScalarType>
lapack;
570 Teuchos::BLAS<int,ScalarType>
blas;
575 problem_->setSolution(
sol);
581#ifdef ANASAZI_TEUCHOS_TIME_MONITOR
582 Teuchos::TimeMonitor
slvtimer(*_timerSolve);
595 if (debugTest_ != Teuchos::null && debugTest_->getStatus() ==
Passed) {
596 throw AnasaziError(
"Anasazi::BlockDavidsonSolMgr::solve(): User-specified debug status test returned Passed.");
616#ifdef ANASAZI_TEUCHOS_TIME_MONITOR
617 Teuchos::TimeMonitor
restimer(*_timerRestarting);
625 printer_->stream(
IterationDetails) <<
" Performing restart number " <<
numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
629 int newdim = numRestartBlocks_*blockSize_;
634 *
out <<
"Ritz values from solver:\n";
644 Teuchos::SerialDenseMatrix<int,ScalarType> S(
curdim,
curdim);
649 std::stringstream
os;
650 os <<
"KK before HEEV...\n"
657 "Anasazi::BlockDavidsonSolMgr::solve(): error calling SolverUtils::directSolver.");
659 "Anasazi::BlockDavidsonSolMgr::solve(): direct solve did not compute all eigenvectors.");
663 std::stringstream
os;
664 *
out <<
"Ritz values from heev(KK):\n";
666 os <<
"\nRitz vectors from heev(KK):\n"
679 msutils::permuteVectors(
order,S);
683 std::stringstream
os;
684 *
out <<
"Ritz values from heev(KK) after sorting:\n";
685 std::copy(
theta.begin(),
theta.end(), std::ostream_iterator<ScalarType>(*
out,
" "));
686 os <<
"\nRitz vectors from heev(KK) after sorting:\n"
693 Teuchos::SerialDenseMatrix<int,ScalarType>
Sr(Teuchos::View,S,
curdim,
newdim);
696 std::stringstream
os;
697 os <<
"Significant primitive Ritz vectors:\n"
712 "Anasazi::BlockDavidsonSolMgr::solve(): Logic error calling SerialDenseMatrix::multiply.");
716 "Anasazi::BlockDavidsonSolMgr::solve(): Logic error calling SerialDenseMatrix::multiply.");
726 std::stringstream
os;
748 if (inSituRestart_ ==
true) {
750 *
out <<
"Beginning in-situ restart...\n";
762 "Anasazi::BlockDavidsonSolMgr::solve(): error calling GEQRF during restarting.");
763 if (printer_->isVerbosity(
Debug)) {
764 Teuchos::SerialDenseMatrix<int,ScalarType> R(Teuchos::Copy,
Sr,
newdim,
newdim);
766 R(
j,
j) = SCT::magnitude(R(
j,
j)) - 1.0;
771 printer_->stream(
Debug) <<
"||Triangular factor of Sr - I||: " << R.normFrobenius() << std::endl;
791 *
out <<
"Beginning ex-situ restart...\n";
800 MVT::MvTimesMatAddMv(ONE,*
oldV,
Sr,ZERO,*
newV);
817#ifdef ANASAZI_TEUCHOS_TIME_MONITOR
818 Teuchos::TimeMonitor
lcktimer(*_timerLocking);
829 "Anasazi::BlockDavidsonSolMgr::solve(): status test mistake: howMany() non-positive.");
831 "Anasazi::BlockDavidsonSolMgr::solve(): status test mistake: howMany() not consistent with whichVecs().");
834 "Anasazi::BlockDavidsonSolMgr::solve(): status test mistake: locking not deactivated.");
861 if (printer_->isVerbosity(
Debug)) {
862 printer_->print(
Debug,
"Locking vectors: ");
864 printer_->print(
Debug,
"\n");
865 printer_->print(
Debug,
"Not locking vectors: ");
867 printer_->print(
Debug,
"\n");
878 Teuchos::SerialDenseMatrix<int,ScalarType> S(
curdim,
curdim);
884 "Anasazi::BlockDavidsonSolMgr::solve(): error calling SolverUtils::directSolver.");
886 "Anasazi::BlockDavidsonSolMgr::solve(): direct solve did not compute all eigenvectors.");
893 msutils::permuteVectors(
order,S);
915 if (inSituRestart_ ==
true) {
922 Teuchos::SerialDenseMatrix<int,ScalarType>
copySu(
Su);
927 "Anasazi::BlockDavidsonSolMgr::solve(): error calling GEQRF during restarting.");
928 if (printer_->isVerbosity(
Debug)) {
931 R(
j,
j) = SCT::magnitude(R(
j,
j)) - 1.0;
936 printer_->stream(
Debug) <<
"||Triangular factor of Su - I||: " << R.normFrobenius() << std::endl;
961 MVT::MvTimesMatAddMv(ONE,*
oldV,
Su,ZERO,*
defV);
998 MVT::MvRandom(*
augV);
1003 Teuchos::Array<Teuchos::RCP<const MV> >
against;
1004 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > >
dummyC;
1009 if (problem_->getM() != Teuchos::null) {
1032 "Anasazi::BlockDavidsonSolMgr::solve(): Logic error calling SerialDenseMatrix::multiply.");
1036 "Anasazi::BlockDavidsonSolMgr::solve(): Logic error calling SerialDenseMatrix::multiply.");
1041 OPT::Apply(*problem_->getOperator(),*
augV,*
augTmp);
1049 defV = Teuchos::null;
1050 augV = Teuchos::null;
1084 Teuchos::Array< Teuchos::RCP<const MV> >
aux;
1099 if (inSituRestart_) {
1119 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Anasazi::BlockDavidsonSolMgr::solve(): Invalid return from bd_solver::iterate().");
1124 <<
"Anasazi::BlockDavidsonSolMgr::solve() caught unexpected exception from Anasazi::BlockDavidson::iterate() at iteration " <<
bd_solver->getNumIters() << std::endl
1125 <<
err.what() << std::endl
1126 <<
"Anasazi::BlockDavidsonSolMgr::solve() returning Unconverged with no solutions." << std::endl;
1135 if (
sol.numVecs > 0) {
1136 sol.Evecs = MVT::Clone(*problem_->getInitVec(),
sol.numVecs);
1138 sol.Evals.resize(
sol.numVecs);
1139 std::vector<MagnitudeType>
vals(
sol.numVecs);
1147 for (
unsigned int i=0;
i<
which.size();
i++) {
1193 std::vector<int>
order(
sol.numVecs);
1196 for (
int i=0;
i<
sol.numVecs;
i++) {
1198 sol.Evals[
i].imagpart = MT::zero();
1201 msutils::permuteVectors(
sol.numVecs,
order,*
sol.Evecs);
1205 sol.index.resize(
sol.numVecs,0);
1213#ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1215 Teuchos::TimeMonitor::summarize( printer_->stream(
TimingDetails ) );
1219 problem_->setSolution(
sol);
1220 printer_->stream(
Debug) <<
"Returning " <<
sol.numVecs <<
" eigenpairs to eigenproblem." << std::endl;