33 #ifndef ANASAZI_BLOCK_KRYLOV_SCHUR_HPP
34 #define ANASAZI_BLOCK_KRYLOV_SCHUR_HPP
42 #include "AnasaziHelperTraits.hpp"
75 template <
class ScalarType,
class MulVec>
95 H(Teuchos::null),
S(Teuchos::null),
133 template <
class ScalarType,
class MV,
class OP>
273 std::vector<Value<ScalarType> > ret = ritzValues_;
274 ret.resize(ritzIndex_.size());
289 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
getResNorms() {
290 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> ret(0);
298 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
getRes2Norms() {
299 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> ret(0);
307 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
getRitzRes2Norms() {
308 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> ret = ritzResiduals_;
309 ret.resize(ritzIndex_.size());
333 void setSize(
int blockSize,
int numBlocks);
359 if (!initialized_)
return 0;
364 int getMaxSubspaceDim()
const {
return (problem_->isHermitian()?blockSize_*numBlocks_:blockSize_*numBlocks_+1); }
431 typedef typename std::vector<ScalarType>::iterator STiter;
432 typedef typename std::vector<MagnitudeType>::iterator MTiter;
433 const MagnitudeType MT_ONE;
434 const MagnitudeType MT_ZERO;
435 const MagnitudeType NANVAL;
436 const ScalarType ST_ONE;
437 const ScalarType ST_ZERO;
445 CheckList() : checkV(false), checkArn(false), checkAux(false) {};
450 std::string accuracyCheck(
const CheckList &chk,
const std::string &where)
const;
453 std::vector<int>& order );
470 timerCompSF_, timerSortSF_,
471 timerCompRitzVec_, timerOrtho_;
527 bool ritzVecsCurrent_, ritzValsCurrent_, schurCurrent_;
530 std::vector<Value<ScalarType> > ritzValues_;
531 std::vector<MagnitudeType> ritzResiduals_;
534 std::vector<int> ritzIndex_;
535 std::vector<int> ritzOrder_;
544 template <
class ScalarType,
class MV,
class OP>
553 MT_ONE(Teuchos::ScalarTraits<MagnitudeType>::one()),
554 MT_ZERO(Teuchos::ScalarTraits<MagnitudeType>::zero()),
555 NANVAL(Teuchos::ScalarTraits<MagnitudeType>::nan()),
556 ST_ONE(Teuchos::ScalarTraits<ScalarType>::one()),
557 ST_ZERO(Teuchos::ScalarTraits<ScalarType>::zero()),
565 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
566 timerOp_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: BlockKrylovSchur::Operation Op*x")),
567 timerSortRitzVal_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: BlockKrylovSchur::Sorting Ritz values")),
568 timerCompSF_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: BlockKrylovSchur::Computing Schur form")),
569 timerSortSF_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: BlockKrylovSchur::Sorting Schur form")),
570 timerCompRitzVec_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: BlockKrylovSchur::Computing Ritz vectors")),
571 timerOrtho_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: BlockKrylovSchur::Orthogonalization")),
581 auxVecs_( Teuchos::Array<Teuchos::RCP<const MV> >(0) ),
584 ritzVecsCurrent_(false),
585 ritzValsCurrent_(false),
586 schurCurrent_(false),
590 "Anasazi::BlockKrylovSchur::constructor: user specified null problem pointer.");
592 "Anasazi::BlockKrylovSchur::constructor: user passed null sort manager pointer.");
594 "Anasazi::BlockKrylovSchur::constructor: user passed null output manager pointer.");
596 "Anasazi::BlockKrylovSchur::constructor: user passed null status test pointer.");
598 "Anasazi::BlockKrylovSchur::constructor: user passed null orthogonalization manager pointer.");
600 "Anasazi::BlockKrylovSchur::constructor: user specified problem is not set.");
602 "Anasazi::BlockKrylovSchur::constructor: user specified null sort manager pointer.");
603 TEUCHOS_TEST_FOR_EXCEPTION(printer == Teuchos::null,std::invalid_argument,
604 "Anasazi::BlockKrylovSchur::constructor: user specified null output manager pointer.");
605 TEUCHOS_TEST_FOR_EXCEPTION(tester == Teuchos::null,std::invalid_argument,
606 "Anasazi::BlockKrylovSchur::constructor: user specified null status test pointer.");
607 TEUCHOS_TEST_FOR_EXCEPTION(ortho == Teuchos::null,std::invalid_argument,
608 "Anasazi::BlockKrylovSchur::constructor: user specified null ortho manager pointer.");
611 Op_ = problem_->getOperator();
614 TEUCHOS_TEST_FOR_EXCEPTION(!params.
isParameter(
"Step Size"), std::invalid_argument,
615 "Anasazi::BlockKrylovSchur::constructor: mandatory parameter 'Step Size' is not specified.");
616 int ss = params.
get(
"Step Size",numBlocks_);
620 int bs = params.
get(
"Block Size", 1);
621 int nb = params.
get(
"Num Blocks", 3*problem_->getNEV());
626 int numRitzVecs = params.
get(
"Number of Ritz Vectors", 0);
630 numRitzPrint_ = params.
get(
"Print Number of Ritz Values", bs);
637 template <
class ScalarType,
class MV,
class OP>
640 setSize(blockSize,numBlocks_);
646 template <
class ScalarType,
class MV,
class OP>
649 TEUCHOS_TEST_FOR_EXCEPTION(stepSize <= 0, std::invalid_argument,
"Anasazi::BlockKrylovSchur::setStepSize(): new step size must be positive and non-zero.");
650 stepSize_ = stepSize;
655 template <
class ScalarType,
class MV,
class OP>
661 TEUCHOS_TEST_FOR_EXCEPTION(numRitzVecs < 0, std::invalid_argument,
"Anasazi::BlockKrylovSchur::setNumRitzVectors(): number of Ritz vectors to compute must be positive.");
664 if (numRitzVecs != numRitzVecs_) {
666 ritzVectors_ = Teuchos::null;
667 ritzVectors_ = MVT::Clone(*V_, numRitzVecs);
669 ritzVectors_ = Teuchos::null;
671 numRitzVecs_ = numRitzVecs;
672 ritzVecsCurrent_ =
false;
678 template <
class ScalarType,
class MV,
class OP>
684 TEUCHOS_TEST_FOR_EXCEPTION(numBlocks <= 0 || blockSize <= 0, std::invalid_argument,
"Anasazi::BlockKrylovSchur::setSize was passed a non-positive argument.");
685 TEUCHOS_TEST_FOR_EXCEPTION(numBlocks < 3, std::invalid_argument,
"Anasazi::BlockKrylovSchur::setSize(): numBlocks must be at least three.");
686 if (blockSize == blockSize_ && numBlocks == numBlocks_) {
691 blockSize_ = blockSize;
692 numBlocks_ = numBlocks;
700 if (problem_->getInitVec() != Teuchos::null) {
701 tmp = problem_->getInitVec();
706 "Anasazi::BlockKrylovSchur::setSize(): eigenproblem did not specify initial vectors to clone from.");
714 if (problem_->isHermitian()) {
715 newsd = blockSize_*numBlocks_;
717 newsd = blockSize_*numBlocks_+1;
721 "Anasazi::BlockKrylovSchur::setSize(): maximum basis size is larger than problem dimension.");
723 ritzValues_.resize(newsd);
724 ritzResiduals_.resize(newsd,MT_ONE);
725 ritzOrder_.resize(newsd);
727 V_ = MVT::Clone(*tmp,newsd+blockSize_);
731 initialized_ =
false;
738 template <
class ScalarType,
class MV,
class OP>
745 if (om_->isVerbosity(
Debug ) ) {
749 om_->print(
Debug, accuracyCheck(chk,
": in setAuxVecs()") );
753 for (tarcpmv i=auxVecs_.begin(); i != auxVecs_.end(); i++) {
754 numAuxVecs_ += MVT::GetNumberVecs(**i);
758 if (numAuxVecs_ > 0 && initialized_) {
759 initialized_ =
false;
772 template <
class ScalarType,
class MV,
class OP>
777 std::vector<int> bsind(blockSize_);
778 for (
int i=0; i<blockSize_; i++) bsind[i] = i;
786 std::string errstr(
"Anasazi::BlockKrylovSchur::initialize(): specified multivectors must have a consistent length and width.");
790 if (newstate.
V != Teuchos::null && newstate.
H != Teuchos::null) {
795 std::invalid_argument, errstr );
796 if (newstate.
V != V_) {
798 std::invalid_argument, errstr );
800 std::invalid_argument, errstr );
803 std::invalid_argument, errstr );
805 curDim_ = newstate.
curDim;
806 int lclDim = MVT::GetNumberVecs(*newstate.
V);
811 if (curDim_ == 0 && lclDim > blockSize_) {
812 om_->stream(
Warnings) <<
"Anasazi::BlockKrylovSchur::initialize(): the solver was initialized with a kernel of " << lclDim << std::endl
813 <<
"The block size however is only " << blockSize_ << std::endl
814 <<
"The last " << lclDim - blockSize_ <<
" vectors of the kernel will be overwritten on the first call to iterate()." << std::endl;
819 if (newstate.
V != V_) {
820 std::vector<int> nevind(lclDim);
821 for (
int i=0; i<lclDim; i++) nevind[i] = i;
822 MVT::SetBlock(*newstate.
V,nevind,*V_);
826 if (newstate.
H != H_) {
827 H_->putScalar( ST_ZERO );
834 lclH = Teuchos::null;
843 "Anasazi::BlockKrylovSchur::initialize(): eigenproblem did not specify initial vectors to clone from.");
845 int lclDim = MVT::GetNumberVecs(*ivec);
846 bool userand =
false;
847 if (lclDim < blockSize_) {
855 std::vector<int> dimind2(lclDim);
856 for (
int i=0; i<lclDim; i++) { dimind2[i] = i; }
862 MVT::SetBlock(*ivec,dimind2,*newV1);
865 dimind2.resize(blockSize_-lclDim);
866 for (
int i=0; i<blockSize_-lclDim; i++) { dimind2[i] = lclDim + i; }
870 MVT::MvRandom(*newV2);
880 MVT::SetBlock(*ivecV,bsind,*newV1);
887 if (auxVecs_.size() > 0) {
888 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
893 int rank = orthman_->projectAndNormalize(*newV,auxVecs_);
895 "Anasazi::BlockKrylovSchur::initialize(): couldn't generate initial basis of full rank." );
898 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
902 int rank = orthman_->normalize(*newV);
904 "Anasazi::BlockKrylovSchur::initialize(): couldn't generate initial basis of full rank." );
911 newV = Teuchos::null;
915 ritzVecsCurrent_ =
false;
916 ritzValsCurrent_ =
false;
917 schurCurrent_ =
false;
922 if (om_->isVerbosity(
Debug ) ) {
928 om_->print(
Debug, accuracyCheck(chk,
": after initialize()") );
932 if (om_->isVerbosity(
Debug)) {
933 currentStatus( om_->stream(
Debug) );
943 template <
class ScalarType,
class MV,
class OP>
953 template <
class ScalarType,
class MV,
class OP>
959 if (initialized_ ==
false) {
965 int searchDim = blockSize_*numBlocks_;
966 if (problem_->isHermitian() ==
false) {
975 while (tester_->checkStatus(
this) !=
Passed && curDim_+blockSize_ <= searchDim) {
980 int lclDim = curDim_ + blockSize_;
983 std::vector<int> curind(blockSize_);
984 for (
int i=0; i<blockSize_; i++) { curind[i] = lclDim + i; }
989 for (
int i=0; i<blockSize_; i++) { curind[i] = curDim_ + i; }
996 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
999 OPT::Apply(*Op_,*Vprev,*Vnext);
1000 count_ApplyOp_ += blockSize_;
1004 Vprev = Teuchos::null;
1008 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1013 std::vector<int> prevind(lclDim);
1014 for (
int i=0; i<lclDim; i++) { prevind[i] = i; }
1015 Vprev = MVT::CloneView(*V_,prevind);
1026 if (auxVecs_.size() > 0) {
1027 for (Array_size_type i=0; i<auxVecs_.size(); i++) {
1028 AVprev.
append( auxVecs_[i] );
1029 AsubH.
append( Teuchos::null );
1038 (
Teuchos::View,*H_,blockSize_,blockSize_,lclDim,curDim_ ) );
1039 int rank = orthman_->projectAndNormalize(*Vnext,AVprev,AsubH,subR);
1046 "Anasazi::BlockKrylovSchur::iterate(): couldn't generate basis of full rank.");
1052 Vnext = Teuchos::null;
1053 curDim_ += blockSize_;
1055 ritzVecsCurrent_ =
false;
1056 ritzValsCurrent_ =
false;
1057 schurCurrent_ =
false;
1060 if (!(iter_%stepSize_)) {
1061 computeRitzValues();
1065 if (om_->isVerbosity(
Debug ) ) {
1069 chk.checkArn =
true;
1070 om_->print(
Debug, accuracyCheck(chk,
": after local update") );
1075 om_->print(
OrthoDetails, accuracyCheck(chk,
": after local update") );
1079 if (om_->isVerbosity(
Debug)) {
1080 currentStatus( om_->stream(
Debug) );
1104 template <
class ScalarType,
class MV,
class OP>
1107 std::stringstream os;
1109 os.setf(std::ios::scientific, std::ios::floatfield);
1112 os <<
" Debugging checks: iteration " << iter_ << where << std::endl;
1115 std::vector<int> lclind(curDim_);
1116 for (
int i=0; i<curDim_; i++) lclind[i] = i;
1117 std::vector<int> bsind(blockSize_);
1118 for (
int i=0; i<blockSize_; i++) { bsind[i] = curDim_ + i; }
1123 lclV = MVT::CloneView(*V_,lclind);
1124 lclF = MVT::CloneView(*V_,bsind);
1128 tmp = orthman_->orthonormError(*lclV);
1129 os <<
" >> Error in V^H M V == I : " << tmp << std::endl;
1131 tmp = orthman_->orthonormError(*lclF);
1132 os <<
" >> Error in F^H M F == I : " << tmp << std::endl;
1134 tmp = orthman_->orthogError(*lclV,*lclF);
1135 os <<
" >> Error in V^H M F == 0 : " << tmp << std::endl;
1137 for (Array_size_type i=0; i<auxVecs_.size(); i++) {
1139 tmp = orthman_->orthogError(*lclV,*auxVecs_[i]);
1140 os <<
" >> Error in V^H M Aux[" << i <<
"] == 0 : " << tmp << std::endl;
1142 tmp = orthman_->orthogError(*lclF,*auxVecs_[i]);
1143 os <<
" >> Error in F^H M Aux[" << i <<
"] == 0 : " << tmp << std::endl;
1151 lclAV = MVT::Clone(*V_,curDim_);
1153 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1156 OPT::Apply(*Op_,*lclV,*lclAV);
1161 MVT::MvTimesMatAddMv( -ST_ONE, *lclV, subH, ST_ONE, *lclAV );
1165 blockSize_,curDim_, curDim_ );
1166 MVT::MvTimesMatAddMv( -ST_ONE, *lclF, curB, ST_ONE, *lclAV );
1169 std::vector<MagnitudeType> arnNorms( curDim_ );
1170 orthman_->norm( *lclAV, arnNorms );
1172 for (
int i=0; i<curDim_; i++) {
1173 os <<
" >> Error in Krylov-Schur factorization (R = AV-VS-FB^H), ||R[" << i <<
"]|| : " << arnNorms[i] << std::endl;
1179 for (Array_size_type i=0; i<auxVecs_.size(); i++) {
1180 tmp = orthman_->orthonormError(*auxVecs_[i]);
1181 os <<
" >> Error in Aux[" << i <<
"]^H M Aux[" << i <<
"] == I : " << tmp << std::endl;
1182 for (Array_size_type j=i+1; j<auxVecs_.size(); j++) {
1183 tmp = orthman_->orthogError(*auxVecs_[i],*auxVecs_[j]);
1184 os <<
" >> Error in Aux[" << i <<
"]^H M Aux[" << j <<
"] == 0 : " << tmp << std::endl;
1205 template <
class ScalarType,
class MV,
class OP>
1213 if (!ritzValsCurrent_) {
1216 computeSchurForm(
false );
1233 template <
class ScalarType,
class MV,
class OP>
1236 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1241 "Anasazi::BlockKrylovSchur::computeRitzVectors(): no Ritz vectors were required from this solver.");
1244 "Anasazi::BlockKrylovSchur::computeRitzVectors(): the current subspace is not large enough to compute the number of requested Ritz vectors.");
1248 if (curDim_ && initialized_) {
1251 if (!ritzVecsCurrent_) {
1254 if (!schurCurrent_) {
1257 computeSchurForm(
true );
1263 "Anasazi::BlockKrylovSchur::computeRitzVectors(): the number of required Ritz vectors splits a complex conjugate pair.");
1276 std::vector<int> curind( curDim_ );
1277 for (
int i=0; i<curDim_; i++) { curind[i] = i; }
1279 if (problem_->isHermitian()) {
1284 MVT::MvTimesMatAddMv( ST_ONE, *Vtemp, subQ, ST_ZERO, *ritzVectors_ );
1295 MVT::MvTimesMatAddMv( ST_ONE, *Vtemp, subQ, ST_ZERO, *tmpritzVectors_ );
1303 int lwork = 3*curDim_;
1304 std::vector<ScalarType> work( lwork );
1305 std::vector<MagnitudeType> rwork( curDim_ );
1309 ScalarType vl[ ldvl ];
1311 lapack.
TREVC( side, curDim_, schurH_->values(), schurH_->stride(), vl, ldvl,
1312 copyQ.
values(), copyQ.
stride(), curDim_, &mm, &work[0], &rwork[0], &info );
1314 "Anasazi::BlockKrylovSchur::computeRitzVectors(): TREVC(n==" << curDim_ <<
") returned info " << info <<
" != 0.");
1320 curind.resize( numRitzVecs_ );
1321 Teuchos::RCP<MV> view_ritzVectors = MVT::CloneViewNonConst( *ritzVectors_, curind );
1322 MVT::MvTimesMatAddMv( ST_ONE, *tmpritzVectors_, subCopyQ, ST_ZERO, *view_ritzVectors );
1325 std::vector<MagnitudeType> ritzNrm( numRitzVecs_ );
1326 MVT::MvNorm( *view_ritzVectors, ritzNrm );
1329 tmpritzVectors_ = Teuchos::null;
1330 view_ritzVectors = Teuchos::null;
1333 ScalarType ritzScale = ST_ONE;
1334 for (
int i=0; i<numRitzVecs_; i++) {
1337 if (ritzIndex_[i] == 1 ) {
1338 ritzScale = ST_ONE/lapack_mag.
LAPY2(ritzNrm[i],ritzNrm[i+1]);
1339 std::vector<int> newind(2);
1340 newind[0] = i; newind[1] = i+1;
1341 tmpritzVectors_ = MVT::CloneCopy( *ritzVectors_, newind );
1342 view_ritzVectors = MVT::CloneViewNonConst( *ritzVectors_, newind );
1343 MVT::MvAddMv( ritzScale, *tmpritzVectors_, ST_ZERO, *tmpritzVectors_, *view_ritzVectors );
1350 std::vector<int> newind(1);
1352 tmpritzVectors_ = MVT::CloneCopy( *ritzVectors_, newind );
1353 view_ritzVectors = MVT::CloneViewNonConst( *ritzVectors_, newind );
1354 MVT::MvAddMv( ST_ONE/ritzNrm[i], *tmpritzVectors_, ST_ZERO, *tmpritzVectors_, *view_ritzVectors );
1361 ritzVecsCurrent_ =
true;
1370 template <
class ScalarType,
class MV,
class OP>
1373 "Anasazi::BlockKrylovSchur::setStatusTest() was passed a null StatusTest.");
1379 template <
class ScalarType,
class MV,
class OP>
1397 template <
class ScalarType,
class MV,
class OP>
1401 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1409 if (!schurCurrent_) {
1413 if (!ritzValsCurrent_) {
1437 int lwork = 3*curDim_;
1438 std::vector<ScalarType> work( lwork );
1439 std::vector<MagnitudeType> rwork( curDim_ );
1440 std::vector<MagnitudeType> tmp_rRitzValues( curDim_ );
1441 std::vector<MagnitudeType> tmp_iRitzValues( curDim_ );
1442 std::vector<int> bwork( curDim_ );
1443 int info = 0, sdim = 0;
1445 lapack.
GEES( jobvs,curDim_, schurH_->values(), schurH_->stride(), &sdim, &tmp_rRitzValues[0],
1446 &tmp_iRitzValues[0], subQ.
values(), subQ.
stride(), &work[0], lwork,
1447 &rwork[0], &bwork[0], &info );
1450 "Anasazi::BlockKrylovSchur::computeSchurForm(): GEES(n==" << curDim_ <<
") returned info " << info <<
" != 0.");
1467 blockSize_, curDim_, curDim_ );
1477 ScalarType* b_ptr = subB.
values();
1478 if (problem_->isHermitian()) {
1482 for (
int i=0; i<curDim_ ; i++) {
1483 ritzResiduals_[i] = blas.
NRM2(blockSize_, b_ptr + i*blockSize_, 1);
1492 ScalarType vl[ ldvl ];
1494 lapack.
TREVC( side, curDim_, schurH_->values(), schurH_->stride(), vl, ldvl,
1495 S.
values(), S.
stride(), curDim_, &mm, &work[0], &rwork[0], &info );
1498 "Anasazi::BlockKrylovSchur::computeSchurForm(): TREVC(n==" << curDim_ <<
") returned info " << info <<
" != 0.");
1543 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1547 if (problem_->isHermitian()) {
1550 sm_->sort(tmp_rRitzValues, Teuchos::rcpFromRef(ritzOrder_), curDim_);
1552 while ( i < curDim_ ) {
1554 ritzValues_[i].set(tmp_rRitzValues[i], MT_ZERO);
1555 ritzIndex_.push_back(0);
1562 sm_->sort(tmp_rRitzValues, tmp_iRitzValues, Teuchos::rcpFromRef(ritzOrder_) , curDim_);
1567 std::vector<MagnitudeType> ritz2( curDim_ );
1568 for (i=0; i<curDim_; i++) { ritz2[i] = ritzResiduals_[ ritzOrder_[i] ]; }
1569 blas_mag.
COPY( curDim_, &ritz2[0], 1, &ritzResiduals_[0], 1 );
1572 ritzValsCurrent_ =
true;
1588 sortSchurForm( *schurH_, *Q_, ritzOrder_ );
1591 schurCurrent_ =
true;
1602 template <
class ScalarType,
class MV,
class OP>
1605 std::vector<int>& order )
1608 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
1620 int i = 0, nevtemp = 0;
1622 std::vector<int> offset2( curDim_ );
1623 std::vector<int> order2( curDim_ );
1627 int lwork = 3*curDim_;
1628 std::vector<ScalarType> work( lwork );
1630 while (i < curDim_) {
1631 if ( ritzIndex_[i] != 0 ) {
1632 offset2[nevtemp] = 0;
1633 for (
int j=i; j<curDim_; j++) {
1634 if (order[j] > order[i]) { offset2[nevtemp]++; }
1636 order2[nevtemp] = order[i];
1639 offset2[nevtemp] = 0;
1640 for (
int j=i; j<curDim_; j++) {
1641 if (order[j] > order[i]) { offset2[nevtemp]++; }
1643 order2[nevtemp] = order[i];
1648 ScalarType *ptr_h = H.
values();
1649 ScalarType *ptr_q = Q.
values();
1652 for (i=nevtemp-1; i>=0; i--) {
1653 lapack.
TREXC( compq, curDim_, ptr_h, ldh, ptr_q, ldq, order2[i]+1+offset2[i],
1654 1, &work[0], &info );
1656 "Anasazi::BlockKrylovSchur::computeSchurForm(): TREXC(n==" << curDim_ <<
") returned info " << info <<
" != 0.");
1662 template <
class ScalarType,
class MV,
class OP>
1667 os.setf(std::ios::scientific, std::ios::floatfield);
1669 os <<
"================================================================================" << endl;
1671 os <<
" BlockKrylovSchur Solver Status" << endl;
1673 os <<
"The solver is "<<(initialized_ ?
"initialized." :
"not initialized.") << endl;
1674 os <<
"The number of iterations performed is " <<iter_<<endl;
1675 os <<
"The block size is " << blockSize_<<endl;
1676 os <<
"The number of blocks is " << numBlocks_<<endl;
1677 os <<
"The current basis size is " << curDim_<<endl;
1678 os <<
"The number of auxiliary vectors is " << numAuxVecs_ << endl;
1679 os <<
"The number of operations Op*x is "<<count_ApplyOp_<<endl;
1681 os.setf(std::ios_base::right, std::ios_base::adjustfield);
1685 os <<
"CURRENT RITZ VALUES "<<endl;
1686 if (ritzIndex_.size() != 0) {
1687 int numPrint = (curDim_ < numRitzPrint_? curDim_: numRitzPrint_);
1688 if (problem_->isHermitian()) {
1689 os << std::setw(20) <<
"Ritz Value"
1690 << std::setw(20) <<
"Ritz Residual"
1692 os <<
"--------------------------------------------------------------------------------"<<endl;
1693 for (
int i=0; i<numPrint; i++) {
1694 os << std::setw(20) << ritzValues_[i].realpart
1695 << std::setw(20) << ritzResiduals_[i]
1699 os << std::setw(24) <<
"Ritz Value"
1700 << std::setw(30) <<
"Ritz Residual"
1702 os <<
"--------------------------------------------------------------------------------"<<endl;
1703 for (
int i=0; i<numPrint; i++) {
1705 os << std::setw(15) << ritzValues_[i].realpart;
1706 if (ritzValues_[i].imagpart < MT_ZERO) {
1709 os <<
" + i" << std::setw(15) << ritzValues_[i].imagpart;
1711 os << std::setw(20) << ritzResiduals_[i] << endl;
1715 os << std::setw(20) <<
"[ NONE COMPUTED ]" << endl;
1719 os <<
"================================================================================" << endl;
ScalarType * values() const
void computeRitzValues()
Compute the Ritz values using the current Krylov factorization.
BlockKrylovSchurOrthoFailure is thrown when the orthogonalization manager is unable to generate ortho...
Teuchos::Array< Teuchos::RCP< const MV > > getAuxVecs() const
Get the auxiliary vectors for the solver.
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > H
The current Hessenberg matrix.
BlockKrylovSchurState< ScalarType, MV > getState() const
Get the current state of the eigensolver.
An extension of the MultiVecTraits class that adds a new vector length method.This traits class provi...
void setStepSize(int stepSize)
Set the step size.
bool isRitzValsCurrent() const
Get the status of the Ritz values currently stored in the eigensolver.
const Eigenproblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the eigenvalue problem.
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getRitzRes2Norms()
Get the current Ritz residual 2-norms.
Array< T > & append(const T &x)
void TREXC(const char COMPQ, const OrdinalType n, ScalarType *T, const OrdinalType ldt, ScalarType *Q, const OrdinalType ldq, OrdinalType ifst, OrdinalType ilst, ScalarType *WORK, OrdinalType *info) const
Teuchos::RCP< const MV > getRitzVectors()
Get the Ritz vectors.
This class defines the interface required by an eigensolver and status test class to compute solution...
virtual ~BlockKrylovSchur()
BlockKrylovSchur destructor.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this eigenproblem.
Declaration of basic traits for the multivector type.
bool isInitialized() const
Indicates whether the solver has been initialized or not.
T & get(const std::string &name, T def_value)
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getResNorms()
Get the current residual norms.
void setAuxVecs(const Teuchos::Array< Teuchos::RCP< const MV > > &auxvecs)
Set the auxiliary vectors for the solver.
void COPY(const OrdinalType n, const ScalarType *x, const OrdinalType incx, ScalarType *y, const OrdinalType incy) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void iterate()
This method performs Block Krylov-Schur iterations until the status test indicates the need to stop o...
Virtual base class which defines basic traits for the operator type.
void GEES(const char JOBVS, const char SORT, OrdinalType(*ptr2func)(ScalarType *, ScalarType *), const OrdinalType n, ScalarType *A, const OrdinalType lda, OrdinalType *sdim, ScalarType *WR, ScalarType *WI, ScalarType *VS, const OrdinalType ldvs, ScalarType *WORK, const OrdinalType lwork, OrdinalType *BWORK, OrdinalType *info) const
static void scaleRitzVectors(const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &iRV, Teuchos::SerialDenseMatrix< int, ScalarType > *S)
Helper function for correctly scaling the eigenvectors of the projected eigenproblem.
Structure to contain pointers to BlockKrylovSchur state variables.
An exception class parent to all Anasazi exceptions.
void setStatusTest(Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test)
Set a new StatusTest for the solver.
void TREVC(const char SIDE, const char HOWMNY, OrdinalType *select, const OrdinalType n, const ScalarType *T, const OrdinalType ldt, ScalarType *VL, const OrdinalType ldvl, ScalarType *VR, const OrdinalType ldvr, const OrdinalType mm, OrdinalType *m, ScalarType *WORK, OrdinalType *info) const
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current eigenvectors and eigenvalues...
int getNumIters() const
Get the current iteration count.
Pure virtual base class which describes the basic interface to the iterative eigensolver.
bool isRitzVecsCurrent() const
Get the status of the Ritz vectors currently stored in the eigensolver.
void initialize()
Initialize the solver with the initial vectors from the eigenproblem or random data.
void computeRitzVectors()
Compute the Ritz vectors using the current Krylov factorization.
int getStepSize() const
Get the step size.
bool isParameter(const std::string &name) const
void setNumRitzVectors(int numRitzVecs)
Set the number of Ritz vectors to compute.
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > getStatusTest() const
Get the current StatusTest used by the solver.
void computeSchurForm(const bool sort=true)
Compute the Schur form of the projected eigenproblem from the current Krylov factorization.
static void sortRitzValues(const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &rRV, const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &iRV, std::vector< Value< ScalarType > > *RV, std::vector< int > *RO, std::vector< int > *RI)
Helper function for correctly storing the Ritz values when the eigenproblem is non-Hermitian.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool isSchurCurrent() const
Get the status of the Schur form currently stored in the eigensolver.
BlockKrylovSchur(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< OrthoManager< ScalarType, MV > > &ortho, Teuchos::ParameterList ¶ms)
BlockKrylovSchur constructor with eigenproblem, solver utilities, and parameter list of solver option...
Output managers remove the need for the eigensolver to know any information about the required output...
void resetNumIters()
Reset the iteration count.
void GEMM(ETransp transa, ETransp transb, const OrdinalType m, const OrdinalType n, const OrdinalType k, const alpha_type alpha, const A_type *A, const OrdinalType lda, const B_type *B, const OrdinalType ldb, const beta_type beta, ScalarType *C, const OrdinalType ldc) const
Templated virtual class for providing orthogonalization/orthonormalization methods.
Traits class which defines basic operations on multivectors.
Virtual base class which defines basic traits for the operator type.
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace.
int getNumRitzVectors() const
Get the number of Ritz vectors to compute.
std::vector< Value< ScalarType > > getRitzValues()
Get the Ritz values.
std::vector< int > getRitzIndex()
Get the Ritz index vector.
static magnitudeType magnitude(T a)
std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getRes2Norms()
Get the current residual 2-norms.
Teuchos::RCP< const MulVec > V
The current Krylov basis.
BlockKrylovSchurInitFailure is thrown when the BlockKrylovSchur solver is unable to generate an initi...
Types and exceptions used within Anasazi solvers and interfaces.
void currentStatus(std::ostream &os)
This method requests that the solver print out its current status to screen.
Anasazi's templated virtual class for providing routines for orthogonalization and orthonormalization...
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > Q
The current Schur vectors of the valid part of H.
static void computeRitzResiduals(const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &iRV, const Teuchos::SerialDenseMatrix< int, ScalarType > &S, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > *RR)
Helper function for correctly computing the Ritz residuals of the projected eigenproblem.
void setBlockSize(int blockSize)
Set the blocksize.
This class implements the block Krylov-Schur iteration, for solving linear eigenvalue problems...
Anasazi's templated pure virtual class for managing the sorting of approximate eigenvalues computed b...
void setSize(int blockSize, int numBlocks)
Set the blocksize and number of blocks to be used by the iterative solver in solving this eigenproble...
int curDim
The current dimension of the reduction.
A pure virtual class for defining the status tests for the Anasazi iterative solvers.
The Eigensolver is a templated virtual base class that defines the basic interface that any eigensolv...
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > S
The current Schur form reduction of the valid part of H.
OrdinalType stride() const
ScalarType LAPY2(const ScalarType x, const ScalarType y) const
ScalarTraits< ScalarType >::magnitudeType NRM2(const OrdinalType n, const ScalarType *x, const OrdinalType incx) const