Anasazi  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AnasaziBlockKrylovSchurSolMgr.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Anasazi: Block Eigensolvers Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // USA
24 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
25 //
26 // ***********************************************************************
27 // @HEADER
28 
29 #ifndef ANASAZI_BLOCK_KRYLOV_SCHUR_SOLMGR_HPP
30 #define ANASAZI_BLOCK_KRYLOV_SCHUR_SOLMGR_HPP
31 
36 #include "AnasaziConfigDefs.hpp"
37 #include "AnasaziTypes.hpp"
38 
39 #include "AnasaziEigenproblem.hpp"
40 #include "AnasaziSolverManager.hpp"
41 #include "AnasaziSolverUtils.hpp"
42 
44 #include "AnasaziBasicSort.hpp"
52 #include "Teuchos_BLAS.hpp"
53 #include "Teuchos_LAPACK.hpp"
54 #include "Teuchos_TimeMonitor.hpp"
55 
56 
77 namespace Anasazi {
78 
79 
106 template<class ScalarType, class MV, class OP>
107 class BlockKrylovSchurSolMgr : public SolverManager<ScalarType,MV,OP> {
108 
109  private:
114  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
116 
117  public:
118 
120 
121 
141 
145 
147 
148 
151  return *_problem;
152  }
153 
155  int getNumIters() const {
156  return _numIters;
157  }
158 
161  std::vector<Value<ScalarType> > getRitzValues() const {
162  std::vector<Value<ScalarType> > ret( _ritzValues );
163  return ret;
164  }
165 
173  return Teuchos::tuple(_timerSolve, _timerRestarting);
174  }
175 
177 
179 
180 
199  ReturnType solve();
200 
203 
206 
209 
212 
214 
215  private:
218 
219  std::string _whch, _ortho;
220  MagnitudeType _ortho_kappa;
221 
222  MagnitudeType _convtol;
223  int _maxRestarts;
224  bool _relconvtol,_conjSplit;
225  int _blockSize, _numBlocks, _stepSize, _nevBlocks, _xtra_nevBlocks;
226  int _numIters;
227  int _verbosity;
228  bool _inSituRestart, _dynXtraNev;
229 
230  std::vector<Value<ScalarType> > _ritzValues;
231 
232  int _printNum;
233  Teuchos::RCP<Teuchos::Time> _timerSolve, _timerRestarting;
234 
237 
238 };
239 
240 
241 // Constructor
242 template<class ScalarType, class MV, class OP>
245  Teuchos::ParameterList &pl ) :
246  _problem(problem),
247  _whch("LM"),
248  _ortho("SVQB"),
249  _ortho_kappa(-1.0),
250  _convtol(0),
251  _maxRestarts(20),
252  _relconvtol(true),
253  _conjSplit(false),
254  _blockSize(0),
255  _numBlocks(0),
256  _stepSize(0),
257  _nevBlocks(0),
258  _xtra_nevBlocks(0),
259  _numIters(0),
260  _verbosity(Anasazi::Errors),
261  _inSituRestart(false),
262  _dynXtraNev(false),
263  _printNum(-1)
264 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
265  ,_timerSolve(Teuchos::TimeMonitor::getNewTimer("Anasazi: BlockKrylovSchurSolMgr::solve()")),
266  _timerRestarting(Teuchos::TimeMonitor::getNewTimer("Anasazi: BlockKrylovSchurSolMgr restarting"))
267 #endif
268 {
269  TEUCHOS_TEST_FOR_EXCEPTION(_problem == Teuchos::null, std::invalid_argument, "Problem not given to solver manager.");
270  TEUCHOS_TEST_FOR_EXCEPTION(!_problem->isProblemSet(), std::invalid_argument, "Problem not set.");
271  TEUCHOS_TEST_FOR_EXCEPTION(_problem->getInitVec() == Teuchos::null, std::invalid_argument, "Problem does not contain initial vectors to clone from.");
272 
273  const int nev = _problem->getNEV();
274 
275  // convergence tolerance
276  _convtol = pl.get("Convergence Tolerance",MT::prec());
277  _relconvtol = pl.get("Relative Convergence Tolerance",_relconvtol);
278 
279  // maximum number of restarts
280  _maxRestarts = pl.get("Maximum Restarts",_maxRestarts);
281 
282  // block size: default is 1
283  _blockSize = pl.get("Block Size",1);
284  TEUCHOS_TEST_FOR_EXCEPTION(_blockSize <= 0, std::invalid_argument,
285  "Anasazi::BlockKrylovSchurSolMgr: \"Block Size\" must be strictly positive.");
286 
287  // set the number of blocks we need to save to compute the nev eigenvalues of interest.
288  _xtra_nevBlocks = pl.get("Extra NEV Blocks",0);
289  if (nev%_blockSize) {
290  _nevBlocks = nev/_blockSize + _xtra_nevBlocks + 1;
291  } else {
292  _nevBlocks = nev/_blockSize + _xtra_nevBlocks;
293  }
294 
295  // determine if we should use the dynamic scheme for selecting the current number of retained eigenvalues.
296  // NOTE: This employs a technique similar to ARPACK in that it increases the number of retained eigenvalues
297  // by one for every converged eigenpair to accelerate convergence.
298  if (pl.isParameter("Dynamic Extra NEV")) {
299  if (Teuchos::isParameterType<bool>(pl,"Dynamic Extra NEV")) {
300  _dynXtraNev = pl.get("Dynamic Extra NEV",_dynXtraNev);
301  } else {
302  _dynXtraNev = ( Teuchos::getParameter<int>(pl,"Dynamic Extra NEV") != 0 );
303  }
304  }
305 
306  _numBlocks = pl.get("Num Blocks",3*_nevBlocks);
307  TEUCHOS_TEST_FOR_EXCEPTION(_numBlocks <= _nevBlocks, std::invalid_argument,
308  "Anasazi::BlockKrylovSchurSolMgr: \"Num Blocks\" must be strictly positive and large enough to compute the requested eigenvalues.");
309 
310  TEUCHOS_TEST_FOR_EXCEPTION(static_cast<ptrdiff_t>(_numBlocks)*_blockSize > MVText::GetGlobalLength(*_problem->getInitVec()),
311  std::invalid_argument,
312  "Anasazi::BlockKrylovSchurSolMgr: Potentially impossible orthogonality requests. Reduce basis size.");
313 
314  // step size: the default is _maxRestarts*_numBlocks, so that Ritz values are only computed every restart.
315  if (_maxRestarts) {
316  _stepSize = pl.get("Step Size", (_maxRestarts+1)*(_numBlocks+1));
317  } else {
318  _stepSize = pl.get("Step Size", _numBlocks+1);
319  }
320  TEUCHOS_TEST_FOR_EXCEPTION(_stepSize < 1, std::invalid_argument,
321  "Anasazi::BlockKrylovSchurSolMgr: \"Step Size\" must be strictly positive.");
322 
323  // get the sort manager
324  if (pl.isParameter("Sort Manager")) {
325  _sort = Teuchos::getParameter<Teuchos::RCP<Anasazi::SortManager<MagnitudeType> > >(pl,"Sort Manager");
326  } else {
327  // which values to solve for
328  _whch = pl.get("Which",_whch);
329  TEUCHOS_TEST_FOR_EXCEPTION(_whch != "SM" && _whch != "LM" && _whch != "SR" && _whch != "LR" && _whch != "SI" && _whch != "LI",
330  std::invalid_argument, "Invalid sorting string.");
331  _sort = Teuchos::rcp( new BasicSort<MagnitudeType>(_whch) );
332  }
333 
334  // which orthogonalization to use
335  _ortho = pl.get("Orthogonalization",_ortho);
336  if (_ortho != "DGKS" && _ortho != "SVQB") {
337  _ortho = "SVQB";
338  }
339 
340  // which orthogonalization constant to use
341  _ortho_kappa = pl.get("Orthogonalization Constant",_ortho_kappa);
342 
343  // verbosity level
344  if (pl.isParameter("Verbosity")) {
345  if (Teuchos::isParameterType<int>(pl,"Verbosity")) {
346  _verbosity = pl.get("Verbosity", _verbosity);
347  } else {
348  _verbosity = (int)Teuchos::getParameter<Anasazi::MsgType>(pl,"Verbosity");
349  }
350  }
351 
352  // restarting technique: V*Q or applyHouse(V,H,tau)
353  if (pl.isParameter("In Situ Restarting")) {
354  if (Teuchos::isParameterType<bool>(pl,"In Situ Restarting")) {
355  _inSituRestart = pl.get("In Situ Restarting",_inSituRestart);
356  } else {
357  _inSituRestart = ( Teuchos::getParameter<int>(pl,"In Situ Restarting") != 0 );
358  }
359  }
360 
361  _printNum = pl.get<int>("Print Number of Ritz Values",-1);
362 }
363 
364 
365 // solve()
366 template<class ScalarType, class MV, class OP>
367 ReturnType
369 
370  const int nev = _problem->getNEV();
371  ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
372  ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
373 
376  typedef SolverUtils<ScalarType,MV,OP> msutils;
377 
379  // Output manager
381 
383  // Status tests
384  //
385  // convergence
387  if (globalTest_ == Teuchos::null) {
389  }
390  else {
391  convtest = globalTest_;
392  }
394  = Teuchos::rcp( new StatusTestWithOrdering<ScalarType,MV,OP>(convtest,_sort,nev) );
395  // for a non-short-circuited OR test, the order doesn't matter
397  alltests.push_back(ordertest);
398 
399  if (debugTest_ != Teuchos::null) alltests.push_back(debugTest_);
400 
403  // printing StatusTest
405  if ( printer->isVerbosity(Debug) ) {
406  outputtest = Teuchos::rcp( new StatusTestOutput<ScalarType,MV,OP>( printer,combotest,1,Passed+Failed+Undefined ) );
407  }
408  else {
409  outputtest = Teuchos::rcp( new StatusTestOutput<ScalarType,MV,OP>( printer,combotest,1,Passed ) );
410  }
411 
413  // Orthomanager
415  if (_ortho=="SVQB") {
416  ortho = Teuchos::rcp( new SVQBOrthoManager<ScalarType,MV,OP>(_problem->getM()) );
417  } else if (_ortho=="DGKS") {
418  if (_ortho_kappa <= 0) {
419  ortho = Teuchos::rcp( new BasicOrthoManager<ScalarType,MV,OP>(_problem->getM()) );
420  }
421  else {
422  ortho = Teuchos::rcp( new BasicOrthoManager<ScalarType,MV,OP>(_problem->getM(),_ortho_kappa) );
423  }
424  } else {
425  TEUCHOS_TEST_FOR_EXCEPTION(_ortho!="SVQB"&&_ortho!="DGKS",std::logic_error,"Anasazi::BlockKrylovSchurSolMgr::solve(): Invalid orthogonalization type.");
426  }
427 
429  // Parameter list
431  plist.set("Block Size",_blockSize);
432  plist.set("Num Blocks",_numBlocks);
433  plist.set("Step Size",_stepSize);
434  if (_printNum == -1) {
435  plist.set("Print Number of Ritz Values",_nevBlocks*_blockSize);
436  }
437  else {
438  plist.set("Print Number of Ritz Values",_printNum);
439  }
440 
442  // BlockKrylovSchur solver
444  = Teuchos::rcp( new BlockKrylovSchur<ScalarType,MV,OP>(_problem,_sort,printer,outputtest,ortho,plist) );
445  // set any auxiliary vectors defined in the problem
446  Teuchos::RCP< const MV > probauxvecs = _problem->getAuxVecs();
447  if (probauxvecs != Teuchos::null) {
448  bks_solver->setAuxVecs( Teuchos::tuple< Teuchos::RCP<const MV> >(probauxvecs) );
449  }
450 
451  // Create workspace for the Krylov basis generated during a restart
452  // Need at most (_nevBlocks*_blockSize+1) for the updated factorization and another block for the current factorization residual block (F).
453  // ---> (_nevBlocks*_blockSize+1) + _blockSize
454  // If Hermitian, this becomes _nevBlocks*_blockSize + _blockSize
455  // we only need this if there is the possibility of restarting, ex situ
456 
457  // Maximum allowable extra vectors that BKS can keep to accelerate convergence; only works for _blockSize=1
458  int maxXtraVecs = 0;
459  if ( _dynXtraNev && _blockSize==1 ) maxXtraVecs = ( bks_solver->getMaxSubspaceDim() - _nevBlocks ) / 2;
460 
461  Teuchos::RCP<MV> workMV;
462  if (_maxRestarts > 0) {
463  if (_inSituRestart==true) {
464  // still need one work vector for applyHouse()
465  workMV = MVT::Clone( *_problem->getInitVec(), 1 );
466  }
467  else { // inSituRestart == false
468  if (_problem->isHermitian()) {
469  workMV = MVT::Clone( *_problem->getInitVec(), (_nevBlocks+maxXtraVecs)*_blockSize + _blockSize );
470  } else {
471  workMV = MVT::Clone( *_problem->getInitVec(), (_nevBlocks+maxXtraVecs)*_blockSize + 1 + _blockSize );
472  }
473  }
474  } else {
475  workMV = Teuchos::null;
476  }
477 
478  // go ahead and initialize the solution to nothing in case we throw an exception
480  sol.numVecs = 0;
481  _problem->setSolution(sol);
482 
483  int numRestarts = 0;
484  int cur_nevBlocks = 0;
485 
486  // enter solve() iterations
487  {
488 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
489  Teuchos::TimeMonitor slvtimer(*_timerSolve);
490 #endif
491 
492  // tell bks_solver to iterate
493  while (1) {
494  try {
495  bks_solver->iterate();
496 
498  //
499  // check convergence first
500  //
502  if ( ordertest->getStatus() == Passed ) {
503  // we have convergence
504  // ordertest->whichVecs() tells us which vectors from solver state are the ones we want
505  // ordertest->howMany() will tell us how many
506  break;
507  }
509  //
510  // check for restarting, i.e. the subspace is full
511  //
513  // this is for the Hermitian case, or non-Hermitian conjugate split situation.
514  // --> for the Hermitian case the current subspace dimension needs to match the maximum subspace dimension
515  // --> for the non-Hermitian case:
516  // --> if a conjugate pair was detected in the previous restart then the current subspace dimension needs to match the
517  // maximum subspace dimension (the BKS solver keeps one extra vector if the problem is non-Hermitian).
518  // --> if a conjugate pair was not detected in the previous restart then the current subspace dimension will be one less
519  // than the maximum subspace dimension.
520  else if ( (bks_solver->getCurSubspaceDim() == bks_solver->getMaxSubspaceDim()) ||
521  (!_problem->isHermitian() && !_conjSplit && (bks_solver->getCurSubspaceDim()+1 == bks_solver->getMaxSubspaceDim())) ) {
522 
523  // Update the Schur form of the projected eigenproblem, then sort it.
524  if (!bks_solver->isSchurCurrent()) {
525  bks_solver->computeSchurForm( true );
526 
527  // Check for convergence, just in case we wait for every restart to check
528  outputtest->checkStatus( &*bks_solver );
529  }
530 
531  // Don't bother to restart if we've converged or reached the maximum number of restarts
532  if ( numRestarts >= _maxRestarts || ordertest->getStatus() == Passed) {
533  break; // break from while(1){bks_solver->iterate()}
534  }
535 
536  // Start restarting timer and increment counter
537 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
538  Teuchos::TimeMonitor restimer(*_timerRestarting);
539 #endif
540  numRestarts++;
541 
542  int numConv = ordertest->howMany();
543  cur_nevBlocks = _nevBlocks*_blockSize;
544  if ( _dynXtraNev && _blockSize==1 && numConv > 0 ) {
545  int cur_numConv = numConv;
546  while ( (cur_nevBlocks < (_nevBlocks + maxXtraVecs)) && cur_numConv > 0 ) {
547  cur_nevBlocks++;
548  cur_numConv--;
549  }
550  }
551 
552  printer->stream(Debug) << " Performing restart number " << numRestarts << " of " << _maxRestarts << std::endl << std::endl;
553 
554  // Get the most current Ritz values before we continue.
555  _ritzValues = bks_solver->getRitzValues();
556 
557  // Get the state.
558  BlockKrylovSchurState<ScalarType,MV> oldState = bks_solver->getState();
559 
560  // Get the current dimension of the factorization
561  int curDim = oldState.curDim;
562 
563  // Determine if the storage for the nev eigenvalues of interest splits a complex conjugate pair.
564  std::vector<int> ritzIndex = bks_solver->getRitzIndex();
565  if (ritzIndex[cur_nevBlocks-1]==1) {
566  _conjSplit = true;
567  cur_nevBlocks++;
568  } else {
569  _conjSplit = false;
570  }
571 
572  // Update the Krylov-Schur decomposition
573 
574  // Get a view of the Schur vectors of interest.
575  Teuchos::SerialDenseMatrix<int,ScalarType> Qnev(Teuchos::View, *(oldState.Q), curDim, cur_nevBlocks);
576 
577  // Get a view of the current Krylov basis.
578  std::vector<int> curind( curDim );
579  for (int i=0; i<curDim; i++) { curind[i] = i; }
580  Teuchos::RCP<const MV> basistemp = MVT::CloneView( *(oldState.V), curind );
581 
582  // Compute the new Krylov basis: Vnew = V*Qnev
583  //
584  // this will occur ex situ in workspace allocated for this purpose (tmpMV)
585  // or in situ in the solver's memory space.
586  //
587  // we will also set a pointer for the location that the current factorization residual block (F),
588  // currently located after the current basis in oldstate.V, will be moved to
589  //
590  Teuchos::RCP<MV> newF;
591  if (_inSituRestart) {
592  //
593  // get non-const pointer to solver's basis so we can work in situ
594  Teuchos::RCP<MV> solverbasis = Teuchos::rcp_const_cast<MV>(oldState.V);
596  //
597  // perform Householder QR of copyQnev = Q [D;0], where D is unit diag. We will want D below.
598  std::vector<ScalarType> tau(cur_nevBlocks), work(cur_nevBlocks);
599  int info;
600  lapack.GEQRF(curDim,cur_nevBlocks,copyQnev.values(),copyQnev.stride(),&tau[0],&work[0],work.size(),&info);
601  TEUCHOS_TEST_FOR_EXCEPTION(info != 0,std::logic_error,
602  "Anasazi::BlockKrylovSchurSolMgr::solve(): error calling GEQRF during restarting.");
603  // we need to get the diagonal of D
604  std::vector<ScalarType> d(cur_nevBlocks);
605  for (int j=0; j<copyQnev.numCols(); j++) {
606  d[j] = copyQnev(j,j);
607  }
608  if (printer->isVerbosity(Debug)) {
609  Teuchos::SerialDenseMatrix<int,ScalarType> R(Teuchos::Copy,copyQnev,cur_nevBlocks,cur_nevBlocks);
610  for (int j=0; j<R.numCols(); j++) {
611  R(j,j) = SCT::magnitude(R(j,j)) - 1.0;
612  for (int i=j+1; i<R.numRows(); i++) {
613  R(i,j) = zero;
614  }
615  }
616  printer->stream(Debug) << "||Triangular factor of Su - I||: " << R.normFrobenius() << std::endl;
617  }
618  //
619  // perform implicit V*Qnev
620  // this actually performs V*[Qnev Qtrunc*M] = [newV truncV], for some unitary M
621  // we are interested in only the first cur_nevBlocks vectors of the result
622  curind.resize(curDim);
623  for (int i=0; i<curDim; i++) curind[i] = i;
624  {
625  Teuchos::RCP<MV> oldV = MVT::CloneViewNonConst(*solverbasis,curind);
626  msutils::applyHouse(cur_nevBlocks,*oldV,copyQnev,tau,workMV);
627  }
628  // multiply newV*D
629  // get pointer to new basis
630  curind.resize(cur_nevBlocks);
631  for (int i=0; i<cur_nevBlocks; i++) { curind[i] = i; }
632  {
633  Teuchos::RCP<MV> newV = MVT::CloneViewNonConst( *solverbasis, curind );
634  MVT::MvScale(*newV,d);
635  }
636  // get pointer to new location for F
637  curind.resize(_blockSize);
638  for (int i=0; i<_blockSize; i++) { curind[i] = cur_nevBlocks + i; }
639  newF = MVT::CloneViewNonConst( *solverbasis, curind );
640  }
641  else {
642  // get pointer to first part of work space
643  curind.resize(cur_nevBlocks);
644  for (int i=0; i<cur_nevBlocks; i++) { curind[i] = i; }
645  Teuchos::RCP<MV> tmp_newV = MVT::CloneViewNonConst(*workMV, curind );
646  // perform V*Qnev
647  MVT::MvTimesMatAddMv( one, *basistemp, Qnev, zero, *tmp_newV );
648  tmp_newV = Teuchos::null;
649  // get pointer to new location for F
650  curind.resize(_blockSize);
651  for (int i=0; i<_blockSize; i++) { curind[i] = cur_nevBlocks + i; }
652  newF = MVT::CloneViewNonConst( *workMV, curind );
653  }
654 
655  // Move the current factorization residual block (F) to the last block of newV.
656  curind.resize(_blockSize);
657  for (int i=0; i<_blockSize; i++) { curind[i] = curDim + i; }
658  Teuchos::RCP<const MV> oldF = MVT::CloneView( *(oldState.V), curind );
659  for (int i=0; i<_blockSize; i++) { curind[i] = i; }
660  MVT::SetBlock( *oldF, curind, *newF );
661  newF = Teuchos::null;
662 
663  // Update the Krylov-Schur quasi-triangular matrix.
664  //
665  // Create storage for the new Schur matrix of the Krylov-Schur factorization
666  // Copy over the current quasi-triangular factorization of oldState.H which is stored in oldState.S.
667  Teuchos::SerialDenseMatrix<int,ScalarType> oldS(Teuchos::View, *(oldState.S), cur_nevBlocks+_blockSize, cur_nevBlocks);
670  //
671  // Get a view of the B block of the current factorization
672  Teuchos::SerialDenseMatrix<int,ScalarType> oldB(Teuchos::View, *(oldState.H), _blockSize, _blockSize, curDim, curDim-_blockSize);
673  //
674  // Get a view of the a block row of the Schur vectors.
675  Teuchos::SerialDenseMatrix<int,ScalarType> subQ(Teuchos::View, *(oldState.Q), _blockSize, cur_nevBlocks, curDim-_blockSize);
676  //
677  // Get a view of the new B block of the updated Krylov-Schur factorization
678  Teuchos::SerialDenseMatrix<int,ScalarType> newB(Teuchos::View, *newH, _blockSize, cur_nevBlocks, cur_nevBlocks);
679  //
680  // Compute the new B block.
681  blas.GEMM( Teuchos::NO_TRANS, Teuchos::NO_TRANS, _blockSize, cur_nevBlocks, _blockSize, one,
682  oldB.values(), oldB.stride(), subQ.values(), subQ.stride(), zero, newB.values(), newB.stride() );
683 
684 
685  //
686  // Set the new state and initialize the solver.
688  if (_inSituRestart) {
689  newstate.V = oldState.V;
690  } else {
691  newstate.V = workMV;
692  }
693  newstate.H = newH;
694  newstate.curDim = cur_nevBlocks;
695  bks_solver->initialize(newstate);
696 
697  } // end of restarting
699  //
700  // we returned from iterate(), but none of our status tests Passed.
701  // something is wrong, and it is probably our fault.
702  //
704  else {
705  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,"Anasazi::BlockKrylovSchurSolMgr::solve(): Invalid return from bks_solver::iterate().");
706  }
707  }
708  catch (const AnasaziError &err) {
709  printer->stream(Errors)
710  << "Anasazi::BlockKrylovSchurSolMgr::solve() caught unexpected exception from Anasazi::BlockKrylovSchur::iterate() at iteration " << bks_solver->getNumIters() << std::endl
711  << err.what() << std::endl
712  << "Anasazi::BlockKrylovSchurSolMgr::solve() returning Unconverged with no solutions." << std::endl;
713  return Unconverged;
714  }
715  }
716 
717  //
718  // free temporary space
719  workMV = Teuchos::null;
720 
721  // Get the most current Ritz values before we return
722  _ritzValues = bks_solver->getRitzValues();
723 
724  sol.numVecs = ordertest->howMany();
725  printer->stream(Debug) << "ordertest->howMany() : " << sol.numVecs << std::endl;
726  std::vector<int> whichVecs = ordertest->whichVecs();
727 
728  // Place any converged eigenpairs in the solution container.
729  if (sol.numVecs > 0) {
730 
731  // Next determine if there is a conjugate pair on the boundary and resize.
732  std::vector<int> tmpIndex = bks_solver->getRitzIndex();
733  for (int i=0; i<(int)_ritzValues.size(); ++i) {
734  printer->stream(Debug) << _ritzValues[i].realpart << " + i " << _ritzValues[i].imagpart << ", Index = " << tmpIndex[i] << std::endl;
735  }
736  printer->stream(Debug) << "Number of converged eigenpairs (before) = " << sol.numVecs << std::endl;
737  for (int i=0; i<sol.numVecs; ++i) {
738  printer->stream(Debug) << "whichVecs[" << i << "] = " << whichVecs[i] << ", tmpIndex[" << whichVecs[i] << "] = " << tmpIndex[whichVecs[i]] << std::endl;
739  }
740  if (tmpIndex[whichVecs[sol.numVecs-1]]==1) {
741  printer->stream(Debug) << "There is a conjugate pair on the boundary, resizing sol.numVecs" << std::endl;
742  whichVecs.push_back(whichVecs[sol.numVecs-1]+1);
743  sol.numVecs++;
744  for (int i=0; i<sol.numVecs; ++i) {
745  printer->stream(Debug) << "whichVecs[" << i << "] = " << whichVecs[i] << ", tmpIndex[" << whichVecs[i] << "] = " << tmpIndex[whichVecs[i]] << std::endl;
746  }
747  }
748 
749  bool keepMore = false;
750  int numEvecs = sol.numVecs;
751  printer->stream(Debug) << "Number of converged eigenpairs (after) = " << sol.numVecs << std::endl;
752  printer->stream(Debug) << "whichVecs[sol.numVecs-1] > sol.numVecs-1 : " << whichVecs[sol.numVecs-1] << " > " << sol.numVecs-1 << std::endl;
753  if (whichVecs[sol.numVecs-1] > (sol.numVecs-1)) {
754  keepMore = true;
755  numEvecs = whichVecs[sol.numVecs-1]+1; // Add 1 to fix zero-based indexing
756  printer->stream(Debug) << "keepMore = true; numEvecs = " << numEvecs << std::endl;
757  }
758 
759  // Next set the number of Ritz vectors that the iteration must compute and compute them.
760  bks_solver->setNumRitzVectors(numEvecs);
761  bks_solver->computeRitzVectors();
762 
763  // If the leading Ritz pairs are the converged ones, get the information
764  // from the iteration to the solution container. Otherwise copy the necessary
765  // information using 'whichVecs'.
766  if (!keepMore) {
767  sol.index = bks_solver->getRitzIndex();
768  sol.Evals = bks_solver->getRitzValues();
769  sol.Evecs = MVT::CloneCopy( *(bks_solver->getRitzVectors()) );
770  }
771 
772  // Resize based on the number of solutions being returned and set the number of Ritz
773  // vectors for the iteration to compute.
774  sol.Evals.resize(sol.numVecs);
775  sol.index.resize(sol.numVecs);
776 
777  // If the converged Ritz pairs are not the leading ones, copy over the information directly.
778  if (keepMore) {
779  std::vector<Anasazi::Value<ScalarType> > tmpEvals = bks_solver->getRitzValues();
780  for (int vec_i=0; vec_i<sol.numVecs; ++vec_i) {
781  sol.index[vec_i] = tmpIndex[whichVecs[vec_i]];
782  sol.Evals[vec_i] = tmpEvals[whichVecs[vec_i]];
783  }
784  sol.Evecs = MVT::CloneCopy( *(bks_solver->getRitzVectors()), whichVecs );
785  }
786 
787  // Set the solution space to be the Ritz vectors at this time.
788  sol.Espace = sol.Evecs;
789  }
790  }
791 
792  // print final summary
793  bks_solver->currentStatus(printer->stream(FinalSummary));
794 
795  // print timing information
796 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
797  if ( printer->isVerbosity( TimingDetails ) ) {
798  Teuchos::TimeMonitor::summarize( printer->stream( TimingDetails ) );
799  }
800 #endif
801 
802  _problem->setSolution(sol);
803  printer->stream(Debug) << "Returning " << sol.numVecs << " eigenpairs to eigenproblem." << std::endl;
804 
805  // get the number of iterations performed during this solve.
806  _numIters = bks_solver->getNumIters();
807 
808  if (sol.numVecs < nev) {
809  return Unconverged; // return from BlockKrylovSchurSolMgr::solve()
810  }
811  return Converged; // return from BlockKrylovSchurSolMgr::solve()
812 }
813 
814 
815 template <class ScalarType, class MV, class OP>
816 void
818  const Teuchos::RCP< StatusTest<ScalarType,MV,OP> > &global)
819 {
820  globalTest_ = global;
821 }
822 
823 template <class ScalarType, class MV, class OP>
826 {
827  return globalTest_;
828 }
829 
830 template <class ScalarType, class MV, class OP>
831 void
834 {
835  debugTest_ = debug;
836 }
837 
838 template <class ScalarType, class MV, class OP>
841 {
842  return debugTest_;
843 }
844 
845 } // end Anasazi namespace
846 
847 #endif /* ANASAZI_BLOCK_KRYLOV_SCHUR_SOLMGR_HPP */
ScalarType * values() const
Pure virtual base class which describes the basic interface for a solver manager. ...
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > H
The current Hessenberg matrix.
std::vector< Value< ScalarType > > Evals
The computed eigenvalues.
An extension of the MultiVecTraits class that adds a new vector length method.This traits class provi...
A special StatusTest for printing other status tests.
This class defines the interface required by an eigensolver and status test class to compute solution...
static ptrdiff_t GetGlobalLength(const MV &mv)
An implementation of the Anasazi::SortManager that performs a collection of common sorting techniques...
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void GEQRF(const OrdinalType m, const OrdinalType n, ScalarType *A, const OrdinalType lda, ScalarType *TAU, ScalarType *WORK, const OrdinalType lwork, OrdinalType *info) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Virtual base class which defines basic traits for the operator type.
Teuchos::RCP< MV > Evecs
The computed eigenvectors.
ReturnType solve()
This method performs possibly repeated calls to the underlying eigensolver&#39;s iterate() routine until ...
Status test for forming logical combinations of other status tests.
The Anasazi::SolverManager is a templated virtual base class that defines the basic interface that an...
void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &debug)
Set the status test for debugging.
Basic implementation of the Anasazi::SortManager class.
An implementation of the Anasazi::MatOrthoManager that performs orthogonalization using the SVQB iter...
Structure to contain pointers to BlockKrylovSchur state variables.
An exception class parent to all Anasazi exceptions.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
The Anasazi::BlockKrylovSchurSolMgr provides a flexible solver manager over the BlockKrylovSchur eige...
A status test for testing the norm of the eigenvectors residuals along with a set of auxiliary eigenv...
Anasazi&#39;s templated, static class providing utilities for the solvers.
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="")
bool isParameter(const std::string &name) const
int numVecs
The number of computed eigenpairs.
std::vector< Value< ScalarType > > getRitzValues() const
Return the Ritz values from the most recent solve.
void setGlobalStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &global)
Set the status test defining global convergence.
BlockKrylovSchurSolMgr(const Teuchos::RCP< Eigenproblem< ScalarType, MV, OP > > &problem, Teuchos::ParameterList &pl)
Basic constructor for BlockKrylovSchurSolMgr.
Basic output manager for sending information of select verbosity levels to the appropriate output str...
Teuchos::RCP< MV > Espace
An orthonormal basis for the computed eigenspace.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Anasazi&#39;s basic output manager for sending information of select verbosity levels to the appropriate ...
Abstract base class which defines the interface required by an eigensolver and status test class to c...
static magnitudeType prec()
ReturnType
Enumerated type used to pass back information from a solver manager.
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
A status test for testing the norm of the eigenvectors residuals.
Traits class which defines basic operations on multivectors.
std::vector< int > index
An index into Evecs to allow compressed storage of eigenvectors for real, non-Hermitian problems...
const Eigenproblem< ScalarType, MV, OP > & getProblem() const
Return the eigenvalue problem.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
Orthogonalization manager based on the SVQB technique described in &quot;A Block Orthogonalization Procedu...
Struct for storing an eigenproblem solution.
const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > & getGlobalStatusTest() const
Get the status test defining global convergence.
OrdinalType numCols() const
void push_back(const value_type &x)
Teuchos::RCP< const MulVec > V
The current Krylov basis.
Special StatusTest for printing status tests.
A status test for testing the norm of the eigenvectors residuals along with a set of auxiliary eigenv...
Status test for forming logical combinations of other status tests.
An implementation of the Anasazi::MatOrthoManager that performs orthogonalization using (potentially)...
Types and exceptions used within Anasazi solvers and interfaces.
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > Q
The current Schur vectors of the valid part of H.
Implementation of a block Krylov-Schur eigensolver.
This class implements the block Krylov-Schur iteration, for solving linear eigenvalue problems...
int curDim
The current dimension of the reduction.
A pure virtual class for defining the status tests for the Anasazi iterative solvers.
A status test for testing the norm of the eigenvectors residuals.
Basic implementation of the Anasazi::OrthoManager class.
const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > & getDebugStatusTest() const
Get the status test for debugging.
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > S
The current Schur form reduction of the valid part of H.
OrdinalType stride() const
int getNumIters() const
Get the iteration count for the most recent call to solve().
OrdinalType numRows() const
Class which provides internal utilities for the Anasazi solvers.