52 #ifndef ANASAZI_LOBPCG_HPP
53 #define ANASAZI_LOBPCG_HPP
60 #include "Teuchos_ScalarTraits.hpp"
65 #include "Teuchos_LAPACK.hpp"
66 #include "Teuchos_BLAS.hpp"
67 #include "Teuchos_SerialDenseMatrix.hpp"
68 #include "Teuchos_ParameterList.hpp"
69 #include "Teuchos_TimeMonitor.hpp"
100 template <
class ScalarType,
class MultiVector>
103 Teuchos::RCP<const MultiVector>
V;
105 Teuchos::RCP<const MultiVector>
KV;
107 Teuchos::RCP<const MultiVector>
MV;
110 Teuchos::RCP<const MultiVector>
X;
112 Teuchos::RCP<const MultiVector>
KX;
114 Teuchos::RCP<const MultiVector>
MX;
117 Teuchos::RCP<const MultiVector>
P;
119 Teuchos::RCP<const MultiVector>
KP;
121 Teuchos::RCP<const MultiVector>
MP;
127 Teuchos::RCP<const MultiVector>
H;
129 Teuchos::RCP<const MultiVector>
KH;
131 Teuchos::RCP<const MultiVector>
MH;
134 Teuchos::RCP<const MultiVector>
R;
137 Teuchos::RCP<const std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> >
T;
140 V(Teuchos::null),
KV(Teuchos::null),
MV(Teuchos::null),
141 X(Teuchos::null),
KX(Teuchos::null),
MX(Teuchos::null),
142 P(Teuchos::null),
KP(Teuchos::null),
MP(Teuchos::null),
143 H(Teuchos::null),
KH(Teuchos::null),
MH(Teuchos::null),
144 R(Teuchos::null),
T(Teuchos::null) {};
208 template <
class ScalarType,
class MV,
class OP>
223 const Teuchos::RCP<
SortManager<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
227 Teuchos::ParameterList ¶ms
373 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
getResNorms();
381 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
getRes2Norms();
391 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
getRitzRes2Norms();
418 Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
getStatusTest()
const;
450 void setAuxVecs(
const Teuchos::Array<Teuchos::RCP<const MV> > &auxvecs);
453 Teuchos::Array<Teuchos::RCP<const MV> >
getAuxVecs()
const;
495 typedef Teuchos::ScalarTraits<ScalarType> SCT;
496 typedef typename SCT::magnitudeType MagnitudeType;
497 const MagnitudeType ONE;
498 const MagnitudeType ZERO;
499 const MagnitudeType NANVAL;
504 bool checkX, checkMX, checkKX;
505 bool checkH, checkMH;
506 bool checkP, checkMP, checkKP;
508 CheckList() : checkX(false),checkMX(false),checkKX(false),
509 checkH(false),checkMH(false),
510 checkP(false),checkMP(false),checkKP(false),
511 checkR(false),checkQ(false) {};
516 std::string accuracyCheck(
const CheckList &chk,
const std::string &where)
const;
520 const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > problem_;
521 const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > sm_;
522 const Teuchos::RCP<OutputManager<ScalarType> > om_;
523 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > tester_;
524 const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > orthman_;
528 Teuchos::RCP<const OP> Op_;
529 Teuchos::RCP<const OP> MOp_;
530 Teuchos::RCP<const OP> Prec_;
535 Teuchos::RCP<Teuchos::Time> timerOp_, timerMOp_, timerPrec_,
537 timerLocalProj_, timerDS_,
538 timerLocalUpdate_, timerCompRes_,
539 timerOrtho_, timerInit_;
544 int count_ApplyOp_, count_ApplyM_, count_ApplyPrec_;
573 Teuchos::RCP<MV> V_, KV_, MV_, R_;
575 Teuchos::RCP<MV> X_, KX_, MX_,
589 Teuchos::RCP<MV> tmpmvec_;
592 Teuchos::Array<Teuchos::RCP<const MV> > auxVecs_;
599 std::vector<MagnitudeType> theta_, Rnorms_, R2norms_;
602 bool Rnorms_current_, R2norms_current_;
611 template <
class ScalarType,
class MV,
class OP>
614 const Teuchos::RCP<
SortManager<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
618 Teuchos::ParameterList ¶ms
620 ONE(Teuchos::ScalarTraits<MagnitudeType>::one()),
621 ZERO(Teuchos::ScalarTraits<MagnitudeType>::zero()),
622 NANVAL(Teuchos::ScalarTraits<MagnitudeType>::nan()),
630 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
631 timerOp_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Operation Op*x")),
632 timerMOp_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Operation M*x")),
633 timerPrec_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Operation Prec*x")),
634 timerSort_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Sorting eigenvalues")),
635 timerLocalProj_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Local projection")),
636 timerDS_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Direct solve")),
637 timerLocalUpdate_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Local update")),
638 timerCompRes_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Computing residuals")),
639 timerOrtho_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Orthogonalization")),
640 timerInit_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: LOBPCG::Initialization")),
647 fullOrtho_(params.get(
"Full Ortho", true)),
651 auxVecs_( Teuchos::Array<Teuchos::RCP<const MV> >(0) ),
654 Rnorms_current_(false),
655 R2norms_current_(false)
657 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null,std::invalid_argument,
658 "Anasazi::LOBPCG::constructor: user passed null problem pointer.");
659 TEUCHOS_TEST_FOR_EXCEPTION(sm_ == Teuchos::null,std::invalid_argument,
660 "Anasazi::LOBPCG::constructor: user passed null sort manager pointer.");
661 TEUCHOS_TEST_FOR_EXCEPTION(om_ == Teuchos::null,std::invalid_argument,
662 "Anasazi::LOBPCG::constructor: user passed null output manager pointer.");
663 TEUCHOS_TEST_FOR_EXCEPTION(tester_ == Teuchos::null,std::invalid_argument,
664 "Anasazi::LOBPCG::constructor: user passed null status test pointer.");
665 TEUCHOS_TEST_FOR_EXCEPTION(orthman_ == Teuchos::null,std::invalid_argument,
666 "Anasazi::LOBPCG::constructor: user passed null orthogonalization manager pointer.");
667 TEUCHOS_TEST_FOR_EXCEPTION(problem_->isProblemSet() ==
false, std::invalid_argument,
668 "Anasazi::LOBPCG::constructor: problem is not set.");
669 TEUCHOS_TEST_FOR_EXCEPTION(problem_->isHermitian() ==
false, std::invalid_argument,
670 "Anasazi::LOBPCG::constructor: problem is not Hermitian; LOBPCG requires Hermitian problem.");
673 Op_ = problem_->getOperator();
674 TEUCHOS_TEST_FOR_EXCEPTION(Op_ == Teuchos::null, std::invalid_argument,
675 "Anasazi::LOBPCG::constructor: problem provides no operator.");
676 MOp_ = problem_->getM();
677 Prec_ = problem_->getPrec();
678 hasM_ = (MOp_ != Teuchos::null);
681 int bs = params.get(
"Block Size", problem_->getNEV());
688 template <
class ScalarType,
class MV,
class OP>
692 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
693 Teuchos::TimeMonitor lcltimer( *timerInit_ );
700 Teuchos::RCP<const MV> tmp;
706 if (blockSize_ > 0) {
710 tmp = problem_->getInitVec();
711 TEUCHOS_TEST_FOR_EXCEPTION(tmp == Teuchos::null,std::logic_error,
712 "Anasazi::LOBPCG::setBlockSize(): eigenproblem did not specify initial vectors to clone from.");
715 TEUCHOS_TEST_FOR_EXCEPTION(newBS <= 0 || static_cast<ptrdiff_t>(newBS) > MVText::GetGlobalLength(*tmp),
716 std::invalid_argument,
"Anasazi::LOBPCG::setBlockSize(): block size must be strictly positive.");
717 if (newBS == blockSize_) {
721 else if (newBS < blockSize_ && initialized_) {
737 std::vector<int> newind(newBS), oldind(newBS);
738 for (
int i=0; i<newBS; i++) {
743 Teuchos::RCP<MV> newV, newMV, newKV, newR;
744 Teuchos::RCP<const MV> src;
746 newR = MVT::Clone(*tmp,newBS);
747 newV = MVT::Clone(*tmp,newBS*3);
748 newKV = MVT::Clone(*tmp,newBS*3);
750 newMV = MVT::Clone(*tmp,newBS*3);
770 theta_.resize(3*newBS);
771 Rnorms_.resize(newBS);
772 R2norms_.resize(newBS);
775 src = MVT::CloneView(*R_,newind);
776 MVT::SetBlock(*src,newind,*newR);
782 src = MVT::CloneView(*V_,oldind);
783 MVT::SetBlock(*src,newind,*newV);
784 src = MVT::CloneView(*KV_,oldind);
785 MVT::SetBlock(*src,newind,*newKV);
787 src = MVT::CloneView(*MV_,oldind);
788 MVT::SetBlock(*src,newind,*newMV);
791 for (
int i=0; i<newBS; i++) {
792 newind[i] += 2*newBS;
793 oldind[i] += 2*blockSize_;
795 src = MVT::CloneView(*V_,oldind);
796 MVT::SetBlock(*src,newind,*newV);
797 src = MVT::CloneView(*KV_,oldind);
798 MVT::SetBlock(*src,newind,*newKV);
800 src = MVT::CloneView(*MV_,oldind);
801 MVT::SetBlock(*src,newind,*newMV);
820 initialized_ =
false;
839 theta_.resize(3*newBS,NANVAL);
840 Rnorms_.resize(newBS,NANVAL);
841 R2norms_.resize(newBS,NANVAL);
844 R_ = MVT::Clone(*tmp,newBS);
845 V_ = MVT::Clone(*tmp,newBS*3);
846 KV_ = MVT::Clone(*tmp,newBS*3);
848 MV_ = MVT::Clone(*tmp,newBS*3);
856 tmpmvec_ = Teuchos::null;
858 tmpmvec_ = MVT::Clone(*tmp,newBS);
871 template <
class ScalarType,
class MV,
class OP>
874 std::vector<int> ind(blockSize_);
876 for (
int i=0; i<blockSize_; i++) {
879 X_ = MVT::CloneViewNonConst(*V_,ind);
880 KX_ = MVT::CloneViewNonConst(*KV_,ind);
882 MX_ = MVT::CloneViewNonConst(*MV_,ind);
888 for (
int i=0; i<blockSize_; i++) {
889 ind[i] += blockSize_;
891 H_ = MVT::CloneViewNonConst(*V_,ind);
892 KH_ = MVT::CloneViewNonConst(*KV_,ind);
894 MH_ = MVT::CloneViewNonConst(*MV_,ind);
900 for (
int i=0; i<blockSize_; i++) {
901 ind[i] += blockSize_;
903 P_ = MVT::CloneViewNonConst(*V_,ind);
904 KP_ = MVT::CloneViewNonConst(*KV_,ind);
906 MP_ = MVT::CloneViewNonConst(*MV_,ind);
916 template <
class ScalarType,
class MV,
class OP>
918 typedef typename Teuchos::Array<Teuchos::RCP<const MV> >::iterator tarcpmv;
924 for (tarcpmv i=auxVecs_.begin(); i != auxVecs_.end(); i++) {
925 numAuxVecs_ += MVT::GetNumberVecs(**i);
929 if (numAuxVecs_ > 0 && initialized_) {
930 initialized_ =
false;
934 if (om_->isVerbosity(
Debug ) ) {
938 om_->print(
Debug, accuracyCheck(chk,
": in setAuxVecs()") );
961 template <
class ScalarType,
class MV,
class OP>
967 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
968 Teuchos::TimeMonitor inittimer( *timerInit_ );
971 std::vector<int> bsind(blockSize_);
972 for (
int i=0; i<blockSize_; i++) bsind[i] = i;
996 if (newstate.
X != Teuchos::null) {
997 TEUCHOS_TEST_FOR_EXCEPTION( MVText::GetGlobalLength(*newstate.
X) != MVText::GetGlobalLength(*X_),
998 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.X not correct." );
1000 TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*newstate.
X) < blockSize_,
1001 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.X must have at least block size vectors.");
1004 MVT::SetBlock(*newstate.
X,bsind,*X_);
1008 if (newstate.
MX != Teuchos::null) {
1009 TEUCHOS_TEST_FOR_EXCEPTION( MVText::GetGlobalLength(*newstate.
MX) != MVText::GetGlobalLength(*MX_),
1010 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.MX not correct." );
1012 TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*newstate.
MX) < blockSize_,
1013 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.MX must have at least block size vectors.");
1014 MVT::SetBlock(*newstate.
MX,bsind,*MX_);
1019 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1020 Teuchos::TimeMonitor lcltimer( *timerMOp_ );
1022 OPT::Apply(*MOp_,*X_,*MX_);
1023 count_ApplyM_ += blockSize_;
1026 newstate.
R = Teuchos::null;
1031 if (newstate.
KX != Teuchos::null) {
1032 TEUCHOS_TEST_FOR_EXCEPTION( MVText::GetGlobalLength(*newstate.
KX) != MVText::GetGlobalLength(*KX_),
1033 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.KX not correct." );
1035 TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*newstate.
KX) < blockSize_,
1036 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.KX must have at least block size vectors.");
1037 MVT::SetBlock(*newstate.
KX,bsind,*KX_);
1042 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1043 Teuchos::TimeMonitor lcltimer( *timerOp_ );
1045 OPT::Apply(*Op_,*X_,*KX_);
1046 count_ApplyOp_ += blockSize_;
1049 newstate.
R = Teuchos::null;
1057 newstate.
P = Teuchos::null;
1058 newstate.
KP = Teuchos::null;
1059 newstate.
MP = Teuchos::null;
1060 newstate.
R = Teuchos::null;
1061 newstate.
T = Teuchos::null;
1064 Teuchos::RCP<const MV> ivec = problem_->getInitVec();
1065 TEUCHOS_TEST_FOR_EXCEPTION(ivec == Teuchos::null,std::logic_error,
1066 "Anasazi::LOBPCG::initialize(): Eigenproblem did not specify initial vectors to clone from.");
1068 int initSize = MVT::GetNumberVecs(*ivec);
1069 if (initSize > blockSize_) {
1071 initSize = blockSize_;
1072 std::vector<int> ind(blockSize_);
1073 for (
int i=0; i<blockSize_; i++) ind[i] = i;
1074 ivec = MVT::CloneView(*ivec,ind);
1079 std::vector<int> ind(initSize);
1080 for (
int i=0; i<initSize; i++) ind[i] = i;
1081 MVT::SetBlock(*ivec,ind,*X_);
1084 if (blockSize_ > initSize) {
1085 std::vector<int> ind(blockSize_ - initSize);
1086 for (
int i=0; i<blockSize_ - initSize; i++) ind[i] = initSize + i;
1087 Teuchos::RCP<MV> rX = MVT::CloneViewNonConst(*X_,ind);
1094 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1095 Teuchos::TimeMonitor lcltimer( *timerMOp_ );
1097 OPT::Apply(*MOp_,*X_,*MX_);
1098 count_ApplyM_ += blockSize_;
1102 if (numAuxVecs_ > 0) {
1103 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1104 Teuchos::TimeMonitor lcltimer( *timerOrtho_ );
1106 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > dummy;
1107 int rank = orthman_->projectAndNormalizeMat(*X_,auxVecs_,dummy,Teuchos::null,MX_);
1109 "Anasazi::LOBPCG::initialize(): Couldn't generate initial basis of full rank.");
1112 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1113 Teuchos::TimeMonitor lcltimer( *timerOrtho_ );
1115 int rank = orthman_->normalizeMat(*X_,Teuchos::null,MX_);
1117 "Anasazi::LOBPCG::initialize(): Couldn't generate initial basis of full rank.");
1122 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1123 Teuchos::TimeMonitor lcltimer( *timerOp_ );
1125 OPT::Apply(*Op_,*X_,*KX_);
1126 count_ApplyOp_ += blockSize_;
1134 theta_.resize(3*blockSize_,NANVAL);
1135 if (newstate.
T != Teuchos::null) {
1136 TEUCHOS_TEST_FOR_EXCEPTION( (
signed int)(newstate.
T->size()) < blockSize_,
1137 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.T must contain at least block size Ritz values.");
1138 for (
int i=0; i<blockSize_; i++) {
1139 theta_[i] = (*newstate.
T)[i];
1141 nevLocal_ = blockSize_;
1145 Teuchos::SerialDenseMatrix<int,ScalarType> KK(blockSize_,blockSize_),
1146 MM(blockSize_,blockSize_),
1147 S(blockSize_,blockSize_);
1149 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1150 Teuchos::TimeMonitor lcltimer( *timerLocalProj_ );
1153 MVT::MvTransMv(ONE,*X_,*KX_,KK);
1155 MVT::MvTransMv(ONE,*X_,*MX_,MM);
1156 nevLocal_ = blockSize_;
1161 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1162 Teuchos::TimeMonitor lcltimer( *timerDS_ );
1164 Utils::directSolver(blockSize_, KK, Teuchos::rcpFromRef(MM), S, theta_, nevLocal_, 1);
1166 "Anasazi::LOBPCG::initialize(): Initial Ritz analysis did not produce enough Ritz pairs to initialize algorithm.");
1172 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1173 Teuchos::TimeMonitor lcltimer( *timerSort_ );
1176 std::vector<int> order(blockSize_);
1179 sm_->sort(theta_, Teuchos::rcpFromRef(order), blockSize_);
1182 Utils::permuteVectors(order,S);
1187 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1188 Teuchos::TimeMonitor lcltimer( *timerLocalUpdate_ );
1191 MVT::MvAddMv( ONE, *X_, ZERO, *X_, *R_ );
1192 MVT::MvTimesMatAddMv( ONE, *R_, S, ZERO, *X_ );
1194 MVT::MvAddMv( ONE, *KX_, ZERO, *KX_, *R_ );
1195 MVT::MvTimesMatAddMv( ONE, *R_, S, ZERO, *KX_ );
1198 MVT::MvAddMv( ONE, *MX_, ZERO, *MX_, *R_ );
1199 MVT::MvTimesMatAddMv( ONE, *R_, S, ZERO, *MX_ );
1207 if (newstate.
R != Teuchos::null) {
1208 TEUCHOS_TEST_FOR_EXCEPTION( MVText::GetGlobalLength(*newstate.
R) != MVText::GetGlobalLength(*R_),
1209 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.R not correct." );
1210 TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*newstate.
R) < blockSize_,
1211 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.R must have blockSize number of vectors." );
1212 MVT::SetBlock(*newstate.
R,bsind,*R_);
1215 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1216 Teuchos::TimeMonitor lcltimer( *timerCompRes_ );
1219 MVT::MvAddMv(ZERO,*KX_,ONE,*KX_,*R_);
1220 Teuchos::SerialDenseMatrix<int,ScalarType> T(blockSize_,blockSize_);
1221 for (
int i=0; i<blockSize_; i++) T(i,i) = theta_[i];
1222 MVT::MvTimesMatAddMv(-ONE,*MX_,T,ONE,*R_);
1226 Rnorms_current_ =
false;
1227 R2norms_current_ =
false;
1230 if (newstate.
P != Teuchos::null) {
1231 TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*newstate.
P) < blockSize_ ,
1232 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.P must have blockSize number of vectors." );
1233 TEUCHOS_TEST_FOR_EXCEPTION( MVText::GetGlobalLength(*newstate.
P) != MVText::GetGlobalLength(*P_),
1234 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.P not correct." );
1238 MVT::SetBlock(*newstate.
P,bsind,*P_);
1241 if (newstate.
KP != Teuchos::null) {
1242 TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*newstate.
KP) < blockSize_,
1243 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.KP must have blockSize number of vectors." );
1244 TEUCHOS_TEST_FOR_EXCEPTION( MVText::GetGlobalLength(*newstate.
KP) != MVText::GetGlobalLength(*KP_),
1245 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.KP not correct." );
1246 MVT::SetBlock(*newstate.
KP,bsind,*KP_);
1249 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1250 Teuchos::TimeMonitor lcltimer( *timerOp_ );
1252 OPT::Apply(*Op_,*P_,*KP_);
1253 count_ApplyOp_ += blockSize_;
1258 if (newstate.
MP != Teuchos::null) {
1259 TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*newstate.
MP) < blockSize_,
1260 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): newstate.MP must have blockSize number of vectors." );
1261 TEUCHOS_TEST_FOR_EXCEPTION( MVText::GetGlobalLength(*newstate.
MP) != MVText::GetGlobalLength(*MP_),
1262 std::invalid_argument,
"Anasazi::LOBPCG::initialize(newstate): vector length of newstate.MP not correct." );
1263 MVT::SetBlock(*newstate.
MP,bsind,*MP_);
1266 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1267 Teuchos::TimeMonitor lcltimer( *timerMOp_ );
1269 OPT::Apply(*MOp_,*P_,*MP_);
1270 count_ApplyM_ += blockSize_;
1279 initialized_ =
true;
1281 if (om_->isVerbosity(
Debug ) ) {
1292 om_->print(
Debug, accuracyCheck(chk,
": after initialize()") );
1297 template <
class ScalarType,
class MV,
class OP>
1307 template <
class ScalarType,
class MV,
class OP>
1310 if ( fullOrtho_ ==
true || initialized_ ==
false || fullOrtho == fullOrtho_ ) {
1312 fullOrtho_ = fullOrtho;
1324 if (fullOrtho_ && tmpmvec_ == Teuchos::null) {
1326 tmpmvec_ = MVT::Clone(*X_,blockSize_);
1328 else if (fullOrtho_==
false) {
1330 tmpmvec_ = Teuchos::null;
1337 template <
class ScalarType,
class MV,
class OP>
1343 if (initialized_ ==
false) {
1349 const int oneBlock = blockSize_;
1350 const int twoBlocks = 2*blockSize_;
1351 const int threeBlocks = 3*blockSize_;
1353 std::vector<int> indblock1(blockSize_), indblock2(blockSize_), indblock3(blockSize_);
1354 for (
int i=0; i<blockSize_; i++) {
1356 indblock2[i] = i + blockSize_;
1357 indblock3[i] = i + 2*blockSize_;
1365 Teuchos::SerialDenseMatrix<int,ScalarType> KK( threeBlocks, threeBlocks ),
1366 MM( threeBlocks, threeBlocks ),
1367 S( threeBlocks, threeBlocks );
1369 while (tester_->checkStatus(
this) !=
Passed) {
1372 if (om_->isVerbosity(
Debug)) {
1373 currentStatus( om_->stream(
Debug) );
1383 if (Prec_ != Teuchos::null) {
1384 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1385 Teuchos::TimeMonitor lcltimer( *timerPrec_ );
1387 OPT::Apply( *Prec_, *R_, *H_ );
1388 count_ApplyPrec_ += blockSize_;
1391 MVT::MvAddMv(ONE,*R_,ZERO,*R_,*H_);
1396 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1397 Teuchos::TimeMonitor lcltimer( *timerMOp_ );
1399 OPT::Apply( *MOp_, *H_, *MH_);
1400 count_ApplyM_ += blockSize_;
1405 Teuchos::Array<Teuchos::RCP<const MV> > Q;
1416 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1417 Teuchos::TimeMonitor lcltimer( *timerOrtho_ );
1419 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > dummyC =
1420 Teuchos::tuple<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > >(Teuchos::null);
1421 int rank = orthman_->projectAndNormalizeMat(*H_,Q,dummyC,Teuchos::null,MH_);
1424 "Anasazi::LOBPCG::iterate(): unable to compute orthonormal basis for H.");
1427 if (om_->isVerbosity(
Debug ) ) {
1431 om_->print(
Debug, accuracyCheck(chk,
": after ortho H") );
1437 om_->print(
OrthoDetails, accuracyCheck(chk,
": after ortho H") );
1442 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1443 Teuchos::TimeMonitor lcltimer( *timerOp_ );
1445 OPT::Apply( *Op_, *H_, *KH_);
1446 count_ApplyOp_ += blockSize_;
1450 nevLocal_ = threeBlocks;
1453 nevLocal_ = twoBlocks;
1475 KX_ = Teuchos::null;
1476 MX_ = Teuchos::null;
1478 KH_ = Teuchos::null;
1479 MH_ = Teuchos::null;
1481 KP_ = Teuchos::null;
1482 MP_ = Teuchos::null;
1483 Teuchos::RCP<const MV> cX, cH, cXHP, cHP, cK_XHP, cK_HP, cM_XHP, cM_HP, cP, cK_P, cM_P;
1485 cX = MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(V_),indblock1);
1486 cH = MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(V_),indblock2);
1488 std::vector<int> indXHP(nevLocal_);
1489 for (
int i=0; i<nevLocal_; i++) {
1492 cXHP = MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(V_),indXHP);
1493 cK_XHP = MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(KV_),indXHP);
1495 cM_XHP = MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(MV_),indXHP);
1501 std::vector<int> indHP(nevLocal_-blockSize_);
1502 for (
int i=blockSize_; i<nevLocal_; i++) {
1503 indHP[i-blockSize_] = i;
1505 cHP = MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(V_),indHP);
1506 cK_HP = MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(KV_),indHP);
1508 cM_HP = MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(MV_),indHP);
1514 if (nevLocal_ == threeBlocks) {
1515 cP = MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(V_),indblock3);
1516 cK_P = MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(KV_),indblock3);
1518 cM_P = MVT::CloneView(*Teuchos::rcp_implicit_cast<const MV>(MV_),indblock3);
1540 Teuchos::SerialDenseMatrix<int,ScalarType>
1541 K1(Teuchos::View,KK,blockSize_,nevLocal_ ,0*blockSize_,0*blockSize_),
1542 K2(Teuchos::View,KK,blockSize_,nevLocal_-1*blockSize_,1*blockSize_,1*blockSize_),
1543 K3(Teuchos::View,KK,blockSize_,nevLocal_-2*blockSize_,2*blockSize_,2*blockSize_),
1544 M1(Teuchos::View,MM,blockSize_,nevLocal_ ,0*blockSize_,0*blockSize_),
1545 M2(Teuchos::View,MM,blockSize_,nevLocal_-1*blockSize_,1*blockSize_,1*blockSize_),
1546 M3(Teuchos::View,MM,blockSize_,nevLocal_-2*blockSize_,2*blockSize_,2*blockSize_);
1548 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1549 Teuchos::TimeMonitor lcltimer( *timerLocalProj_ );
1551 MVT::MvTransMv( ONE, *cX, *cK_XHP, K1 );
1552 MVT::MvTransMv( ONE, *cX, *cM_XHP, M1 );
1553 MVT::MvTransMv( ONE, *cH, *cK_HP , K2 );
1554 MVT::MvTransMv( ONE, *cH, *cM_HP , M2 );
1555 if (nevLocal_ == threeBlocks) {
1556 MVT::MvTransMv( ONE, *cP, *cK_P, K3 );
1557 MVT::MvTransMv( ONE, *cP, *cM_P, M3 );
1567 cK_P = Teuchos::null;
1568 cM_P = Teuchos::null;
1569 if (fullOrtho_ ==
true) {
1570 cHP = Teuchos::null;
1571 cK_HP = Teuchos::null;
1572 cM_HP = Teuchos::null;
1581 Teuchos::SerialDenseMatrix<int,ScalarType> lclKK(Teuchos::View,KK,nevLocal_,nevLocal_),
1582 lclMM(Teuchos::View,MM,nevLocal_,nevLocal_),
1583 lclS(Teuchos::View, S,nevLocal_,nevLocal_);
1585 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1586 Teuchos::TimeMonitor lcltimer( *timerDS_ );
1588 int localSize = nevLocal_;
1589 Utils::directSolver(localSize, lclKK, Teuchos::rcpFromRef(lclMM), lclS, theta_, nevLocal_, 0);
1598 if (nevLocal_ != localSize) {
1601 cXHP = Teuchos::null;
1602 cK_XHP = Teuchos::null;
1603 cM_XHP = Teuchos::null;
1604 cHP = Teuchos::null;
1605 cK_HP = Teuchos::null;
1606 cM_HP = Teuchos::null;
1610 "Anasazi::LOBPCG::iterate(): indefiniteness detected in projected mass matrix." );
1617 Teuchos::LAPACK<int,ScalarType> lapack;
1618 Teuchos::BLAS<int,ScalarType> blas;
1620 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1621 Teuchos::TimeMonitor lcltimer( *timerSort_ );
1624 std::vector<int> order(nevLocal_);
1627 sm_->sort(theta_, Teuchos::rcpFromRef(order), nevLocal_);
1630 Utils::permuteVectors(order,lclS);
1642 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > CX, CP;
1653 Teuchos::SerialDenseMatrix<int,ScalarType> C(nevLocal_,twoBlocks),
1654 MMC(nevLocal_,twoBlocks),
1655 CMMC(twoBlocks ,twoBlocks);
1658 for (
int j=0; j<oneBlock; j++) {
1659 for (
int i=0; i<oneBlock; i++) {
1663 C(i,j+oneBlock) = ZERO;
1667 for (
int j=0; j<oneBlock; j++) {
1668 for (
int i=oneBlock; i<twoBlocks; i++) {
1672 C(i,j+oneBlock) = lclS(i,j);
1676 if (nevLocal_ == threeBlocks) {
1677 for (
int j=0; j<oneBlock; j++) {
1678 for (
int i=twoBlocks; i<threeBlocks; i++) {
1682 C(i,j+oneBlock) = lclS(i,j);
1690 teuchosret = MMC.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,ONE,lclMM,C,ZERO);
1691 TEUCHOS_TEST_FOR_EXCEPTION(teuchosret != 0,std::logic_error,
1692 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1694 teuchosret = CMMC.multiply(Teuchos::CONJ_TRANS,Teuchos::NO_TRANS,ONE,C,MMC,ZERO);
1695 TEUCHOS_TEST_FOR_EXCEPTION(teuchosret != 0,std::logic_error,
1696 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1702 lapack.POTRF(
'U',twoBlocks,CMMC.values(),CMMC.stride(),&info);
1706 Teuchos::SerialDenseMatrix<int,ScalarType> K22(Teuchos::View,KK,blockSize_,blockSize_,1*blockSize_,1*blockSize_);
1707 Teuchos::SerialDenseMatrix<int,ScalarType> K22_trans( K22, Teuchos::CONJ_TRANS );
1709 MagnitudeType symNorm = K22_trans.normOne();
1710 MagnitudeType tol = SCT::magnitude(SCT::squareroot(SCT::eps()));
1712 cXHP = Teuchos::null;
1713 cHP = Teuchos::null;
1714 cK_XHP = Teuchos::null;
1715 cK_HP = Teuchos::null;
1716 cM_XHP = Teuchos::null;
1717 cM_HP = Teuchos::null;
1720 std::string errMsg =
"Anasazi::LOBPCG::iterate(): Cholesky factorization failed during full orthogonalization.";
1721 if ( symNorm < tol )
1727 errMsg +=
" Check the operator A (or K), it may not be Hermitian!";
1733 blas.TRSM(Teuchos::RIGHT_SIDE,Teuchos::UPPER_TRI,Teuchos::NO_TRANS,Teuchos::NON_UNIT_DIAG,
1734 nevLocal_,twoBlocks,ONE,CMMC.values(),CMMC.stride(),C.values(),C.stride());
1736 CX = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(Teuchos::Copy,C,nevLocal_,oneBlock,0,0) );
1738 CP = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(Teuchos::Copy,C,nevLocal_,oneBlock,0,oneBlock) );
1741 if (om_->isVerbosity(
Debug ) ) {
1742 Teuchos::SerialDenseMatrix<int,ScalarType> tmp1(nevLocal_,oneBlock),
1743 tmp2(oneBlock,oneBlock);
1746 std::stringstream os;
1748 os.setf(std::ios::scientific, std::ios::floatfield);
1750 os <<
" Checking Full Ortho: iteration " << iter_ << std::endl;
1754 teuchosret = tmp1.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,ONE,lclMM,*CX,ZERO);
1755 TEUCHOS_TEST_FOR_EXCEPTION(teuchosret != 0,std::logic_error,
1756 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1758 teuchosret = tmp2.multiply(Teuchos::CONJ_TRANS,Teuchos::NO_TRANS,ONE,*CX,tmp1,ZERO);
1759 TEUCHOS_TEST_FOR_EXCEPTION(teuchosret != 0,std::logic_error,
1760 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1762 for (
int i=0; i<oneBlock; i++) tmp2(i,i) -= ONE;
1763 tmp = tmp2.normFrobenius();
1764 os <<
" >> Error in CX^H MM CX == I : " << tmp << std::endl;
1768 teuchosret = tmp1.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,ONE,lclMM,*CP,ZERO);
1769 TEUCHOS_TEST_FOR_EXCEPTION(teuchosret != 0,std::logic_error,
1770 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1772 teuchosret = tmp2.multiply(Teuchos::CONJ_TRANS,Teuchos::NO_TRANS,ONE,*CP,tmp1,ZERO);
1773 TEUCHOS_TEST_FOR_EXCEPTION(teuchosret != 0,std::logic_error,
1774 "Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1776 for (
int i=0; i<oneBlock; i++) tmp2(i,i) -= ONE;
1777 tmp = tmp2.normFrobenius();
1778 os <<
" >> Error in CP^H MM CP == I : " << tmp << std::endl;
1782 teuchosret = tmp1.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,ONE,lclMM,*CP,ZERO);
1783 TEUCHOS_TEST_FOR_EXCEPTION(teuchosret != 0,std::logic_error,
"Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1785 teuchosret = tmp2.multiply(Teuchos::CONJ_TRANS,Teuchos::NO_TRANS,ONE,*CX,tmp1,ZERO);
1786 TEUCHOS_TEST_FOR_EXCEPTION(teuchosret != 0,std::logic_error,
"Anasazi::LOBPCG::iterate(): Logic error calling SerialDenseMatrix::multiply");
1788 tmp = tmp2.normFrobenius();
1789 os <<
" >> Error in CX^H MM CP == 0 : " << tmp << std::endl;
1792 om_->print(
Debug,os.str());
1807 CX = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(Teuchos::Copy,lclS,nevLocal_ ,oneBlock,0 ,0) );
1808 CP = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(Teuchos::Copy,lclS,nevLocal_-oneBlock,oneBlock,oneBlock,0) );
1817 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1818 Teuchos::TimeMonitor lcltimer( *timerLocalUpdate_ );
1846 MVT::MvTimesMatAddMv(ONE,*cXHP,*CX,ZERO,*tmpmvec_);
1847 MVT::MvTimesMatAddMv(ONE,*cXHP,*CP,ZERO,*R_);
1848 cXHP = Teuchos::null;
1849 MVT::SetBlock(*tmpmvec_,indblock1,*V_);
1850 MVT::SetBlock(*R_ ,indblock3,*V_);
1852 MVT::MvTimesMatAddMv(ONE,*cK_XHP,*CX,ZERO,*tmpmvec_);
1853 MVT::MvTimesMatAddMv(ONE,*cK_XHP,*CP,ZERO,*R_);
1854 cK_XHP = Teuchos::null;
1855 MVT::SetBlock(*tmpmvec_,indblock1,*KV_);
1856 MVT::SetBlock(*R_ ,indblock3,*KV_);
1859 MVT::MvTimesMatAddMv(ONE,*cM_XHP,*CX,ZERO,*tmpmvec_);
1860 MVT::MvTimesMatAddMv(ONE,*cM_XHP,*CP,ZERO,*R_);
1861 cM_XHP = Teuchos::null;
1862 MVT::SetBlock(*tmpmvec_,indblock1,*MV_);
1863 MVT::SetBlock(*R_ ,indblock3,*MV_);
1866 cM_XHP = Teuchos::null;
1871 MVT::MvTimesMatAddMv(ONE,*cXHP,*CX,ZERO,*R_);
1872 cXHP = Teuchos::null;
1873 MVT::SetBlock(*R_,indblock1,*V_);
1874 MVT::MvTimesMatAddMv(ONE,*cHP,*CP,ZERO,*R_);
1875 cHP = Teuchos::null;
1876 MVT::SetBlock(*R_,indblock3,*V_);
1878 MVT::MvTimesMatAddMv(ONE,*cK_XHP,*CX,ZERO,*R_);
1879 cK_XHP = Teuchos::null;
1880 MVT::SetBlock(*R_,indblock1,*KV_);
1881 MVT::MvTimesMatAddMv(ONE,*cK_HP,*CP,ZERO,*R_);
1882 cK_HP = Teuchos::null;
1883 MVT::SetBlock(*R_,indblock3,*KV_);
1886 MVT::MvTimesMatAddMv(ONE,*cM_XHP,*CX,ZERO,*R_);
1887 cM_XHP = Teuchos::null;
1888 MVT::SetBlock(*R_,indblock1,*MV_);
1889 MVT::MvTimesMatAddMv(ONE,*cM_HP,*CP,ZERO,*R_);
1890 cM_HP = Teuchos::null;
1891 MVT::SetBlock(*R_,indblock3,*MV_);
1894 cM_XHP = Teuchos::null;
1895 cM_HP = Teuchos::null;
1909 TEUCHOS_TEST_FOR_EXCEPTION( cXHP != Teuchos::null || cK_XHP != Teuchos::null || cM_XHP != Teuchos::null
1910 || cHP != Teuchos::null || cK_HP != Teuchos::null || cM_HP != Teuchos::null
1911 || cP != Teuchos::null || cK_P != Teuchos::null || cM_P != Teuchos::null,
1913 "Anasazi::BlockKrylovSchur::iterate(): const views were not all cleared! Something went wrong!" );
1922 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1923 Teuchos::TimeMonitor lcltimer( *timerCompRes_ );
1925 MVT::MvAddMv( ONE, *KX_, ZERO, *KX_, *R_ );
1926 Teuchos::SerialDenseMatrix<int,ScalarType> T( blockSize_, blockSize_ );
1927 for (
int i = 0; i < blockSize_; i++) {
1930 MVT::MvTimesMatAddMv( -ONE, *MX_, T, ONE, *R_ );
1934 Rnorms_current_ =
false;
1935 R2norms_current_ =
false;
1938 if (om_->isVerbosity(
Debug ) ) {
1948 om_->print(
Debug, accuracyCheck(chk,
": after local update") );
1955 om_->print(
OrthoDetails, accuracyCheck(chk,
": after local update") );
1963 template <
class ScalarType,
class MV,
class OP>
1964 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
1966 if (Rnorms_current_ ==
false) {
1968 orthman_->norm(*R_,Rnorms_);
1969 Rnorms_current_ =
true;
1977 template <
class ScalarType,
class MV,
class OP>
1978 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
1980 if (R2norms_current_ ==
false) {
1982 MVT::MvNorm(*R_,R2norms_);
1983 R2norms_current_ =
true;
2018 template <
class ScalarType,
class MV,
class OP>
2023 std::stringstream os;
2025 os.setf(std::ios::scientific, std::ios::floatfield);
2028 os <<
" Debugging checks: iteration " << iter_ << where << endl;
2031 if (chk.checkX && initialized_) {
2032 tmp = orthman_->orthonormError(*X_);
2033 os <<
" >> Error in X^H M X == I : " << tmp << endl;
2034 for (Array_size_type i=0; i<auxVecs_.size(); i++) {
2035 tmp = orthman_->orthogError(*X_,*auxVecs_[i]);
2036 os <<
" >> Error in X^H M Q[" << i <<
"] == 0 : " << tmp << endl;
2039 if (chk.checkMX && hasM_ && initialized_) {
2040 tmp = Utils::errorEquality(*X_, *MX_, MOp_);
2041 os <<
" >> Error in MX == M*X : " << tmp << endl;
2043 if (chk.checkKX && initialized_) {
2044 tmp = Utils::errorEquality(*X_, *KX_, Op_);
2045 os <<
" >> Error in KX == K*X : " << tmp << endl;
2049 if (chk.checkP && hasP_ && initialized_) {
2051 tmp = orthman_->orthonormError(*P_);
2052 os <<
" >> Error in P^H M P == I : " << tmp << endl;
2053 tmp = orthman_->orthogError(*P_,*X_);
2054 os <<
" >> Error in P^H M X == 0 : " << tmp << endl;
2056 for (Array_size_type i=0; i<auxVecs_.size(); i++) {
2057 tmp = orthman_->orthogError(*P_,*auxVecs_[i]);
2058 os <<
" >> Error in P^H M Q[" << i <<
"] == 0 : " << tmp << endl;
2061 if (chk.checkMP && hasM_ && hasP_ && initialized_) {
2062 tmp = Utils::errorEquality(*P_, *MP_, MOp_);
2063 os <<
" >> Error in MP == M*P : " << tmp << endl;
2065 if (chk.checkKP && hasP_ && initialized_) {
2066 tmp = Utils::errorEquality(*P_, *KP_, Op_);
2067 os <<
" >> Error in KP == K*P : " << tmp << endl;
2071 if (chk.checkH && initialized_) {
2073 tmp = orthman_->orthonormError(*H_);
2074 os <<
" >> Error in H^H M H == I : " << tmp << endl;
2075 tmp = orthman_->orthogError(*H_,*X_);
2076 os <<
" >> Error in H^H M X == 0 : " << tmp << endl;
2078 tmp = orthman_->orthogError(*H_,*P_);
2079 os <<
" >> Error in H^H M P == 0 : " << tmp << endl;
2082 for (Array_size_type i=0; i<auxVecs_.size(); i++) {
2083 tmp = orthman_->orthogError(*H_,*auxVecs_[i]);
2084 os <<
" >> Error in H^H M Q[" << i <<
"] == 0 : " << tmp << endl;
2087 if (chk.checkMH && hasM_ && initialized_) {
2088 tmp = Utils::errorEquality(*H_, *MH_, MOp_);
2089 os <<
" >> Error in MH == M*H : " << tmp << endl;
2093 if (chk.checkR && initialized_) {
2094 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(blockSize_,blockSize_);
2095 MVT::MvTransMv(ONE,*X_,*R_,xTx);
2096 tmp = xTx.normFrobenius();
2097 MVT::MvTransMv(ONE,*R_,*R_,xTx);
2098 double normR = xTx.normFrobenius();
2099 os <<
" >> RelError in X^H R == 0: " << tmp/normR << endl;
2104 for (Array_size_type i=0; i<auxVecs_.size(); i++) {
2105 tmp = orthman_->orthonormError(*auxVecs_[i]);
2106 os <<
" >> Error in Q[" << i <<
"]^H M Q[" << i <<
"] == I : " << tmp << endl;
2107 for (Array_size_type j=i+1; j<auxVecs_.size(); j++) {
2108 tmp = orthman_->orthogError(*auxVecs_[i],*auxVecs_[j]);
2109 os <<
" >> Error in Q[" << i <<
"]^H M Q[" << j <<
"] == 0 : " << tmp << endl;
2122 template <
class ScalarType,
class MV,
class OP>
2128 os.setf(std::ios::scientific, std::ios::floatfield);
2131 os <<
"================================================================================" << endl;
2133 os <<
" LOBPCG Solver Status" << endl;
2135 os <<
"The solver is "<<(initialized_ ?
"initialized." :
"not initialized.") << endl;
2136 os <<
"The number of iterations performed is " << iter_ << endl;
2137 os <<
"The current block size is " << blockSize_ << endl;
2138 os <<
"The number of auxiliary vectors is " << numAuxVecs_ << endl;
2139 os <<
"The number of operations Op*x is " << count_ApplyOp_ << endl;
2140 os <<
"The number of operations M*x is " << count_ApplyM_ << endl;
2141 os <<
"The number of operations Prec*x is " << count_ApplyPrec_ << endl;
2143 os.setf(std::ios_base::right, std::ios_base::adjustfield);
2147 os <<
"CURRENT EIGENVALUE ESTIMATES "<<endl;
2148 os << std::setw(20) <<
"Eigenvalue"
2149 << std::setw(20) <<
"Residual(M)"
2150 << std::setw(20) <<
"Residual(2)"
2152 os <<
"--------------------------------------------------------------------------------"<<endl;
2153 for (
int i=0; i<blockSize_; i++) {
2154 os << std::setw(20) << theta_[i];
2155 if (Rnorms_current_) os << std::setw(20) << Rnorms_[i];
2156 else os << std::setw(20) <<
"not current";
2157 if (R2norms_current_) os << std::setw(20) << R2norms_[i];
2158 else os << std::setw(20) <<
"not current";
2162 os <<
"================================================================================" << endl;
2168 template <
class ScalarType,
class MV,
class OP>
2170 return initialized_;
2176 template <
class ScalarType,
class MV,
class OP>
2183 template <
class ScalarType,
class MV,
class OP>
2191 template <
class ScalarType,
class MV,
class OP>
2198 template <
class ScalarType,
class MV,
class OP>
2205 template <
class ScalarType,
class MV,
class OP>
2213 template <
class ScalarType,
class MV,
class OP>
2215 return 3*blockSize_;
2220 template <
class ScalarType,
class MV,
class OP>
2222 if (!initialized_)
return 0;
2229 template <
class ScalarType,
class MV,
class OP>
2230 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
2233 return this->getRes2Norms();
2239 template <
class ScalarType,
class MV,
class OP>
2241 std::vector<int> ret(nevLocal_,0);
2248 template <
class ScalarType,
class MV,
class OP>
2250 std::vector<Value<ScalarType> > ret(nevLocal_);
2251 for (
int i=0; i<nevLocal_; i++) {
2252 ret[i].realpart = theta_[i];
2253 ret[i].imagpart = ZERO;
2260 template <
class ScalarType,
class MV,
class OP>
2262 TEUCHOS_TEST_FOR_EXCEPTION(test == Teuchos::null,std::invalid_argument,
2263 "Anasazi::LOBPCG::setStatusTest() was passed a null StatusTest.");
2269 template <
class ScalarType,
class MV,
class OP>
2276 template <
class ScalarType,
class MV,
class OP>
2284 template <
class ScalarType,
class MV,
class OP>
2292 template <
class ScalarType,
class MV,
class OP>
2300 template <
class ScalarType,
class MV,
class OP>
2312 state.
T = Teuchos::rcp(
new std::vector<MagnitudeType>(theta_));
2320 state.
MX = Teuchos::null;
2321 state.
MP = Teuchos::null;
2322 state.
MH = Teuchos::null;
2329 #endif // ANASAZI_LOBPCG_HPP
An extension of the MultiVecTraits class that adds a new vector length method.This traits class provi...
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
Teuchos::Array< Teuchos::RCP< const MV > > getAuxVecs() const
Get the current auxiliary vectors.
LOBPCG(const Teuchos::RCP< Eigenproblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< SortManager< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > > &sorter, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &tester, const Teuchos::RCP< MatOrthoManager< ScalarType, MV, OP > > &ortho, Teuchos::ParameterList ¶ms)
LOBPCG constructor with eigenproblem, solver utilities, and parameter list of solver options...
This class defines the interface required by an eigensolver and status test class to compute solution...
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this eigenproblem.
void setStatusTest(Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test)
Set a new StatusTest for the solver.
Declaration of basic traits for the multivector type.
This class provides the Locally Optimal Block Preconditioned Conjugate Gradient (LOBPCG) iteration...
Teuchos::RCP< const MultiVector > V
The current test basis.
virtual ~LOBPCG()
LOBPCG destructor
Virtual base class which defines basic traits for the operator type.
Teuchos::RCP< const MultiVector > H
The current preconditioned residual vectors.
Teuchos::RCP< const MultiVector > P
The current search direction.
An exception class parent to all Anasazi exceptions.
Teuchos::RCP< const MultiVector > MV
The image of the current test basis under M, or Teuchos::null if M was not specified.
Pure virtual base class which describes the basic interface to the iterative eigensolver.
Teuchos::RCP< const MultiVector > R
The current residual vectors.
void initialize()
Initialize the solver with the initial vectors from the eigenproblem or random data.
Teuchos::RCP< const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > > T
The current Ritz values.
bool isInitialized() const
Indicates whether the solver has been initialized or not.
Anasazi's templated, static class providing utilities for the solvers.
const Eigenproblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the eigenvalue problem.
Anasazi's templated virtual class for providing routines for orthogonalization and orthonormalization...
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver in solving this eigenproblem.
Output managers remove the need for the eigensolver to know any information about the required output...
Traits class which defines basic operations on multivectors.
int getNumIters() const
Get the current iteration count.
Virtual base class which defines basic traits for the operator type.
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getRes2Norms()
Get the current residual 2-norms.
Teuchos::RCP< const MultiVector > MX
The image of the current eigenvectors under M, or Teuchos::null if M was not specified.
Teuchos::RCP< const MultiVector > KX
The image of the current eigenvectors under K.
bool getFullOrtho() const
Determine if the LOBPCG iteration is using full orthogonality.
Teuchos::RCP< const MultiVector > KH
The image of the current preconditioned residual vectors under K.
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getResNorms()
Get the current residual norms.
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getRitzRes2Norms()
Get the 2-norms of the residuals.
std::vector< int > getRitzIndex()
Get the index used for extracting Ritz vectors from getRitzVectors().
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace. For LOBPCG, this always returns 3*getBlo...
Teuchos::RCP< const MultiVector > MH
The image of the current preconditioned residual vectors under M, or Teuchos::null if M was not speci...
Teuchos::RCP< const MultiVector > KP
The image of the current search direction under K.
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > getStatusTest() const
Get the current StatusTest used by the solver.
void currentStatus(std::ostream &os)
This method requests that the solver print out its current status to screen.
void iterate()
This method performs LOBPCG iterations until the status test indicates the need to stop or an error o...
LOBPCGRitzFailure is thrown when the LOBPCG solver is unable to continue a call to LOBPCG::iterate() ...
std::vector< Value< ScalarType > > getRitzValues()
Get the Ritz values from the previous iteration.
Teuchos::RCP< const MultiVector > KV
The image of the current test basis under K.
void setAuxVecs(const Teuchos::Array< Teuchos::RCP< const MV > > &auxvecs)
Set the auxiliary vectors for the solver.
Types and exceptions used within Anasazi solvers and interfaces.
void resetNumIters()
Reset the iteration count.
Teuchos::RCP< const MultiVector > MP
The image of the current search direction under M, or Teuchos::null if M was not specified.
Anasazi's templated pure virtual class for managing the sorting of approximate eigenvalues computed b...
A pure virtual class for defining the status tests for the Anasazi iterative solvers.
LOBPCGOrthoFailure is thrown when an orthogonalization attempt fails.
LOBPCGInitFailure is thrown when the LOBPCG solver is unable to generate an initial iterate in the LO...
LOBPCGState< ScalarType, MV > getState() const
Get the current state of the eigensolver.
The Eigensolver is a templated virtual base class that defines the basic interface that any eigensolv...
void setFullOrtho(bool fullOrtho)
Instruct the LOBPCG iteration to use full orthogonality.
Structure to contain pointers to Anasazi state variables.
Teuchos::RCP< const MultiVector > X
The current eigenvectors.
Teuchos::RCP< const MV > getRitzVectors()
Get the Ritz vectors from the previous iteration.
bool hasP()
Indicates whether the search direction given by getState() is valid.
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current eigenvectors and eigenvalues...
Class which provides internal utilities for the Anasazi solvers.