147 typedef Teuchos::ScalarTraits<ScalarType> SCT;
148 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
149 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
184 Teuchos::ParameterList &
pl );
209 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
210 return Teuchos::tuple(_timerSolve, _timerLocking);
268 Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > problem_;
270 std::string whch_, ortho_;
272 MagnitudeType convtol_, locktol_;
273 int maxIters_, numIters_;
275 bool relconvtol_, rellocktol_;
282 Teuchos::RCP<LOBPCGState<ScalarType,MV> > state_;
283 enum ResType convNorm_, lockNorm_;
286 Teuchos::RCP<Teuchos::Time> _timerSolve, _timerLocking;
288 Teuchos::RCP<Teuchos::FancyOStream> osp_;
290 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > globalTest_;
291 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > lockingTest_;
292 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > debugTest_;
300 Teuchos::ParameterList &
pl ) :
304 convtol_(MT::
prec()),
325 TEUCHOS_TEST_FOR_EXCEPTION(problem_->getInitVec() == Teuchos::null,std::invalid_argument,
"Problem does not contain initial vectors to clone from.");
331 whch_ =
pl.get(
"Which",whch_);
333 std::invalid_argument,
"Anasazi::LOBPCGSolMgr: Invalid sorting string.");
336 ortho_ =
pl.get(
"Orthogonalization",ortho_);
337 if (ortho_ !=
"DGKS" && ortho_ !=
"SVQB" && ortho_ !=
"ICGS") {
342 convtol_ =
pl.get(
"Convergence Tolerance",convtol_);
343 relconvtol_ =
pl.get(
"Relative Convergence Tolerance",relconvtol_);
344 strtmp =
pl.get(
"Convergence Norm",std::string(
"2"));
346 convNorm_ = RES_2NORM;
349 convNorm_ = RES_ORTH;
353 "Anasazi::LOBPCGSolMgr: Invalid Convergence Norm.");
358 useLocking_ =
pl.get(
"Use Locking",useLocking_);
359 rellocktol_ =
pl.get(
"Relative Locking Tolerance",rellocktol_);
361 locktol_ = convtol_/10;
362 locktol_ =
pl.get(
"Locking Tolerance",locktol_);
363 strtmp =
pl.get(
"Locking Norm",std::string(
"2"));
365 lockNorm_ = RES_2NORM;
368 lockNorm_ = RES_ORTH;
372 "Anasazi::LOBPCGSolMgr: Invalid Locking Norm.");
376 maxIters_ =
pl.get(
"Maximum Iterations",maxIters_);
379 blockSize_ =
pl.get(
"Block Size",problem_->getNEV());
381 "Anasazi::LOBPCGSolMgr: \"Block Size\" must be strictly positive.");
385 maxLocked_ =
pl.get(
"Max Locked",problem_->getNEV());
390 if (maxLocked_ == 0) {
394 "Anasazi::LOBPCGSolMgr: \"Max Locked\" must be positive.");
396 std::invalid_argument,
397 "Anasazi::LOBPCGSolMgr: Not enough storage space for requested number of eigenpairs.");
400 lockQuorum_ =
pl.get(
"Locking Quorum",lockQuorum_);
402 std::invalid_argument,
403 "Anasazi::LOBPCGSolMgr: \"Locking Quorum\" must be strictly positive.");
407 fullOrtho_ =
pl.get(
"Full Ortho",fullOrtho_);
411 osProc_ =
pl.get(
"Output Processor", osProc_);
414 if (
pl.isParameter(
"Output Stream")) {
415 osp_ = Teuchos::getParameter<Teuchos::RCP<Teuchos::FancyOStream> >(
pl,
"Output Stream");
422 if (
pl.isParameter(
"Verbosity")) {
423 if (Teuchos::isParameterType<int>(
pl,
"Verbosity")) {
424 verbosity_ =
pl.get(
"Verbosity", verbosity_);
426 verbosity_ = (
int)Teuchos::getParameter<Anasazi::MsgType>(
pl,
"Verbosity");
431 recover_ =
pl.get(
"Recover",recover_);
434 if (
pl.isParameter(
"Init")) {
435 state_ = Teuchos::getParameter<Teuchos::RCP<Anasazi::LOBPCGState<ScalarType,MV> > >(
pl,
"Init");
447 const int nev = problem_->getNEV();
463 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> >
maxtest;
468 Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
convtest;
469 if (globalTest_ == Teuchos::null) {
475 Teuchos::RCP<StatusTestWithOrdering<ScalarType,MV,OP> >
ordertest
478 Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
locktest;
480 if (lockingTest_ == Teuchos::null) {
488 Teuchos::Array<Teuchos::RCP<StatusTest<ScalarType,MV,OP> > >
alltests;
491 if (debugTest_ != Teuchos::null)
alltests.push_back(debugTest_);
493 Teuchos::RCP<StatusTestCombo<ScalarType,MV,OP> >
combotest
496 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> >
outputtest;
506 Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> >
ortho;
507 if (ortho_==
"SVQB") {
509 }
else if (ortho_==
"DGKS") {
511 }
else if (ortho_==
"ICGS") {
514 TEUCHOS_TEST_FOR_EXCEPTION(ortho_!=
"SVQB"&&ortho_!=
"DGKS"&&ortho_!=
"ICGS",std::logic_error,
"Anasazi::LOBPCGSolMgr::solve(): Invalid orthogonalization type.");
519 Teuchos::ParameterList
plist;
520 plist.set(
"Block Size",blockSize_);
521 plist.set(
"Full Ortho",fullOrtho_);
528 Teuchos::RCP< const MV >
probauxvecs = problem_->getAuxVecs();
540 lockvecs = MVT::Clone(*problem_->getInitVec(),maxLocked_);
542 std::vector<MagnitudeType>
lockvals;
552 if (fullOrtho_ ==
false && recover_ ==
true) {
553 workMV = MVT::Clone(*problem_->getInitVec(),2*3*blockSize_);
555 else if (useLocking_) {
556 if (problem_->getM() != Teuchos::null) {
557 workMV = MVT::Clone(*problem_->getInitVec(),4*blockSize_);
560 workMV = MVT::Clone(*problem_->getInitVec(),2*blockSize_);
567 problem_->setSolution(
sol);
570 if (state_ != Teuchos::null) {
576#ifdef ANASAZI_TEUCHOS_TIME_MONITOR
577 Teuchos::TimeMonitor
slvtimer(*_timerSolve);
590 if (debugTest_ != Teuchos::null && debugTest_->getStatus() ==
Passed) {
591 throw AnasaziError(
"Anasazi::LOBPCGSolMgr::solve(): User-specified debug status test returned Passed.");
611#ifdef ANASAZI_TEUCHOS_TIME_MONITOR
612 Teuchos::TimeMonitor
lcktimer(*_timerLocking);
617 "Anasazi::LOBPCGSolMgr::solve(): status test mistake: howMany() non-positive.");
619 "Anasazi::LOBPCGSolMgr::solve(): status test mistake: howMany() not consistent with whichVecs().");
621 "Anasazi::LOBPCGSolMgr::solve(): status test mistake: locking not deactivated.");
643 Teuchos::RCP<const MV>
newvecs;
686 std::vector<int>
bsind(blockSize_);
687 for (
int i=0;
i<blockSize_;
i++)
bsind[
i] =
i;
691 if (
state.MX != Teuchos::null) {
692 std::vector<int>
block3(blockSize_);
693 for (
int i=0;
i<blockSize_;
i++)
block3[
i] = 2*blockSize_+
i;
701 MVT::MvRandom(*
newX);
705 OPT::Apply(*problem_->getM(),*
newX,*
newMX);
710 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > >
dummyC;
717 std::vector<int>
block2(blockSize_);
718 for (
int i=0;
i<blockSize_;
i++)
block2[
i] = blockSize_+
i;
722 if (
state.MP != Teuchos::null) {
723 std::vector<int>
block4(blockSize_);
724 for (
int i=0;
i<blockSize_;
i++)
block4[
i] = 3*blockSize_+
i;
754 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Anasazi::LOBPCGSolMgr::solve(): Invalid return from lobpcg_solver::iterate().");
763 if (fullOrtho_==
true || recover_==
false) {
768 <<
"Will not try to recover." << std::endl;
772 <<
"Full orthogonalization is off; will try to recover." << std::endl;
780 bool hasM = problem_->getM() != Teuchos::null;
802 std::vector<int>
blk1(blockSize_);
803 for (
int i=0;
i < blockSize_;
i++)
blk1[
i] =
i;
814 std::vector<int>
blk2(blockSize_);
815 for (
int i=0;
i < blockSize_;
i++)
blk2[
i] = blockSize_+
i;
825 std::vector<int>
blk3(blockSize_);
826 for (
int i=0;
i < blockSize_;
i++)
blk3[
i] = 2*blockSize_+
i;
835 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > >
dummyC;
836 Teuchos::Array<Teuchos::RCP<const MV> > Q;
849 if (
rank < blockSize_) {
851 printer->stream(
Errors) <<
"Error! Recovered basis only rank " <<
rank <<
". Block size is " << blockSize_ <<
".\n"
852 <<
"Recovery failed." << std::endl;
884 if (
rank < blockSize_) {
885 printer->stream(
Errors) <<
"Error! Recovered basis of rank " <<
rank <<
" produced only " <<
rank <<
"ritz vectors.\n"
886 <<
"Block size is " << blockSize_ <<
".\n"
887 <<
"Recovery failed." << std::endl;
894 Teuchos::BLAS<int,ScalarType>
blas;
899 Teuchos::SerialDenseMatrix<int,ScalarType>
curS(Teuchos::View,S,
rank,
rank);
903 Teuchos::SerialDenseMatrix<int,ScalarType>
S1(Teuchos::View,S,
localsize,blockSize_);
907 Teuchos::RCP<MV>
newX;
909 std::vector<int>
bsind(blockSize_);
910 for (
int i=0;
i<blockSize_;
i++)
bsind[
i] =
i;
916 theta.resize(blockSize_);
923 <<
"Anasazi::LOBPCGSolMgr::solve() caught unexpected exception from Anasazi::LOBPCG::iterate() at iteration " <<
lobpcg_solver->getNumIters() << std::endl
924 <<
err.what() << std::endl
925 <<
"Anasazi::LOBPCGSolMgr::solve() returning Unconverged with no solutions." << std::endl;
932 if (
sol.numVecs > 0) {
933 sol.Evecs = MVT::Clone(*problem_->getInitVec(),
sol.numVecs);
935 sol.Evals.resize(
sol.numVecs);
936 std::vector<MagnitudeType>
vals(
sol.numVecs);
944 for (
unsigned int i=0;
i<
which.size();
i++) {
990 std::vector<int>
order(
sol.numVecs);
993 for (
int i=0;
i<
sol.numVecs;
i++) {
995 sol.Evals[
i].imagpart = MT::zero();
998 msutils::permuteVectors(
sol.numVecs,
order,*
sol.Evecs);
1002 sol.index.resize(
sol.numVecs,0);
1010#ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1016 problem_->setSolution(
sol);
1017 printer->stream(
Debug) <<
"Returning " <<
sol.numVecs <<
" eigenpairs to eigenproblem." << std::endl;