Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosPseudoBlockGmresIter.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
42 #ifndef BELOS_PSEUDO_BLOCK_GMRES_ITER_HPP
43 #define BELOS_PSEUDO_BLOCK_GMRES_ITER_HPP
44 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosTypes.hpp"
51 #include "BelosIteration.hpp"
52 
53 #include "BelosLinearProblem.hpp"
54 #include "BelosMatOrthoManager.hpp"
55 #include "BelosOutputManager.hpp"
56 #include "BelosStatusTest.hpp"
57 #include "BelosOperatorTraits.hpp"
58 #include "BelosMultiVecTraits.hpp"
59 
60 #include "Teuchos_BLAS.hpp"
63 #include "Teuchos_ScalarTraits.hpp"
65 #include "Teuchos_TimeMonitor.hpp"
66 
80 namespace Belos {
81 
83 
84 
89  template <class ScalarType, class MV>
91 
94 
99  int curDim;
101  std::vector<Teuchos::RCP<const MV> > V;
107  std::vector<Teuchos::RCP<const Teuchos::SerialDenseMatrix<int,ScalarType> > > H;
109  std::vector<Teuchos::RCP<const Teuchos::SerialDenseMatrix<int,ScalarType> > > R;
111  std::vector<Teuchos::RCP<const Teuchos::SerialDenseVector<int,ScalarType> > > Z;
113  std::vector<Teuchos::RCP<const Teuchos::SerialDenseVector<int,ScalarType> > > sn;
114  std::vector<Teuchos::RCP<const Teuchos::SerialDenseVector<int,MagnitudeType> > > cs;
115 
117  H(0), R(0), Z(0),
118  sn(0), cs(0)
119  {}
120  };
121 
123 
124 
138  PseudoBlockGmresIterInitFailure(const std::string& what_arg) : BelosError(what_arg)
139  {}};
140 
148  PseudoBlockGmresIterOrthoFailure(const std::string& what_arg) : BelosError(what_arg)
149  {}};
150 
152 
153 
154  template<class ScalarType, class MV, class OP>
155  class PseudoBlockGmresIter : virtual public Iteration<ScalarType,MV,OP> {
156 
157  public:
158 
159  //
160  // Convenience typedefs
161  //
167 
169 
170 
180  const Teuchos::RCP<OutputManager<ScalarType> > &printer,
183  Teuchos::ParameterList &params );
184 
186  virtual ~PseudoBlockGmresIter() {};
188 
189 
191 
192 
214  void iterate();
215 
238 
242  void initialize()
243  {
245  initialize(empty);
246  }
247 
257  state.curDim = curDim_;
258  state.V.resize(numRHS_);
259  state.H.resize(numRHS_);
260  state.Z.resize(numRHS_);
261  state.sn.resize(numRHS_);
262  state.cs.resize(numRHS_);
263  for (int i=0; i<numRHS_; ++i) {
264  state.V[i] = V_[i];
265  state.H[i] = H_[i];
266  state.Z[i] = Z_[i];
267  state.sn[i] = sn_[i];
268  state.cs[i] = cs_[i];
269  }
270  return state;
271  }
272 
274 
275 
277 
278 
280  int getNumIters() const { return iter_; }
281 
283  void resetNumIters( int iter = 0 ) { iter_ = iter; }
284 
302  Teuchos::RCP<const MV> getNativeResiduals( std::vector<MagnitudeType> *norms ) const;
303 
305 
311 
313 
316  void updateLSQR( int dim = -1 );
317 
319  int getCurSubspaceDim() const {
320  if (!initialized_) return 0;
321  return curDim_;
322  };
323 
325  int getMaxSubspaceDim() const { return numBlocks_; }
326 
328 
329 
331 
332 
334  const LinearProblem<ScalarType,MV,OP>& getProblem() const { return *lp_; }
335 
337  int getBlockSize() const { return 1; }
338 
340  void setBlockSize(int blockSize) {
341  TEUCHOS_TEST_FOR_EXCEPTION(blockSize!=1,std::invalid_argument,
342  "Belos::PseudoBlockGmresIter::setBlockSize(): Cannot use a block size that is not one.");
343  }
344 
346  int getNumBlocks() const { return numBlocks_; }
347 
349  void setNumBlocks(int numBlocks);
350 
352  bool isInitialized() { return initialized_; }
353 
355 
356  private:
357 
358  //
359  // Classes inputed through constructor that define the linear problem to be solved.
360  //
365 
366  //
367  // Algorithmic parameters
368  //
369  // numRHS_ is the current number of linear systems being solved.
370  int numRHS_;
371  // numBlocks_ is the size of the allocated space for the Krylov basis, in blocks.
372  int numBlocks_;
373 
374  // Storage for QR factorization of the least squares system.
375  std::vector<Teuchos::RCP<Teuchos::SerialDenseVector<int,ScalarType> > > sn_;
376  std::vector<Teuchos::RCP<Teuchos::SerialDenseVector<int,MagnitudeType> > > cs_;
377 
378  // Pointers to a work vector used to improve aggregate performance.
379  Teuchos::RCP<MV> U_vec_, AU_vec_;
380 
381  // Pointers to the current right-hand side and solution multivecs being solved for.
382  Teuchos::RCP<MV> cur_block_rhs_, cur_block_sol_;
383 
384  //
385  // Current solver state
386  //
387  // initialized_ specifies that the basis vectors have been initialized and the iterate() routine
388  // is capable of running; _initialize is controlled by the initialize() member method
389  // For the implications of the state of initialized_, please see documentation for initialize()
390  bool initialized_;
391 
392  // Current subspace dimension, and number of iterations performed.
393  int curDim_, iter_;
394 
395  //
396  // State Storage
397  //
398  std::vector<Teuchos::RCP<MV> > V_;
399  //
400  // Projected matrices
401  // H_ : Projected matrix from the Krylov factorization AV = VH + FE^T
402  //
403  std::vector<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > H_;
404  //
405  // QR decomposition of Projected matrices for solving the least squares system HY = B.
406  // R_: Upper triangular reduction of H
407  // Z_: Q applied to right-hand side of the least squares system
408  std::vector<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > R_;
409  std::vector<Teuchos::RCP<Teuchos::SerialDenseVector<int,ScalarType> > > Z_;
410  };
411 
413  // Constructor.
414  template<class ScalarType, class MV, class OP>
416  const Teuchos::RCP<OutputManager<ScalarType> > &printer,
419  Teuchos::ParameterList &params ):
420  lp_(problem),
421  om_(printer),
422  stest_(tester),
423  ortho_(ortho),
424  numRHS_(0),
425  numBlocks_(0),
426  initialized_(false),
427  curDim_(0),
428  iter_(0)
429  {
430  // Get the maximum number of blocks allowed for each Krylov subspace
431  TEUCHOS_TEST_FOR_EXCEPTION(!params.isParameter("Num Blocks"), std::invalid_argument,
432  "Belos::PseudoBlockGmresIter::constructor: mandatory parameter 'Num Blocks' is not specified.");
433  int nb = Teuchos::getParameter<int>(params, "Num Blocks");
434 
435  setNumBlocks( nb );
436  }
437 
439  // Set the block size and make necessary adjustments.
440  template <class ScalarType, class MV, class OP>
442  {
443  // This routine only allocates space; it doesn't not perform any computation
444  // any change in size will invalidate the state of the solver.
445 
446  TEUCHOS_TEST_FOR_EXCEPTION(numBlocks <= 0, std::invalid_argument, "Belos::PseudoBlockGmresIter::setNumBlocks was passed a non-positive argument.");
447 
448  numBlocks_ = numBlocks;
449  curDim_ = 0;
450 
451  initialized_ = false;
452  }
453 
455  // Get the current update from this subspace.
456  template <class ScalarType, class MV, class OP>
458  {
459  //
460  // If this is the first iteration of the Arnoldi factorization,
461  // there is no update, so return Teuchos::null.
462  //
463  Teuchos::RCP<MV> currentUpdate = Teuchos::null;
464  if (curDim_==0) {
465  return currentUpdate;
466  } else {
467  currentUpdate = MVT::Clone(*(V_[0]), numRHS_);
468  std::vector<int> index(1), index2(curDim_);
469  for (int i=0; i<curDim_; ++i) {
470  index2[i] = i;
471  }
472  const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
473  const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
475 
476  for (int i=0; i<numRHS_; ++i) {
477  index[0] = i;
478  Teuchos::RCP<MV> cur_block_copy_vec = MVT::CloneViewNonConst( *currentUpdate, index );
479  //
480  // Make a view and then copy the RHS of the least squares problem. DON'T OVERWRITE IT!
481  //
482  Teuchos::SerialDenseVector<int,ScalarType> y( Teuchos::Copy, Z_[i]->values(), curDim_ );
483  //
484  // Solve the least squares problem and compute current solutions.
485  //
487  Teuchos::NON_UNIT_DIAG, curDim_, 1, one,
488  H_[i]->values(), H_[i]->stride(), y.values(), y.stride() );
489 
490  Teuchos::RCP<const MV> Vjp1 = MVT::CloneView( *V_[i], index2 );
491  MVT::MvTimesMatAddMv( one, *Vjp1, y, zero, *cur_block_copy_vec );
492  }
493  }
494  return currentUpdate;
495  }
496 
497 
499  // Get the native residuals stored in this iteration.
500  // Note: No residual vector will be returned by Gmres.
501  template <class ScalarType, class MV, class OP>
504  getNativeResiduals (std::vector<MagnitudeType> *norms) const
505  {
506  typedef typename Teuchos::ScalarTraits<ScalarType> STS;
507 
508  if (norms)
509  { // Resize the incoming std::vector if necessary. The type
510  // cast avoids the compiler warning resulting from a signed /
511  // unsigned integer comparison.
512  if (static_cast<int> (norms->size()) < numRHS_)
513  norms->resize (numRHS_);
514 
516  for (int j = 0; j < numRHS_; ++j)
517  {
518  const ScalarType curNativeResid = (*Z_[j])(curDim_);
519  (*norms)[j] = STS::magnitude (curNativeResid);
520  }
521  }
522  return Teuchos::null;
523  }
524 
525 
526  template <class ScalarType, class MV, class OP>
527  void
530  {
531  using Teuchos::RCP;
532 
533  // (Re)set the number of right-hand sides, by interrogating the
534  // current LinearProblem to solve.
535  this->numRHS_ = MVT::GetNumberVecs (*(lp_->getCurrLHSVec()));
536 
537  // NOTE: In PseudoBlockGmresIter, V and Z are required!!!
538  // Inconsistent multivectors widths and lengths will not be tolerated, and
539  // will be treated with exceptions.
540  //
541  std::string errstr ("Belos::PseudoBlockGmresIter::initialize(): "
542  "Specified multivectors must have a consistent "
543  "length and width.");
544 
545  // Check that newstate has V and Z arrays with nonzero length.
546  TEUCHOS_TEST_FOR_EXCEPTION((int)newstate.V.size()==0 || (int)newstate.Z.size()==0,
547  std::invalid_argument,
548  "Belos::PseudoBlockGmresIter::initialize(): "
549  "V and/or Z was not specified in the input state; "
550  "the V and/or Z arrays have length zero.");
551 
552  // In order to create basis multivectors, we have to clone them
553  // from some already existing multivector. We require that at
554  // least one of the right-hand side B and left-hand side X in the
555  // LinearProblem be non-null. Thus, we can clone from either B or
556  // X. We prefer to close from B, since B is in the range of the
557  // operator A and the basis vectors should also be in the range of
558  // A (the first basis vector is a scaled residual vector).
559  // However, if B is not given, we will try our best by cloning
560  // from X.
561  RCP<const MV> lhsMV = lp_->getLHS();
562  RCP<const MV> rhsMV = lp_->getRHS();
563 
564  // If the right-hand side is null, we make do with the left-hand
565  // side, otherwise we use the right-hand side.
566  RCP<const MV> vectorInBasisSpace = rhsMV.is_null() ? lhsMV : rhsMV;
567  //RCP<const MV> tmp = ( (rhsMV!=Teuchos::null)? rhsMV: lhsMV );
568 
569  TEUCHOS_TEST_FOR_EXCEPTION(vectorInBasisSpace.is_null(),
570  std::invalid_argument,
571  "Belos::PseudoBlockGmresIter::initialize(): "
572  "The linear problem to solve does not specify multi"
573  "vectors from which we can clone basis vectors. The "
574  "right-hand side(s), left-hand side(s), or both should "
575  "be nonnull.");
576 
577  // Check the new dimension is not more that the maximum number of
578  // allowable blocks.
579  TEUCHOS_TEST_FOR_EXCEPTION(newstate.curDim > numBlocks_+1,
580  std::invalid_argument,
581  errstr);
582  curDim_ = newstate.curDim;
583 
584  // Initialize the state storage. If the subspace has not be
585  // initialized before, generate it using the right-hand side or
586  // left-hand side from the LinearProblem lp_ to solve.
587  V_.resize(numRHS_);
588  for (int i=0; i<numRHS_; ++i) {
589  // Create a new vector if we need to. We "need to" if the
590  // current vector V_[i] is null, or if it doesn't have enough
591  // columns.
592  if (V_[i].is_null() || MVT::GetNumberVecs(*V_[i]) < numBlocks_ + 1) {
593  V_[i] = MVT::Clone (*vectorInBasisSpace, numBlocks_ + 1);
594  }
595  // Check that the newstate vector newstate.V[i] has dimensions
596  // consistent with those of V_[i].
597  TEUCHOS_TEST_FOR_EXCEPTION( MVText::GetGlobalLength(*newstate.V[i]) != MVText::GetGlobalLength(*V_[i]),
598  std::invalid_argument, errstr );
599  TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*newstate.V[i]) < newstate.curDim,
600  std::invalid_argument, errstr );
601  //
602  // If newstate.V[i] and V_[i] are not identically the same
603  // vector, then copy newstate.V[i] into V_[i].
604  //
605  int lclDim = MVT::GetNumberVecs(*newstate.V[i]);
606  if (newstate.V[i] != V_[i]) {
607  // Only copy over the first block and print a warning.
608  if (curDim_ == 0 && lclDim > 1) {
609  om_->stream(Warnings)
610  << "Belos::PseudoBlockGmresIter::initialize(): the solver was "
611  << "initialized with a kernel of " << lclDim
612  << std::endl
613  << "The block size however is only " << 1
614  << std::endl
615  << "The last " << lclDim - 1 << " vectors will be discarded."
616  << std::endl;
617  }
618  std::vector<int> nevind (curDim_ + 1);
619  for (int j = 0; j < curDim_ + 1; ++j)
620  nevind[j] = j;
621 
622  RCP<const MV> newV = MVT::CloneView (*newstate.V[i], nevind);
623  RCP<MV> lclV = MVT::CloneViewNonConst( *V_[i], nevind );
624  const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
625  const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
626  MVT::MvAddMv (one, *newV, zero, *newV, *lclV);
627 
628  // Done with local pointers
629  lclV = Teuchos::null;
630  }
631  }
632 
633 
634  // Check size of Z
635  Z_.resize(numRHS_);
636  for (int i=0; i<numRHS_; ++i) {
637  // Create a vector if we need to.
638  if (Z_[i] == Teuchos::null) {
640  }
641  if (Z_[i]->length() < numBlocks_+1) {
642  Z_[i]->shapeUninitialized(numBlocks_+1, 1);
643  }
644 
645  // Check that the newstate vector is consistent.
646  TEUCHOS_TEST_FOR_EXCEPTION(newstate.Z[i]->numRows() < curDim_, std::invalid_argument, errstr);
647 
648  // Put data into Z_, make sure old information is not still hanging around.
649  if (newstate.Z[i] != Z_[i]) {
650  if (curDim_==0)
651  Z_[i]->putScalar();
652 
653  Teuchos::SerialDenseVector<int,ScalarType> newZ(Teuchos::View,newstate.Z[i]->values(),curDim_+1);
655  lclZ = Teuchos::rcp( new Teuchos::SerialDenseVector<int,ScalarType>(Teuchos::View,Z_[i]->values(),curDim_+1) );
656  lclZ->assign(newZ);
657 
658  // Done with local pointers
659  lclZ = Teuchos::null;
660  }
661  }
662 
663 
664  // Check size of H
665  H_.resize(numRHS_);
666  for (int i=0; i<numRHS_; ++i) {
667  // Create a matrix if we need to.
668  if (H_[i] == Teuchos::null) {
670  }
671  if (H_[i]->numRows() < numBlocks_+1 || H_[i]->numCols() < numBlocks_) {
672  H_[i]->shapeUninitialized(numBlocks_+1, numBlocks_);
673  }
674 
675  // Put data into H_ if it exists, make sure old information is not still hanging around.
676  if ((int)newstate.H.size() == numRHS_) {
677 
678  // Check that the newstate matrix is consistent.
679  TEUCHOS_TEST_FOR_EXCEPTION((newstate.H[i]->numRows() < curDim_ || newstate.H[i]->numCols() < curDim_), std::invalid_argument,
680  "Belos::PseudoBlockGmresIter::initialize(): Specified Hessenberg matrices must have a consistent size to the current subspace dimension");
681 
682  if (newstate.H[i] != H_[i]) {
683  // H_[i]->putScalar();
684 
685  Teuchos::SerialDenseMatrix<int,ScalarType> newH(Teuchos::View,*newstate.H[i],curDim_+1, curDim_);
687  lclH = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>(Teuchos::View,*H_[i],curDim_+1, curDim_) );
688  lclH->assign(newH);
689 
690  // Done with local pointers
691  lclH = Teuchos::null;
692  }
693  }
694  }
695 
697  // Reinitialize storage for least squares solve
698  //
699  cs_.resize(numRHS_);
700  sn_.resize(numRHS_);
701 
702  // Copy over rotation angles if they exist
703  if ((int)newstate.cs.size() == numRHS_ && (int)newstate.sn.size() == numRHS_) {
704  for (int i=0; i<numRHS_; ++i) {
705  if (cs_[i] != newstate.cs[i])
706  cs_[i] = Teuchos::rcp( new Teuchos::SerialDenseVector<int,MagnitudeType>(*newstate.cs[i]) );
707  if (sn_[i] != newstate.sn[i])
708  sn_[i] = Teuchos::rcp( new Teuchos::SerialDenseVector<int,ScalarType>(*newstate.sn[i]) );
709  }
710  }
711 
712  // Resize or create the vectors as necessary
713  for (int i=0; i<numRHS_; ++i) {
714  if (cs_[i] == Teuchos::null)
715  cs_[i] = Teuchos::rcp( new Teuchos::SerialDenseVector<int,MagnitudeType>(numBlocks_+1) );
716  else
717  cs_[i]->resize(numBlocks_+1);
718  if (sn_[i] == Teuchos::null)
719  sn_[i] = Teuchos::rcp( new Teuchos::SerialDenseVector<int,ScalarType>(numBlocks_+1) );
720  else
721  sn_[i]->resize(numBlocks_+1);
722  }
723 
724  // the solver is initialized
725  initialized_ = true;
726 
727  /*
728  if (om_->isVerbosity( Debug ) ) {
729  // Check almost everything here
730  CheckList chk;
731  chk.checkV = true;
732  chk.checkArn = true;
733  chk.checkAux = true;
734  om_->print( Debug, accuracyCheck(chk, ": after initialize()") );
735  }
736  */
737 
738  }
739 
740 
742  // Iterate until the status test informs us we should stop.
743  template <class ScalarType, class MV, class OP>
745  {
746  //
747  // Allocate/initialize data structures
748  //
749  if (initialized_ == false) {
750  initialize();
751  }
752 
753  const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
754  const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
755 
756  // Compute the current search dimension.
757  int searchDim = numBlocks_;
758  //
759  // Associate each initial block of V_[i] with U_vec[i]
760  // Reset the index vector (this might have been changed if there was a restart)
761  //
762  std::vector<int> index(1);
763  std::vector<int> index2(1);
764  index[0] = curDim_;
765  Teuchos::RCP<MV> U_vec = MVT::Clone( *V_[0], numRHS_ );
766 
767  // Create AU_vec to hold A*U_vec.
768  Teuchos::RCP<MV> AU_vec = MVT::Clone( *V_[0], numRHS_ );
769 
770  for (int i=0; i<numRHS_; ++i) {
771  index2[0] = i;
772  Teuchos::RCP<const MV> tmp_vec = MVT::CloneView( *V_[i], index );
773  Teuchos::RCP<MV> U_vec_view = MVT::CloneViewNonConst( *U_vec, index2 );
774  MVT::MvAddMv( one, *tmp_vec, zero, *tmp_vec, *U_vec_view );
775  }
776 
778  // iterate until the status test tells us to stop.
779  //
780  // also break if our basis is full
781  //
782  while (stest_->checkStatus(this) != Passed && curDim_ < searchDim) {
783 
784  iter_++;
785  //
786  // Apply the operator to _work_vector
787  //
788  lp_->apply( *U_vec, *AU_vec );
789  //
790  //
791  // Resize index.
792  //
793  int num_prev = curDim_+1;
794  index.resize( num_prev );
795  for (int i=0; i<num_prev; ++i) {
796  index[i] = i;
797  }
798  //
799  // Orthogonalize next Krylov vector for each right-hand side.
800  //
801  for (int i=0; i<numRHS_; ++i) {
802  //
803  // Get previous Krylov vectors.
804  //
805  Teuchos::RCP<const MV> V_prev = MVT::CloneView( *V_[i], index );
806  Teuchos::Array< Teuchos::RCP<const MV> > V_array( 1, V_prev );
807  //
808  // Get a view of the new candidate std::vector.
809  //
810  index2[0] = i;
811  Teuchos::RCP<MV> V_new = MVT::CloneViewNonConst( *AU_vec, index2 );
812  //
813  // Get a view of the current part of the upper-hessenberg matrix.
814  //
817  ( Teuchos::View, *H_[i], num_prev, 1, 0, curDim_ ) );
819 
822  ( Teuchos::View, *H_[i], 1, 1, num_prev, curDim_ ) );
823  //
824  // Orthonormalize the new block of the Krylov expansion
825  // NOTE: Rank deficiencies are not checked because this is a single-std::vector Krylov method.
826  //
827  ortho_->projectAndNormalize( *V_new, h_array, r_new, V_array );
828  //
829  // NOTE: V_new is a copy of the iter+1 vector in V_[i], so the normalized vector has to be
830  // be copied back in when V_new is changed.
831  //
832  index2[0] = curDim_+1;
833  Teuchos::RCP<MV> tmp_vec = MVT::CloneViewNonConst( *V_[i], index2 );
834  MVT::MvAddMv( one, *V_new, zero, *V_new, *tmp_vec );
835  }
836  //
837  // Now _AU_vec is the new _U_vec, so swap these two vectors.
838  // NOTE: This alleviates the need for allocating a vector for AU_vec each iteration.
839  //
840  Teuchos::RCP<MV> tmp_AU_vec = U_vec;
841  U_vec = AU_vec;
842  AU_vec = tmp_AU_vec;
843  //
844  // V has been extended, and H has been extended.
845  //
846  // Update the QR factorization of the upper Hessenberg matrix
847  //
848  updateLSQR();
849  //
850  // Update basis dim and release all pointers.
851  //
852  curDim_ += 1;
853  //
854  /*
855  // When required, monitor some orthogonalities
856  if (om_->isVerbosity( Debug ) ) {
857  // Check almost everything here
858  CheckList chk;
859  chk.checkV = true;
860  chk.checkArn = true;
861  om_->print( Debug, accuracyCheck(chk, ": after local update") );
862  }
863  else if (om_->isVerbosity( OrthoDetails ) ) {
864  CheckList chk;
865  chk.checkV = true;
866  om_->print( OrthoDetails, accuracyCheck(chk, ": after local update") );
867  }
868  */
869 
870  } // end while (statusTest == false)
871 
872  }
873 
875  // Update the least squares solution for each right-hand side.
876  template<class ScalarType, class MV, class OP>
878  {
879  // Get correct dimension based on input "dim"
880  // Remember that ortho failures result in an exit before updateLSQR() is called.
881  // Therefore, it is possible that dim == curDim_.
882  int curDim = curDim_;
883  if (dim >= curDim_ && dim < getMaxSubspaceDim()) {
884  curDim = dim;
885  }
886 
887  int i, j;
888  const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
889 
891 
892  for (i=0; i<numRHS_; ++i) {
893  //
894  // Update the least-squares QR for each linear system.
895  //
896  // QR factorization of Least-Squares system with Givens rotations
897  //
898  for (j=0; j<curDim; j++) {
899  //
900  // Apply previous Givens rotations to new column of Hessenberg matrix
901  //
902  blas.ROT( 1, &(*H_[i])(j,curDim), 1, &(*H_[i])(j+1, curDim), 1, &(*cs_[i])[j], &(*sn_[i])[j] );
903  }
904  //
905  // Calculate new Givens rotation
906  //
907  blas.ROTG( &(*H_[i])(curDim,curDim), &(*H_[i])(curDim+1,curDim), &(*cs_[i])[curDim], &(*sn_[i])[curDim] );
908  (*H_[i])(curDim+1,curDim) = zero;
909  //
910  // Update RHS w/ new transformation
911  //
912  blas.ROT( 1, &(*Z_[i])(curDim), 1, &(*Z_[i])(curDim+1), 1, &(*cs_[i])[curDim], &(*sn_[i])[curDim] );
913  }
914 
915  } // end updateLSQR()
916 
917 } // end Belos namespace
918 
919 #endif /* BELOS_PSEUDO_BLOCK_GMRES_ITER_HPP */
ScalarType * values() const
std::vector< Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > > H
The current Hessenberg matrix.
int getCurSubspaceDim() const
Get the dimension of the search subspace used to generate the current solution to the linear problem...
Collection of types and exceptions used within the Belos solvers.
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
Class which manages the output and verbosity of the Belos solvers.
bool is_null(const boost::shared_ptr< T > &p)
PseudoBlockGmresIterState< ScalarType, MV > getState() const
Get the current state of the linear solver.
std::vector< Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > > R
The current upper-triangular matrix from the QR reduction of H.
Teuchos::ScalarTraits< ScalarType > SCT
Pure virtual base class for defining the status testing capabilities of Belos.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Declaration of basic traits for the multivector type.
int getNumBlocks() const
Get the maximum number of blocks used by the iterative solver in solving this linear problem...
std::vector< Teuchos::RCP< const MV > > V
The current Krylov basis.
int resize(OrdinalType length_in)
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the &quot;native&quot; residual vectors.
An extension of the MultiVecTraits class that adds a new vector length method.
Pure virtual base class which describes the basic interface to the linear solver iteration.
A pure virtual class for defining the status tests for the Belos iterative solvers.
Class which defines basic traits for the operator type.
int getNumIters() const
Get the current iteration count.
Structure to contain pointers to PseudoBlockGmresIter state variables.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
void initialize()
Initialize the solver with the initial vectors from the linear problem or random data.
bool isInitialized()
States whether the solver has been initialized or not.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
Traits class which defines basic operations on multivectors.
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
bool isParameter(const std::string &name) const
void ROTG(ScalarType *da, ScalarType *db, MagnitudeType *c, ScalarType *s) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void updateLSQR(int dim=-1)
Method for updating QR factorization of upper Hessenberg matrix.
PseudoBlockGmresIter(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &tester, const Teuchos::RCP< MatOrthoManager< ScalarType, MV, OP > > &ortho, Teuchos::ParameterList &params)
PseudoBlockGmresIter constructor with linear problem, solver utilities, and parameter list of solver ...
PseudoBlockGmresIterOrthoFailure(const std::string &what_arg)
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, MagnitudeType > > > cs
MultiVecTraitsExt< ScalarType, MV > MVText
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
void setNumBlocks(int numBlocks)
Set the maximum number of blocks used by the iterative solver.
void ROT(const OrdinalType n, ScalarType *dx, const OrdinalType incx, ScalarType *dy, const OrdinalType incy, MagnitudeType *c, ScalarType *s) const
PseudoBlockGmresIterInitFailure(const std::string &what_arg)
Teuchos::ScalarTraits< ScalarType > SCT
int getMaxSubspaceDim() const
Get the maximum dimension allocated for the search subspace.
void resetNumIters(int iter=0)
Reset the iteration count.
MultiVecTraits< ScalarType, MV > MVT
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, ScalarType > > > Z
The current right-hand side of the least squares system RY = Z.
OperatorTraits< ScalarType, MV, OP > OPT
void iterate()
This method performs block Gmres iterations until the status test indicates the need to stop or an er...
void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType m, const OrdinalType n, const alpha_type alpha, const A_type *A, const OrdinalType lda, ScalarType *B, const OrdinalType ldb) const
Class which defines basic traits for the operator type.
int curDim
The current dimension of the reduction.
Parent class to all Belos exceptions.
Definition: BelosTypes.hpp:60
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, ScalarType > > > sn
The current Given&#39;s rotation coefficients.
Belos&#39;s templated virtual class for providing routines for orthogonalization and orthonormzalition of...
Belos header file which uses auto-configuration information to include necessary C++ headers...
This class implements the pseudo-block GMRES iteration, where a block Krylov subspace is constructed ...
SerialDenseMatrix< OrdinalType, ScalarType > & assign(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
void setBlockSize(int blockSize)
Set the blocksize.
PseudoBlockGmresIterOrthoFailure is thrown when the orthogonalization manager is unable to generate o...
OrdinalType stride() const
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
PseudoBlockGmresIterInitFailure is thrown when the PseudoBlockGmresIter object is unable to generate ...