Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosRCGSolMgr.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_RCG_SOLMGR_HPP
43 #define BELOS_RCG_SOLMGR_HPP
44 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosTypes.hpp"
51 
52 #include "BelosLinearProblem.hpp"
53 #include "BelosSolverManager.hpp"
54 
55 #include "BelosRCGIter.hpp"
61 #include "BelosStatusTestCombo.hpp"
63 #include "BelosOutputManager.hpp"
64 #include "Teuchos_BLAS.hpp"
65 #include "Teuchos_LAPACK.hpp"
66 #include "Teuchos_as.hpp"
67 #ifdef BELOS_TEUCHOS_TIME_MONITOR
68 #include "Teuchos_TimeMonitor.hpp"
69 #endif
70 
80 namespace Belos {
81 
83 
84 
91  class RCGSolMgrLinearProblemFailure : public BelosError {public:
92  RCGSolMgrLinearProblemFailure(const std::string& what_arg) : BelosError(what_arg)
93  {}};
94 
101  class RCGSolMgrLAPACKFailure : public BelosError {public:
102  RCGSolMgrLAPACKFailure(const std::string& what_arg) : BelosError(what_arg)
103  {}};
104 
111  class RCGSolMgrRecyclingFailure : public BelosError {public:
112  RCGSolMgrRecyclingFailure(const std::string& what_arg) : BelosError(what_arg)
113  {}};
114 
116 
117  template<class ScalarType, class MV, class OP>
118  class RCGSolMgr : public SolverManager<ScalarType,MV,OP> {
119 
120  private:
125  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
127 
128  public:
129 
131 
132 
138  RCGSolMgr();
139 
163 
165  virtual ~RCGSolMgr() {};
167 
169 
170 
172  return *problem_;
173  }
174 
177 
180 
187  return Teuchos::tuple(timerSolve_);
188  }
189 
194  MagnitudeType achievedTol() const {
195  return achievedTol_;
196  }
197 
199  int getNumIters() const {
200  return numIters_;
201  }
202 
204  bool isLOADetected() const { return false; }
205 
207 
209 
210 
212  void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) { problem_ = problem; }
213 
216 
218 
220 
221 
227  void reset( const ResetType type ) {
228  if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem();
229  else if (type & Belos::RecycleSubspace) existU_ = false;
230  }
232 
234 
235 
253  ReturnType solve();
254 
256 
259 
261  std::string description() const;
262 
264 
265  private:
266 
267  // Called by all constructors; Contains init instructions common to all constructors
268  void init();
269 
270  // Computes harmonic eigenpairs of projected matrix created during one cycle.
271  // Y contains the harmonic Ritz vectors corresponding to the recycleBlocks eigenvalues of smallest magnitude.
272  void getHarmonicVecs(const Teuchos::SerialDenseMatrix<int,ScalarType> &F,
275 
276  // Sort list of n floating-point numbers and return permutation vector
277  void sort(std::vector<ScalarType>& dlist, int n, std::vector<int>& iperm);
278 
279  // Initialize solver state storage
280  void initializeStateStorage();
281 
282  // Linear problem.
284 
285  // Output manager.
287  Teuchos::RCP<std::ostream> outputStream_;
288 
289  // Status test.
294 
295  // Current parameter list.
297 
298  // Default solver values.
299  static const MagnitudeType convtol_default_;
300  static const int maxIters_default_;
301  static const int blockSize_default_;
302  static const int numBlocks_default_;
303  static const int recycleBlocks_default_;
304  static const bool showMaxResNormOnly_default_;
305  static const int verbosity_default_;
306  static const int outputStyle_default_;
307  static const int outputFreq_default_;
308  static const std::string label_default_;
309  static const Teuchos::RCP<std::ostream> outputStream_default_;
310 
311  //
312  // Current solver values.
313  //
314 
316  MagnitudeType convtol_;
317 
322  MagnitudeType achievedTol_;
323 
325  int maxIters_;
326 
328  int numIters_;
329 
330  int numBlocks_, recycleBlocks_;
331  bool showMaxResNormOnly_;
332  int verbosity_, outputStyle_, outputFreq_;
333 
335  // Solver State Storage
337  // Search vectors
338  Teuchos::RCP<MV> P_;
339  //
340  // A times current search direction
341  Teuchos::RCP<MV> Ap_;
342  //
343  // Residual vector
344  Teuchos::RCP<MV> r_;
345  //
346  // Preconditioned residual
347  Teuchos::RCP<MV> z_;
348  //
349  // Flag indicating that the recycle space should be used
350  bool existU_;
351  //
352  // Flag indicating that the updated recycle space has been created
353  bool existU1_;
354  //
355  // Recycled subspace and its image
356  Teuchos::RCP<MV> U_, AU_;
357  //
358  // Recycled subspace for next system and its image
359  Teuchos::RCP<MV> U1_;
360  //
361  // Coefficients arising in RCG iteration
365  //
366  // Solutions to local least-squares problems
368  //
369  // The matrix U^T A U
371  //
372  // LU factorization of U^T A U
374  //
375  // Data from LU factorization of UTAU
377  //
378  // The matrix (AU)^T AU
380  //
381  // The scalar r'*z
383  //
384  // Matrices needed for calculation of harmonic Ritz eigenproblem
386  //
387  // Matrices needed for updating recycle space
388  Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > L2_,DeltaL2_,AU1TUDeltaL2_;
389  Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > AU1TAU1_, AU1TU1_, AU1TAP_;
392  Teuchos::RCP<MV> U1Y1_, PY2_;
394  ScalarType dold;
396 
397  // Timers.
398  std::string label_;
399  Teuchos::RCP<Teuchos::Time> timerSolve_;
400 
401  // Internal state variables.
402  bool params_Set_;
403  };
404 
405 
406 // Default solver values.
407 template<class ScalarType, class MV, class OP>
408 const typename RCGSolMgr<ScalarType,MV,OP>::MagnitudeType RCGSolMgr<ScalarType,MV,OP>::convtol_default_ = 1e-8;
409 
410 template<class ScalarType, class MV, class OP>
411 const int RCGSolMgr<ScalarType,MV,OP>::maxIters_default_ = 1000;
412 
413 template<class ScalarType, class MV, class OP>
414 const int RCGSolMgr<ScalarType,MV,OP>::numBlocks_default_ = 25;
415 
416 template<class ScalarType, class MV, class OP>
417 const int RCGSolMgr<ScalarType,MV,OP>::blockSize_default_ = 1;
418 
419 template<class ScalarType, class MV, class OP>
420 const int RCGSolMgr<ScalarType,MV,OP>::recycleBlocks_default_ = 3;
421 
422 template<class ScalarType, class MV, class OP>
423 const bool RCGSolMgr<ScalarType,MV,OP>::showMaxResNormOnly_default_ = false;
424 
425 template<class ScalarType, class MV, class OP>
426 const int RCGSolMgr<ScalarType,MV,OP>::verbosity_default_ = Belos::Errors;
427 
428 template<class ScalarType, class MV, class OP>
429 const int RCGSolMgr<ScalarType,MV,OP>::outputStyle_default_ = Belos::General;
430 
431 template<class ScalarType, class MV, class OP>
432 const int RCGSolMgr<ScalarType,MV,OP>::outputFreq_default_ = -1;
433 
434 template<class ScalarType, class MV, class OP>
435 const std::string RCGSolMgr<ScalarType,MV,OP>::label_default_ = "Belos";
436 
437 template<class ScalarType, class MV, class OP>
438 const Teuchos::RCP<std::ostream> RCGSolMgr<ScalarType,MV,OP>::outputStream_default_ = Teuchos::rcp(&std::cout,false);
439 
440 // Empty Constructor
441 template<class ScalarType, class MV, class OP>
443  init();
444 }
445 
446 // Basic Constructor
447 template<class ScalarType, class MV, class OP>
451  problem_(problem)
452 {
453  init();
454  TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument, "Problem not given to solver manager.");
455 
456  // If the parameter list pointer is null, then set the current parameters to the default parameter list.
457  if ( !is_null(pl) ) {
458  setParameters( pl );
459  }
460 }
461 
462 // Common instructions executed in all constructors
463 template<class ScalarType, class MV, class OP>
465 {
466  outputStream_ = outputStream_default_;
467  convtol_ = convtol_default_;
468  maxIters_ = maxIters_default_;
469  numBlocks_ = numBlocks_default_;
470  recycleBlocks_ = recycleBlocks_default_;
471  verbosity_ = verbosity_default_;
472  outputStyle_= outputStyle_default_;
473  outputFreq_= outputFreq_default_;
474  showMaxResNormOnly_ = showMaxResNormOnly_default_;
475  label_ = label_default_;
476  params_Set_ = false;
477  P_ = Teuchos::null;
478  Ap_ = Teuchos::null;
479  r_ = Teuchos::null;
480  z_ = Teuchos::null;
481  existU_ = false;
482  existU1_ = false;
483  U_ = Teuchos::null;
484  AU_ = Teuchos::null;
485  U1_ = Teuchos::null;
486  Alpha_ = Teuchos::null;
487  Beta_ = Teuchos::null;
488  D_ = Teuchos::null;
489  Delta_ = Teuchos::null;
490  UTAU_ = Teuchos::null;
491  LUUTAU_ = Teuchos::null;
492  ipiv_ = Teuchos::null;
493  AUTAU_ = Teuchos::null;
494  rTz_old_ = Teuchos::null;
495  F_ = Teuchos::null;
496  G_ = Teuchos::null;
497  Y_ = Teuchos::null;
498  L2_ = Teuchos::null;
499  DeltaL2_ = Teuchos::null;
500  AU1TUDeltaL2_ = Teuchos::null;
501  AU1TAU1_ = Teuchos::null;
502  AU1TU1_ = Teuchos::null;
503  AU1TAP_ = Teuchos::null;
504  FY_ = Teuchos::null;
505  GY_ = Teuchos::null;
506  APTAP_ = Teuchos::null;
507  U1Y1_ = Teuchos::null;
508  PY2_ = Teuchos::null;
509  AUTAP_ = Teuchos::null;
510  AU1TU_ = Teuchos::null;
511  dold = 0.;
512 }
513 
514 template<class ScalarType, class MV, class OP>
516 {
517  // Create the internal parameter list if ones doesn't already exist.
518  if (params_ == Teuchos::null) {
519  params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) );
520  }
521  else {
522  params->validateParameters(*getValidParameters());
523  }
524 
525  // Check for maximum number of iterations
526  if (params->isParameter("Maximum Iterations")) {
527  maxIters_ = params->get("Maximum Iterations",maxIters_default_);
528 
529  // Update parameter in our list and in status test.
530  params_->set("Maximum Iterations", maxIters_);
531  if (maxIterTest_!=Teuchos::null)
532  maxIterTest_->setMaxIters( maxIters_ );
533  }
534 
535  // Check for the maximum number of blocks.
536  if (params->isParameter("Num Blocks")) {
537  numBlocks_ = params->get("Num Blocks",numBlocks_default_);
538  TEUCHOS_TEST_FOR_EXCEPTION(numBlocks_ <= 0, std::invalid_argument,
539  "Belos::RCGSolMgr: \"Num Blocks\" must be strictly positive.");
540 
541  // Update parameter in our list.
542  params_->set("Num Blocks", numBlocks_);
543  }
544 
545  // Check for the maximum number of blocks.
546  if (params->isParameter("Num Recycled Blocks")) {
547  recycleBlocks_ = params->get("Num Recycled Blocks",recycleBlocks_default_);
548  TEUCHOS_TEST_FOR_EXCEPTION(recycleBlocks_ <= 0, std::invalid_argument,
549  "Belos::RCGSolMgr: \"Num Recycled Blocks\" must be strictly positive.");
550 
551  TEUCHOS_TEST_FOR_EXCEPTION(recycleBlocks_ >= numBlocks_, std::invalid_argument,
552  "Belos::RCGSolMgr: \"Num Recycled Blocks\" must be less than \"Num Blocks\".");
553 
554  // Update parameter in our list.
555  params_->set("Num Recycled Blocks", recycleBlocks_);
556  }
557 
558  // Check to see if the timer label changed.
559  if (params->isParameter("Timer Label")) {
560  std::string tempLabel = params->get("Timer Label", label_default_);
561 
562  // Update parameter in our list and solver timer
563  if (tempLabel != label_) {
564  label_ = tempLabel;
565  params_->set("Timer Label", label_);
566  std::string solveLabel = label_ + ": RCGSolMgr total solve time";
567 #ifdef BELOS_TEUCHOS_TIME_MONITOR
568  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
569 #endif
570  }
571  }
572 
573  // Check for a change in verbosity level
574  if (params->isParameter("Verbosity")) {
575  if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
576  verbosity_ = params->get("Verbosity", verbosity_default_);
577  } else {
578  verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
579  }
580 
581  // Update parameter in our list.
582  params_->set("Verbosity", verbosity_);
583  if (printer_ != Teuchos::null)
584  printer_->setVerbosity(verbosity_);
585  }
586 
587  // Check for a change in output style
588  if (params->isParameter("Output Style")) {
589  if (Teuchos::isParameterType<int>(*params,"Output Style")) {
590  outputStyle_ = params->get("Output Style", outputStyle_default_);
591  } else {
592  outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
593  }
594 
595  // Reconstruct the convergence test if the explicit residual test is not being used.
596  params_->set("Output Style", outputStyle_);
597  outputTest_ = Teuchos::null;
598  }
599 
600  // output stream
601  if (params->isParameter("Output Stream")) {
602  outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
603 
604  // Update parameter in our list.
605  params_->set("Output Stream", outputStream_);
606  if (printer_ != Teuchos::null)
607  printer_->setOStream( outputStream_ );
608  }
609 
610  // frequency level
611  if (verbosity_ & Belos::StatusTestDetails) {
612  if (params->isParameter("Output Frequency")) {
613  outputFreq_ = params->get("Output Frequency", outputFreq_default_);
614  }
615 
616  // Update parameter in out list and output status test.
617  params_->set("Output Frequency", outputFreq_);
618  if (outputTest_ != Teuchos::null)
619  outputTest_->setOutputFrequency( outputFreq_ );
620  }
621 
622  // Create output manager if we need to.
623  if (printer_ == Teuchos::null) {
624  printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
625  }
626 
627  // Convergence
628  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
629  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestResNorm_t;
630 
631  // Check for convergence tolerance
632  if (params->isParameter("Convergence Tolerance")) {
633  convtol_ = params->get("Convergence Tolerance",convtol_default_);
634 
635  // Update parameter in our list and residual tests.
636  params_->set("Convergence Tolerance", convtol_);
637  if (convTest_ != Teuchos::null)
638  convTest_->setTolerance( convtol_ );
639  }
640 
641  if (params->isParameter("Show Maximum Residual Norm Only")) {
642  showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
643 
644  // Update parameter in our list and residual tests
645  params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
646  if (convTest_ != Teuchos::null)
647  convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
648  }
649 
650  // Create status tests if we need to.
651 
652  // Basic test checks maximum iterations and native residual.
653  if (maxIterTest_ == Teuchos::null)
654  maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
655 
656  // Implicit residual test, using the native residual to determine if convergence was achieved.
657  if (convTest_ == Teuchos::null)
658  convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, 1 ) );
659 
660  if (sTest_ == Teuchos::null)
661  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
662 
663  if (outputTest_ == Teuchos::null) {
664 
665  // Create the status test output class.
666  // This class manages and formats the output from the status test.
667  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
668  outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
669 
670  // Set the solver string for the output test
671  std::string solverDesc = " Recycling CG ";
672  outputTest_->setSolverDesc( solverDesc );
673  }
674 
675  // Create the timer if we need to.
676  if (timerSolve_ == Teuchos::null) {
677  std::string solveLabel = label_ + ": RCGSolMgr total solve time";
678 #ifdef BELOS_TEUCHOS_TIME_MONITOR
679  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
680 #endif
681  }
682 
683  // Inform the solver manager that the current parameters were set.
684  params_Set_ = true;
685 }
686 
687 
688 template<class ScalarType, class MV, class OP>
691 {
693 
694  // Set all the valid parameters and their default values.
695  if(is_null(validPL)) {
696  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
697  pl->set("Convergence Tolerance", convtol_default_,
698  "The relative residual tolerance that needs to be achieved by the\n"
699  "iterative solver in order for the linear system to be declared converged.");
700  pl->set("Maximum Iterations", maxIters_default_,
701  "The maximum number of block iterations allowed for each\n"
702  "set of RHS solved.");
703  pl->set("Block Size", blockSize_default_,
704  "Block Size Parameter -- currently must be 1 for RCG");
705  pl->set("Num Blocks", numBlocks_default_,
706  "The length of a cycle (and this max number of search vectors kept)\n");
707  pl->set("Num Recycled Blocks", recycleBlocks_default_,
708  "The number of vectors in the recycle subspace.");
709  pl->set("Verbosity", verbosity_default_,
710  "What type(s) of solver information should be outputted\n"
711  "to the output stream.");
712  pl->set("Output Style", outputStyle_default_,
713  "What style is used for the solver information outputted\n"
714  "to the output stream.");
715  pl->set("Output Frequency", outputFreq_default_,
716  "How often convergence information should be outputted\n"
717  "to the output stream.");
718  pl->set("Output Stream", outputStream_default_,
719  "A reference-counted pointer to the output stream where all\n"
720  "solver output is sent.");
721  pl->set("Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
722  "When convergence information is printed, only show the maximum\n"
723  "relative residual norm when the block size is greater than one.");
724  pl->set("Timer Label", label_default_,
725  "The string to use as a prefix for the timer labels.");
726  // pl->set("Restart Timers", restartTimers_);
727  validPL = pl;
728  }
729  return validPL;
730 }
731 
732 // initializeStateStorage
733 template<class ScalarType, class MV, class OP>
735 
736  // Check if there is any multivector to clone from.
737  Teuchos::RCP<const MV> rhsMV = problem_->getRHS();
738  if (rhsMV == Teuchos::null) {
739  // Nothing to do
740  return;
741  }
742  else {
743 
744  // Initialize the state storage
745  TEUCHOS_TEST_FOR_EXCEPTION(static_cast<ptrdiff_t>(numBlocks_) > MVText::GetGlobalLength(*rhsMV),std::invalid_argument,
746  "Belos::RCGSolMgr::initializeStateStorage(): Cannot generate a Krylov basis with dimension larger the operator!");
747 
748  // If the subspace has not been initialized before, generate it using the RHS from lp_.
749  if (P_ == Teuchos::null) {
750  P_ = MVT::Clone( *rhsMV, numBlocks_+2 );
751  }
752  else {
753  // Generate P_ by cloning itself ONLY if more space is needed.
754  if (MVT::GetNumberVecs(*P_) < numBlocks_+2) {
755  Teuchos::RCP<const MV> tmp = P_;
756  P_ = MVT::Clone( *tmp, numBlocks_+2 );
757  }
758  }
759 
760  // Generate Ap_ only if it doesn't exist
761  if (Ap_ == Teuchos::null)
762  Ap_ = MVT::Clone( *rhsMV, 1 );
763 
764  // Generate r_ only if it doesn't exist
765  if (r_ == Teuchos::null)
766  r_ = MVT::Clone( *rhsMV, 1 );
767 
768  // Generate z_ only if it doesn't exist
769  if (z_ == Teuchos::null)
770  z_ = MVT::Clone( *rhsMV, 1 );
771 
772  // If the recycle space has not been initialized before, generate it using the RHS from lp_.
773  if (U_ == Teuchos::null) {
774  U_ = MVT::Clone( *rhsMV, recycleBlocks_ );
775  }
776  else {
777  // Generate U_ by cloning itself ONLY if more space is needed.
778  if (MVT::GetNumberVecs(*U_) < recycleBlocks_) {
779  Teuchos::RCP<const MV> tmp = U_;
780  U_ = MVT::Clone( *tmp, recycleBlocks_ );
781  }
782  }
783 
784  // If the recycle space has not be initialized before, generate it using the RHS from lp_.
785  if (AU_ == Teuchos::null) {
786  AU_ = MVT::Clone( *rhsMV, recycleBlocks_ );
787  }
788  else {
789  // Generate AU_ by cloning itself ONLY if more space is needed.
790  if (MVT::GetNumberVecs(*AU_) < recycleBlocks_) {
791  Teuchos::RCP<const MV> tmp = AU_;
792  AU_ = MVT::Clone( *tmp, recycleBlocks_ );
793  }
794  }
795 
796  // If the recycle space has not been initialized before, generate it using the RHS from lp_.
797  if (U1_ == Teuchos::null) {
798  U1_ = MVT::Clone( *rhsMV, recycleBlocks_ );
799  }
800  else {
801  // Generate U1_ by cloning itself ONLY if more space is needed.
802  if (MVT::GetNumberVecs(*U1_) < recycleBlocks_) {
803  Teuchos::RCP<const MV> tmp = U1_;
804  U1_ = MVT::Clone( *tmp, recycleBlocks_ );
805  }
806  }
807 
808  // Generate Alpha_ only if it doesn't exist, otherwise resize it.
809  if (Alpha_ == Teuchos::null)
810  Alpha_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_, 1 ) );
811  else {
812  if ( (Alpha_->numRows() != numBlocks_) || (Alpha_->numCols() != 1) )
813  Alpha_->reshape( numBlocks_, 1 );
814  }
815 
816  // Generate Beta_ only if it doesn't exist, otherwise resize it.
817  if (Beta_ == Teuchos::null)
818  Beta_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_ + 1, 1 ) );
819  else {
820  if ( (Beta_->numRows() != (numBlocks_+1)) || (Beta_->numCols() != 1) )
821  Beta_->reshape( numBlocks_ + 1, 1 );
822  }
823 
824  // Generate D_ only if it doesn't exist, otherwise resize it.
825  if (D_ == Teuchos::null)
826  D_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_ , 1 ) );
827  else {
828  if ( (D_->numRows() != numBlocks_) || (D_->numCols() != 1) )
829  D_->reshape( numBlocks_, 1 );
830  }
831 
832  // Generate Delta_ only if it doesn't exist, otherwise resize it.
833  if (Delta_ == Teuchos::null)
834  Delta_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, numBlocks_ + 1 ) );
835  else {
836  if ( (Delta_->numRows() != recycleBlocks_) || (Delta_->numCols() != (numBlocks_ + 1)) )
837  Delta_->reshape( recycleBlocks_, numBlocks_ + 1 );
838  }
839 
840  // Generate UTAU_ only if it doesn't exist, otherwise resize it.
841  if (UTAU_ == Teuchos::null)
842  UTAU_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
843  else {
844  if ( (UTAU_->numRows() != recycleBlocks_) || (UTAU_->numCols() != recycleBlocks_) )
845  UTAU_->reshape( recycleBlocks_, recycleBlocks_ );
846  }
847 
848  // Generate LUUTAU_ only if it doesn't exist, otherwise resize it.
849  if (LUUTAU_ == Teuchos::null)
850  LUUTAU_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
851  else {
852  if ( (LUUTAU_->numRows() != recycleBlocks_) || (LUUTAU_->numCols() != recycleBlocks_) )
853  LUUTAU_->reshape( recycleBlocks_, recycleBlocks_ );
854  }
855 
856  // Generate ipiv_ only if it doesn't exist, otherwise resize it.
857  if (ipiv_ == Teuchos::null)
858  ipiv_ = Teuchos::rcp( new std::vector<int>(recycleBlocks_) );
859  else {
860  if ( (int)ipiv_->size() != recycleBlocks_ ) // if ipiv not correct size, always resize it
861  ipiv_->resize(recycleBlocks_);
862  }
863 
864  // Generate AUTAU_ only if it doesn't exist, otherwise resize it.
865  if (AUTAU_ == Teuchos::null)
866  AUTAU_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
867  else {
868  if ( (AUTAU_->numRows() != recycleBlocks_) || (AUTAU_->numCols() != recycleBlocks_) )
869  AUTAU_->reshape( recycleBlocks_, recycleBlocks_ );
870  }
871 
872  // Generate rTz_old_ only if it doesn't exist
873  if (rTz_old_ == Teuchos::null)
875  else {
876  if ( (rTz_old_->numRows() != 1) || (rTz_old_->numCols() != 1) )
877  rTz_old_->reshape( 1, 1 );
878  }
879 
880  // Generate F_ only if it doesn't exist
881  if (F_ == Teuchos::null)
882  F_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ ) );
883  else {
884  if ( (F_->numRows() != (numBlocks_+recycleBlocks_)) || (F_->numCols() != numBlocks_+recycleBlocks_) )
885  F_->reshape( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ );
886  }
887 
888  // Generate G_ only if it doesn't exist
889  if (G_ == Teuchos::null)
890  G_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ ) );
891  else {
892  if ( (G_->numRows() != (numBlocks_+recycleBlocks_)) || (G_->numCols() != numBlocks_+recycleBlocks_) )
893  G_->reshape( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ );
894  }
895 
896  // Generate Y_ only if it doesn't exist
897  if (Y_ == Teuchos::null)
898  Y_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_+recycleBlocks_, recycleBlocks_ ) );
899  else {
900  if ( (Y_->numRows() != (numBlocks_+recycleBlocks_)) || (Y_->numCols() != numBlocks_+recycleBlocks_) )
901  Y_->reshape( numBlocks_+recycleBlocks_, numBlocks_+recycleBlocks_ );
902  }
903 
904  // Generate L2_ only if it doesn't exist
905  if (L2_ == Teuchos::null)
906  L2_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_+1, numBlocks_ ) );
907  else {
908  if ( (L2_->numRows() != (numBlocks_+1)) || (L2_->numCols() != numBlocks_) )
909  L2_->reshape( numBlocks_+1, numBlocks_ );
910  }
911 
912  // Generate DeltaL2_ only if it doesn't exist
913  if (DeltaL2_ == Teuchos::null)
914  DeltaL2_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, numBlocks_ ) );
915  else {
916  if ( (DeltaL2_->numRows() != (recycleBlocks_)) || (DeltaL2_->numCols() != (numBlocks_) ) )
917  DeltaL2_->reshape( recycleBlocks_, numBlocks_ );
918  }
919 
920  // Generate AU1TUDeltaL2_ only if it doesn't exist
921  if (AU1TUDeltaL2_ == Teuchos::null)
922  AU1TUDeltaL2_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, numBlocks_ ) );
923  else {
924  if ( (AU1TUDeltaL2_->numRows() != (recycleBlocks_)) || (AU1TUDeltaL2_->numCols() != (numBlocks_) ) )
925  AU1TUDeltaL2_->reshape( recycleBlocks_, numBlocks_ );
926  }
927 
928  // Generate AU1TAU1_ only if it doesn't exist
929  if (AU1TAU1_ == Teuchos::null)
930  AU1TAU1_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
931  else {
932  if ( (AU1TAU1_->numRows() != (recycleBlocks_)) || (AU1TAU1_->numCols() != (recycleBlocks_) ) )
933  AU1TAU1_->reshape( recycleBlocks_, recycleBlocks_ );
934  }
935 
936  // Generate GY_ only if it doesn't exist
937  if (GY_ == Teuchos::null)
938  GY_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_ + recycleBlocks_, recycleBlocks_ ) );
939  else {
940  if ( (GY_->numRows() != (numBlocks_ + recycleBlocks_)) || (GY_->numCols() != (recycleBlocks_) ) )
941  GY_->reshape( numBlocks_+recycleBlocks_, recycleBlocks_ );
942  }
943 
944  // Generate AU1TU1_ only if it doesn't exist
945  if (AU1TU1_ == Teuchos::null)
946  AU1TU1_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
947  else {
948  if ( (AU1TU1_->numRows() != (recycleBlocks_)) || (AU1TU1_->numCols() != (recycleBlocks_) ) )
949  AU1TU1_->reshape( recycleBlocks_, recycleBlocks_ );
950  }
951 
952  // Generate FY_ only if it doesn't exist
953  if (FY_ == Teuchos::null)
954  FY_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_ + recycleBlocks_, recycleBlocks_ ) );
955  else {
956  if ( (FY_->numRows() != (numBlocks_ + recycleBlocks_)) || (FY_->numCols() != (recycleBlocks_) ) )
957  FY_->reshape( numBlocks_+recycleBlocks_, recycleBlocks_ );
958  }
959 
960  // Generate AU1TAP_ only if it doesn't exist
961  if (AU1TAP_ == Teuchos::null)
962  AU1TAP_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, numBlocks_ ) );
963  else {
964  if ( (AU1TAP_->numRows() != (recycleBlocks_)) || (AU1TAP_->numCols() != (numBlocks_) ) )
965  AU1TAP_->reshape( recycleBlocks_, numBlocks_ );
966  }
967 
968  // Generate APTAP_ only if it doesn't exist
969  if (APTAP_ == Teuchos::null)
970  APTAP_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( numBlocks_, numBlocks_ ) );
971  else {
972  if ( (APTAP_->numRows() != (numBlocks_)) || (APTAP_->numCols() != (numBlocks_) ) )
973  APTAP_->reshape( numBlocks_, numBlocks_ );
974  }
975 
976  // If the subspace has not been initialized before, generate it using the RHS from lp_.
977  if (U1Y1_ == Teuchos::null) {
978  U1Y1_ = MVT::Clone( *rhsMV, recycleBlocks_ );
979  }
980  else {
981  // Generate U1Y1_ by cloning itself ONLY if more space is needed.
982  if (MVT::GetNumberVecs(*U1Y1_) < recycleBlocks_) {
983  Teuchos::RCP<const MV> tmp = U1Y1_;
984  U1Y1_ = MVT::Clone( *tmp, recycleBlocks_ );
985  }
986  }
987 
988  // If the subspace has not been initialized before, generate it using the RHS from lp_.
989  if (PY2_ == Teuchos::null) {
990  PY2_ = MVT::Clone( *rhsMV, recycleBlocks_ );
991  }
992  else {
993  // Generate PY2_ by cloning itself ONLY if more space is needed.
994  if (MVT::GetNumberVecs(*PY2_) < recycleBlocks_) {
995  Teuchos::RCP<const MV> tmp = PY2_;
996  PY2_ = MVT::Clone( *tmp, recycleBlocks_ );
997  }
998  }
999 
1000  // Generate AUTAP_ only if it doesn't exist
1001  if (AUTAP_ == Teuchos::null)
1002  AUTAP_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, numBlocks_ ) );
1003  else {
1004  if ( (AUTAP_->numRows() != (recycleBlocks_)) || (AUTAP_->numCols() != (numBlocks_) ) )
1005  AUTAP_->reshape( recycleBlocks_, numBlocks_ );
1006  }
1007 
1008  // Generate AU1TU_ only if it doesn't exist
1009  if (AU1TU_ == Teuchos::null)
1010  AU1TU_ = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( recycleBlocks_, recycleBlocks_ ) );
1011  else {
1012  if ( (AU1TU_->numRows() != (recycleBlocks_)) || (AU1TU_->numCols() != (recycleBlocks_) ) )
1013  AU1TU_->reshape( recycleBlocks_, recycleBlocks_ );
1014  }
1015 
1016 
1017  }
1018 }
1019 
1020 template<class ScalarType, class MV, class OP>
1022 
1024  std::vector<int> index(recycleBlocks_);
1025  ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
1026  ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
1027 
1028  // Count of number of cycles performed on current rhs
1029  int cycle = 0;
1030 
1031  // Set the current parameters if they were not set before.
1032  // NOTE: This may occur if the user generated the solver manager with the default constructor and
1033  // then didn't set any parameters using setParameters().
1034  if (!params_Set_) {
1035  setParameters(Teuchos::parameterList(*getValidParameters()));
1036  }
1037 
1039  "Belos::RCGSolMgr::solve(): Linear problem is not a valid object.");
1041  "Belos::RCGSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
1042  TEUCHOS_TEST_FOR_EXCEPTION((problem_->getLeftPrec() != Teuchos::null)&&(problem_->getRightPrec() != Teuchos::null),
1044  "Belos::RCGSolMgr::solve(): RCG does not support split preconditioning, only set left or right preconditioner.");
1045 
1046  // Grab the preconditioning object
1047  Teuchos::RCP<OP> precObj;
1048  if (problem_->getLeftPrec() != Teuchos::null) {
1049  precObj = Teuchos::rcp_const_cast<OP>(problem_->getLeftPrec());
1050  }
1051  else if (problem_->getRightPrec() != Teuchos::null) {
1052  precObj = Teuchos::rcp_const_cast<OP>(problem_->getRightPrec());
1053  }
1054 
1055  // Create indices for the linear systems to be solved.
1056  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
1057  std::vector<int> currIdx(1);
1058  currIdx[0] = 0;
1059 
1060  // Inform the linear problem of the current linear system to solve.
1061  problem_->setLSIndex( currIdx );
1062 
1063  // Check the number of blocks and change them if necessary.
1064  ptrdiff_t dim = MVText::GetGlobalLength( *(problem_->getRHS()) );
1065  if (numBlocks_ > dim) {
1066  numBlocks_ = Teuchos::asSafe<int>(dim);
1067  params_->set("Num Blocks", numBlocks_);
1068  printer_->stream(Warnings) <<
1069  "Warning! Requested Krylov subspace dimension is larger than operator dimension!" << std::endl <<
1070  " The maximum number of blocks allowed for the Krylov subspace will be adjusted to " << numBlocks_ << std::endl;
1071  }
1072 
1073  // Initialize storage for all state variables
1074  initializeStateStorage();
1075 
1076  // Parameter list
1077  Teuchos::ParameterList plist;
1078  plist.set("Num Blocks",numBlocks_);
1079  plist.set("Recycled Blocks",recycleBlocks_);
1080 
1081  // Reset the status test.
1082  outputTest_->reset();
1083 
1084  // Assume convergence is achieved, then let any failed convergence set this to false.
1085  bool isConverged = true;
1086 
1087  // Compute AU = A*U, UTAU = U'*AU, AUTAU = (AU)'*(AU)
1088  if (existU_) {
1089  index.resize(recycleBlocks_);
1090  for (int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1091  Teuchos::RCP<const MV> Utmp = MVT::CloneView( *U_, index );
1092  index.resize(recycleBlocks_);
1093  for (int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1094  Teuchos::RCP<MV> AUtmp = MVT::CloneViewNonConst( *AU_, index );
1095  // Initialize AU
1096  problem_->applyOp( *Utmp, *AUtmp );
1097  // Initialize UTAU
1098  Teuchos::SerialDenseMatrix<int,ScalarType> UTAUtmp( Teuchos::View, *UTAU_, recycleBlocks_, recycleBlocks_ );
1099  MVT::MvTransMv( one, *Utmp, *AUtmp, UTAUtmp );
1100  // Initialize AUTAU ( AUTAU = AU'*(M\AU) )
1101  Teuchos::SerialDenseMatrix<int,ScalarType> AUTAUtmp( Teuchos::View, *AUTAU_, recycleBlocks_, recycleBlocks_ );
1102  if ( precObj != Teuchos::null ) {
1103  index.resize(recycleBlocks_);
1104  for (int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1105  index.resize(recycleBlocks_);
1106  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1107  Teuchos::RCP<MV> PCAU = MVT::CloneViewNonConst( *U1_, index ); // use U1 as temp storage
1108  OPT::Apply( *precObj, *AUtmp, *PCAU );
1109  MVT::MvTransMv( one, *AUtmp, *PCAU, AUTAUtmp );
1110  } else {
1111  MVT::MvTransMv( one, *AUtmp, *AUtmp, AUTAUtmp );
1112  }
1113  }
1114 
1116  // RCG solver
1117 
1119  rcg_iter = Teuchos::rcp( new RCGIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,plist) );
1120 
1121  // Enter solve() iterations
1122  {
1123 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1124  Teuchos::TimeMonitor slvtimer(*timerSolve_);
1125 #endif
1126 
1127  while ( numRHS2Solve > 0 ) {
1128 
1129  // Debugging output to tell use if recycle space exists and will be used
1130  if (printer_->isVerbosity( Debug ) ) {
1131  if (existU_) printer_->print( Debug, "Using recycle space generated from previous call to solve()." );
1132  else printer_->print( Debug, "No recycle space exists." );
1133  }
1134 
1135  // Reset the number of iterations.
1136  rcg_iter->resetNumIters();
1137 
1138  // Set the current number of recycle blocks and subspace dimension with the RCG iteration.
1139  rcg_iter->setSize( recycleBlocks_, numBlocks_ );
1140 
1141  // Reset the number of calls that the status test output knows about.
1142  outputTest_->resetNumCalls();
1143 
1144  // indicate that updated recycle space has not yet been generated for this linear system
1145  existU1_ = false;
1146 
1147  // reset cycle count
1148  cycle = 0;
1149 
1150  // Get the current residual
1151  problem_->computeCurrResVec( &*r_ );
1152 
1153  // If U exists, find best soln over this space first
1154  if (existU_) {
1155  // Solve linear system UTAU * y = (U'*r)
1156  Teuchos::SerialDenseMatrix<int,ScalarType> Utr(recycleBlocks_,1);
1157  index.resize(recycleBlocks_);
1158  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1159  Teuchos::RCP<const MV> Utmp = MVT::CloneView( *U_, index );
1160  MVT::MvTransMv( one, *Utmp, *r_, Utr );
1161  Teuchos::SerialDenseMatrix<int,ScalarType> UTAUtmp( Teuchos::View, *UTAU_, recycleBlocks_, recycleBlocks_ );
1162  Teuchos::SerialDenseMatrix<int,ScalarType> LUUTAUtmp( Teuchos::View, *LUUTAU_, recycleBlocks_, recycleBlocks_ );
1163  LUUTAUtmp.assign(UTAUtmp);
1164  int info = 0;
1165  lapack.GESV(recycleBlocks_, 1, LUUTAUtmp.values(), LUUTAUtmp.stride(), &(*ipiv_)[0], Utr.values(), Utr.stride(), &info);
1166  TEUCHOS_TEST_FOR_EXCEPTION(info != 0, RCGSolMgrLAPACKFailure,
1167  "Belos::RCGSolMgr::solve(): LAPACK GESV failed to compute a solution.");
1168 
1169  // Update solution (x = x + U*y)
1170  MVT::MvTimesMatAddMv( one, *Utmp, Utr, one, *problem_->getCurrLHSVec() );
1171 
1172  // Update residual ( r = r - AU*y )
1173  index.resize(recycleBlocks_);
1174  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1175  Teuchos::RCP<const MV> AUtmp = MVT::CloneView( *AU_, index );
1176  MVT::MvTimesMatAddMv( -one, *AUtmp, Utr, one, *r_ );
1177  }
1178 
1179  if ( precObj != Teuchos::null ) {
1180  OPT::Apply( *precObj, *r_, *z_ );
1181  } else {
1182  z_ = r_;
1183  }
1184 
1185  // rTz_old = r'*z
1186  MVT::MvTransMv( one, *r_, *z_, *rTz_old_ );
1187 
1188  if ( existU_ ) {
1189  // mu = UTAU\(AU'*z);
1190  Teuchos::SerialDenseMatrix<int,ScalarType> mu( Teuchos::View, *Delta_, recycleBlocks_, 1);
1191  index.resize(recycleBlocks_);
1192  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1193  Teuchos::RCP<const MV> AUtmp = MVT::CloneView( *AU_, index );
1194  MVT::MvTransMv( one, *AUtmp, *z_, mu );
1195  Teuchos::SerialDenseMatrix<int,ScalarType> LUUTAUtmp( Teuchos::View, *LUUTAU_, recycleBlocks_, recycleBlocks_ );
1196  char TRANS = 'N';
1197  int info;
1198  lapack.GETRS( TRANS, recycleBlocks_, 1, LUUTAUtmp.values(), LUUTAUtmp.stride(), &(*ipiv_)[0], mu.values(), mu.stride(), &info );
1199  TEUCHOS_TEST_FOR_EXCEPTION(info != 0, RCGSolMgrLAPACKFailure,
1200  "Belos::RCGSolMgr::solve(): LAPACK GETRS failed to compute a solution.");
1201  // p = z - U*mu;
1202  index.resize( 1 );
1203  index[0] = 0;
1204  Teuchos::RCP<MV> Ptmp = MVT::CloneViewNonConst( *P_, index );
1205  MVT::MvAddMv(one,*z_,zero,*z_,*Ptmp);
1206  MVT::MvTimesMatAddMv( -one, *U_, mu, one, *Ptmp );
1207  } else {
1208  // p = z;
1209  index.resize( 1 );
1210  index[0] = 0;
1211  Teuchos::RCP<MV> Ptmp = MVT::CloneViewNonConst( *P_, index );
1212  MVT::MvAddMv(one,*z_,zero,*z_,*Ptmp);
1213  }
1214 
1215  // Set the new state and initialize the solver.
1216  RCGIterState<ScalarType,MV> newstate;
1217 
1218  // Create RCP views here
1219  index.resize( numBlocks_+1 );
1220  for (int ii=0; ii<(numBlocks_+1); ++ii) { index[ii] = ii; }
1221  newstate.P = MVT::CloneViewNonConst( *P_, index );
1222  index.resize( recycleBlocks_ );
1223  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1224  newstate.U = MVT::CloneViewNonConst( *U_, index );
1225  index.resize( recycleBlocks_ );
1226  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1227  newstate.AU = MVT::CloneViewNonConst( *AU_, index );
1228  newstate.Alpha = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *Alpha_, numBlocks_, 1 ) );
1229  newstate.Beta = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *Beta_, numBlocks_, 1 ) );
1230  newstate.D = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *D_, numBlocks_, 1 ) );
1231  newstate.Delta = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *Delta_, recycleBlocks_, numBlocks_, 0, 1 ) );
1232  newstate.LUUTAU = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *LUUTAU_, recycleBlocks_, recycleBlocks_ ) );
1233  // assign the rest of the values in the struct
1234  newstate.curDim = 1; // We have initialized the first search vector
1235  newstate.Ap = Ap_;
1236  newstate.r = r_;
1237  newstate.z = z_;
1238  newstate.existU = existU_;
1239  newstate.ipiv = ipiv_;
1240  newstate.rTz_old = rTz_old_;
1241 
1242  rcg_iter->initialize(newstate);
1243 
1244  while(1) {
1245 
1246  // tell rcg_iter to iterate
1247  try {
1248  rcg_iter->iterate();
1249 
1251  //
1252  // check convergence first
1253  //
1255  if ( convTest_->getStatus() == Passed ) {
1256  // We have convergence
1257  break; // break from while(1){rcg_iter->iterate()}
1258  }
1260  //
1261  // check for maximum iterations
1262  //
1264  else if ( maxIterTest_->getStatus() == Passed ) {
1265  // we don't have convergence
1266  isConverged = false;
1267  break; // break from while(1){rcg_iter->iterate()}
1268  }
1270  //
1271  // check if cycle complete; update for next cycle
1272  //
1274  else if ( rcg_iter->getCurSubspaceDim() == rcg_iter->getMaxSubspaceDim() ) {
1275  // index into P_ of last search vector generated this cycle
1276  int lastp = -1;
1277  // index into Beta_ of last entry generated this cycle
1278  int lastBeta = -1;
1279  if (recycleBlocks_ > 0) {
1280  if (!existU_) {
1281  if (cycle == 0) { // No U, no U1
1282 
1283  Teuchos::SerialDenseMatrix<int,ScalarType> Ftmp( Teuchos::View, *F_, numBlocks_, numBlocks_ );
1284  Teuchos::SerialDenseMatrix<int,ScalarType> Gtmp( Teuchos::View, *G_, numBlocks_, numBlocks_ );
1285  Teuchos::SerialDenseMatrix<int,ScalarType> Dtmp( Teuchos::View, *D_, numBlocks_, 1 );
1286  Teuchos::SerialDenseMatrix<int,ScalarType> Alphatmp( Teuchos::View, *Alpha_, numBlocks_, 1 );
1287  Teuchos::SerialDenseMatrix<int,ScalarType> Betatmp( Teuchos::View, *Beta_, numBlocks_, 1 );
1288  Ftmp.putScalar(zero);
1289  Gtmp.putScalar(zero);
1290  for (int ii=0;ii<numBlocks_;ii++) {
1291  Gtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii,0));
1292  if (ii > 0) {
1293  Gtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1294  Gtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1295  }
1296  Ftmp(ii,ii) = Dtmp(ii,0);
1297  }
1298 
1299  // compute harmonic Ritz vectors
1300  Teuchos::SerialDenseMatrix<int,ScalarType> Ytmp( Teuchos::View, *Y_, numBlocks_, recycleBlocks_ );
1301  getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1302 
1303  // U1 = [P(:,1:end-1)*Y];
1304  index.resize( numBlocks_ );
1305  for (int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii; }
1306  Teuchos::RCP<const MV> Ptmp = MVT::CloneView( *P_, index );
1307  index.resize( recycleBlocks_ );
1308  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1309  Teuchos::RCP<MV> U1tmp = MVT::CloneViewNonConst( *U1_, index );
1310  MVT::MvTimesMatAddMv( one, *Ptmp, Ytmp, zero, *U1tmp );
1311 
1312  // Precompute some variables for next cycle
1313 
1314  // AU1TAU1 = Y'*G*Y;
1315  Teuchos::SerialDenseMatrix<int,ScalarType> GYtmp( Teuchos::View, *GY_, numBlocks_, recycleBlocks_ );
1316  GYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Gtmp,Ytmp,zero);
1317  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAU1tmp( Teuchos::View, *AU1TAU1_, recycleBlocks_, recycleBlocks_ );
1318  AU1TAU1tmp.multiply(Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,GYtmp,zero);
1319 
1320  // AU1TU1 = Y'*F*Y;
1321  Teuchos::SerialDenseMatrix<int,ScalarType> FYtmp( Teuchos::View, *FY_, numBlocks_, recycleBlocks_ );
1322  FYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Ftmp,Ytmp,zero);
1323  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TU1tmp( Teuchos::View, *AU1TU1_, recycleBlocks_, recycleBlocks_ );
1324  AU1TU1tmp.multiply(Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,FYtmp,zero);
1325 
1326  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAPtmp( Teuchos::View, *AU1TAP_, recycleBlocks_, 1 );
1327  // Must reinitialize AU1TAP; can become dense later
1328  AU1TAPtmp.putScalar(zero);
1329  // AU1TAP(:,1) = Y(end,:)' * (-1/Alpha(end));
1330  ScalarType alphatmp = -1.0 / Alphatmp(numBlocks_-1,0);
1331  for (int ii=0; ii<recycleBlocks_; ++ii) {
1332  AU1TAPtmp(ii,0) = Ytmp(numBlocks_-1,ii) * alphatmp;
1333  }
1334 
1335  // indicate that updated recycle space now defined
1336  existU1_ = true;
1337 
1338  // Indicate the size of the P, Beta structures generated this cycle
1339  lastp = numBlocks_;
1340  lastBeta = numBlocks_-1;
1341 
1342  } // if (cycle == 0)
1343  else { // No U, but U1 guaranteed to exist now
1344 
1345  // Finish computation of subblocks
1346  // AU1TAP = AU1TAP * D(1);
1347  Teuchos::SerialDenseMatrix<int,ScalarType> Dtmp( Teuchos::View, *D_, numBlocks_, 1 );
1348  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAPtmp( Teuchos::View, *AU1TAP_, recycleBlocks_, numBlocks_ );
1349  AU1TAPtmp.scale(Dtmp(0,0));
1350 
1351  Teuchos::SerialDenseMatrix<int,ScalarType> Alphatmp( Teuchos::View, *Alpha_, numBlocks_, 1 );
1352  Teuchos::SerialDenseMatrix<int,ScalarType> Betatmp( Teuchos::View, *Beta_, numBlocks_+1, 1 );
1353  Teuchos::SerialDenseMatrix<int,ScalarType> APTAPtmp( Teuchos::View, *APTAP_, numBlocks_, numBlocks_ );
1354  APTAPtmp.putScalar(zero);
1355  for (int ii=0; ii<numBlocks_; ii++) {
1356  APTAPtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii+1,0));
1357  if (ii > 0) {
1358  APTAPtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1359  APTAPtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1360  }
1361  }
1362 
1363  // F = [AU1TU1 zeros(k,m); zeros(m,k) diag(D)];
1364  Teuchos::SerialDenseMatrix<int,ScalarType> Ftmp( Teuchos::View, *F_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1365  Teuchos::SerialDenseMatrix<int,ScalarType> F11( Teuchos::View, *F_, recycleBlocks_, recycleBlocks_ );
1366  Teuchos::SerialDenseMatrix<int,ScalarType> F12( Teuchos::View, *F_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1367  Teuchos::SerialDenseMatrix<int,ScalarType> F21( Teuchos::View, *F_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1368  Teuchos::SerialDenseMatrix<int,ScalarType> F22( Teuchos::View, *F_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1369  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TU1tmp( Teuchos::View, *AU1TU1_, recycleBlocks_, recycleBlocks_ );
1370  F11.assign(AU1TU1tmp);
1371  F12.putScalar(zero);
1372  F21.putScalar(zero);
1373  F22.putScalar(zero);
1374  for(int ii=0;ii<numBlocks_;ii++) {
1375  F22(ii,ii) = Dtmp(ii,0);
1376  }
1377 
1378  // G = [AU1TAU1 AU1TAP; AU1TAP' APTAP];
1379  Teuchos::SerialDenseMatrix<int,ScalarType> Gtmp( Teuchos::View, *G_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1380  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAU1tmp( Teuchos::View, *AU1TAU1_, recycleBlocks_, recycleBlocks_ );
1381  Teuchos::SerialDenseMatrix<int,ScalarType> G11( Teuchos::View, *G_, recycleBlocks_, recycleBlocks_ );
1382  Teuchos::SerialDenseMatrix<int,ScalarType> G12( Teuchos::View, *G_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1383  Teuchos::SerialDenseMatrix<int,ScalarType> G21( Teuchos::View, *G_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1384  Teuchos::SerialDenseMatrix<int,ScalarType> G22( Teuchos::View, *G_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1385  G11.assign(AU1TAU1tmp);
1386  G12.assign(AU1TAPtmp);
1387  // G21 = G12'; (no transpose operator exists for SerialDenseMatrix; Do copy manually)
1388  for (int ii=0;ii<recycleBlocks_;++ii)
1389  for (int jj=0;jj<numBlocks_;++jj)
1390  G21(jj,ii) = G12(ii,jj);
1391  G22.assign(APTAPtmp);
1392 
1393  // compute harmonic Ritz vectors
1394  Teuchos::SerialDenseMatrix<int,ScalarType> Ytmp( Teuchos::View, *Y_, (recycleBlocks_+numBlocks_), recycleBlocks_ );
1395  getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1396 
1397  // U1 = [U1 P(:,2:end-1)]*Y;
1398  index.resize( numBlocks_ );
1399  for (int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii+1; }
1400  Teuchos::RCP<const MV> Ptmp = MVT::CloneView( *P_, index );
1401  index.resize( recycleBlocks_ );
1402  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1403  Teuchos::RCP<MV> PY2tmp = MVT::CloneViewNonConst( *PY2_, index );
1404  Teuchos::SerialDenseMatrix<int,ScalarType> Y2( Teuchos::View, *Y_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1405  index.resize( recycleBlocks_ );
1406  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1407  Teuchos::RCP<MV> U1tmp = MVT::CloneViewNonConst( *U1_, index );
1408  index.resize( recycleBlocks_ );
1409  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1410  Teuchos::RCP<MV> U1Y1tmp = MVT::CloneViewNonConst( *U1Y1_, index );
1411  Teuchos::SerialDenseMatrix<int,ScalarType> Y1( Teuchos::View, *Y_, recycleBlocks_, recycleBlocks_ );
1412  MVT::MvTimesMatAddMv( one, *Ptmp, Y2, zero, *PY2tmp );
1413  MVT::MvTimesMatAddMv( one, *U1tmp, Y1, zero, *U1Y1tmp );
1414  MVT::MvAddMv(one,*U1Y1tmp, one, *PY2tmp, *U1tmp);
1415 
1416  // Precompute some variables for next cycle
1417 
1418  // AU1TAU1 = Y'*G*Y;
1419  Teuchos::SerialDenseMatrix<int,ScalarType> GYtmp( Teuchos::View, *GY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1420  GYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Gtmp,Ytmp,zero);
1421  AU1TAU1tmp.multiply(Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,GYtmp,zero);
1422 
1423  // AU1TAP = zeros(k,m);
1424  // AU1TAP(:,1) = Y(end,:)' * (-1/Alpha(end));
1425  AU1TAPtmp.putScalar(zero);
1426  ScalarType alphatmp = -1.0 / Alphatmp(numBlocks_-1,0);
1427  for (int ii=0; ii<recycleBlocks_; ++ii) {
1428  AU1TAPtmp(ii,0) = Ytmp(numBlocks_+recycleBlocks_-1,ii) * alphatmp;
1429  }
1430 
1431  // AU1TU1 = Y'*F*Y;
1432  Teuchos::SerialDenseMatrix<int,ScalarType> FYtmp( Teuchos::View, *FY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1433  FYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Ftmp,Ytmp,zero);
1434  //Teuchos::SerialDenseMatrix<int,ScalarType> AU1TU1tmp( Teuchos::View, *AU1TU1_, recycleBlocks_, recycleBlocks_ );
1435  AU1TU1tmp.multiply(Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,FYtmp,zero);
1436 
1437  // Indicate the size of the P, Beta structures generated this cycle
1438  lastp = numBlocks_+1;
1439  lastBeta = numBlocks_;
1440 
1441  } // if (cycle != 1)
1442  } // if (!existU_)
1443  else { // U exists
1444  if (cycle == 0) { // No U1, but U exists
1445  Teuchos::SerialDenseMatrix<int,ScalarType> Alphatmp( Teuchos::View, *Alpha_, numBlocks_, 1 );
1446  Teuchos::SerialDenseMatrix<int,ScalarType> Betatmp( Teuchos::View, *Beta_, numBlocks_, 1 );
1447  Teuchos::SerialDenseMatrix<int,ScalarType> Dtmp( Teuchos::View, *D_, numBlocks_, 1 );
1448  Teuchos::SerialDenseMatrix<int,ScalarType> APTAPtmp( Teuchos::View, *APTAP_, numBlocks_, numBlocks_ );
1449  APTAPtmp.putScalar(zero);
1450  for (int ii=0; ii<numBlocks_; ii++) {
1451  APTAPtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii,0));
1452  if (ii > 0) {
1453  APTAPtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1454  APTAPtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1455  }
1456  }
1457 
1458  Teuchos::SerialDenseMatrix<int,ScalarType> L2tmp( Teuchos::View, *L2_, numBlocks_+1, numBlocks_ );
1459  L2tmp.putScalar(zero);
1460  for(int ii=0;ii<numBlocks_;ii++) {
1461  L2tmp(ii,ii) = 1./Alphatmp(ii,0);
1462  L2tmp(ii+1,ii) = -1./Alphatmp(ii,0);
1463  }
1464 
1465  // AUTAP = UTAU*Delta*L2;
1466  Teuchos::SerialDenseMatrix<int,ScalarType> AUTAPtmp( Teuchos::View, *AUTAP_, recycleBlocks_, numBlocks_ );
1467  Teuchos::SerialDenseMatrix<int,ScalarType> UTAUtmp( Teuchos::View, *UTAU_, recycleBlocks_, recycleBlocks_ );
1468  Teuchos::SerialDenseMatrix<int,ScalarType> Deltatmp( Teuchos::View, *Delta_, recycleBlocks_, numBlocks_+1 );
1469  Teuchos::SerialDenseMatrix<int,ScalarType> DeltaL2tmp( Teuchos::View, *DeltaL2_, recycleBlocks_, numBlocks_ );
1470  DeltaL2tmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Deltatmp,L2tmp,zero);
1471  AUTAPtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,UTAUtmp,DeltaL2tmp,zero);
1472 
1473  // F = [UTAU zeros(k,m); zeros(m,k) diag(D)];
1474  Teuchos::SerialDenseMatrix<int,ScalarType> Ftmp( Teuchos::View, *F_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1475  Teuchos::SerialDenseMatrix<int,ScalarType> F11( Teuchos::View, *F_, recycleBlocks_, recycleBlocks_ );
1476  Teuchos::SerialDenseMatrix<int,ScalarType> F12( Teuchos::View, *F_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1477  Teuchos::SerialDenseMatrix<int,ScalarType> F21( Teuchos::View, *F_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1478  Teuchos::SerialDenseMatrix<int,ScalarType> F22( Teuchos::View, *F_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1479  F11.assign(UTAUtmp);
1480  F12.putScalar(zero);
1481  F21.putScalar(zero);
1482  F22.putScalar(zero);
1483  for(int ii=0;ii<numBlocks_;ii++) {
1484  F22(ii,ii) = Dtmp(ii,0);
1485  }
1486 
1487  // G = [AUTAU AUTAP; AUTAP' APTAP];
1488  Teuchos::SerialDenseMatrix<int,ScalarType> Gtmp( Teuchos::View, *G_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1489  Teuchos::SerialDenseMatrix<int,ScalarType> G11( Teuchos::View, *G_, recycleBlocks_, recycleBlocks_ );
1490  Teuchos::SerialDenseMatrix<int,ScalarType> G12( Teuchos::View, *G_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1491  Teuchos::SerialDenseMatrix<int,ScalarType> G21( Teuchos::View, *G_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1492  Teuchos::SerialDenseMatrix<int,ScalarType> G22( Teuchos::View, *G_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1493  Teuchos::SerialDenseMatrix<int,ScalarType> AUTAUtmp( Teuchos::View, *AUTAU_, recycleBlocks_, recycleBlocks_ );
1494  G11.assign(AUTAUtmp);
1495  G12.assign(AUTAPtmp);
1496  // G21 = G12'; (no transpose operator exists for SerialDenseMatrix; Do copy manually)
1497  for (int ii=0;ii<recycleBlocks_;++ii)
1498  for (int jj=0;jj<numBlocks_;++jj)
1499  G21(jj,ii) = G12(ii,jj);
1500  G22.assign(APTAPtmp);
1501 
1502  // compute harmonic Ritz vectors
1503  Teuchos::SerialDenseMatrix<int,ScalarType> Ytmp( Teuchos::View, *Y_, (recycleBlocks_+numBlocks_), recycleBlocks_ );
1504  getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1505 
1506  // U1 = [U P(:,1:end-1)]*Y;
1507  index.resize( recycleBlocks_ );
1508  for (int ii=0; ii<(recycleBlocks_); ++ii) { index[ii] = ii; }
1509  Teuchos::RCP<const MV> Utmp = MVT::CloneView( *U_, index );
1510  index.resize( numBlocks_ );
1511  for (int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii; }
1512  Teuchos::RCP<const MV> Ptmp = MVT::CloneView( *P_, index );
1513  index.resize( recycleBlocks_ );
1514  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1515  Teuchos::RCP<MV> PY2tmp = MVT::CloneViewNonConst( *PY2_, index );
1516  Teuchos::SerialDenseMatrix<int,ScalarType> Y2( Teuchos::View, *Y_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1517  index.resize( recycleBlocks_ );
1518  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1519  Teuchos::RCP<MV> UY1tmp = MVT::CloneViewNonConst( *U1Y1_, index );
1520  Teuchos::SerialDenseMatrix<int,ScalarType> Y1( Teuchos::View, *Y_, recycleBlocks_, recycleBlocks_ );
1521  index.resize( recycleBlocks_ );
1522  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1523  Teuchos::RCP<MV> U1tmp = MVT::CloneViewNonConst( *U1_, index );
1524  MVT::MvTimesMatAddMv( one, *Ptmp, Y2, zero, *PY2tmp );
1525  MVT::MvTimesMatAddMv( one, *Utmp, Y1, zero, *UY1tmp );
1526  MVT::MvAddMv(one,*UY1tmp, one, *PY2tmp, *U1tmp);
1527 
1528  // Precompute some variables for next cycle
1529 
1530  // AU1TAU1 = Y'*G*Y;
1531  Teuchos::SerialDenseMatrix<int,ScalarType> GYtmp( Teuchos::View, *GY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1532  GYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Gtmp,Ytmp,zero);
1533  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAU1tmp( Teuchos::View, *AU1TAU1_, recycleBlocks_, recycleBlocks_ );
1534  AU1TAU1tmp.multiply(Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,GYtmp,zero);
1535 
1536  // AU1TU1 = Y'*F*Y;
1537  Teuchos::SerialDenseMatrix<int,ScalarType> FYtmp( Teuchos::View, *FY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1538  FYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Ftmp,Ytmp,zero);
1539  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TU1tmp( Teuchos::View, *AU1TU1_, recycleBlocks_, recycleBlocks_ );
1540  AU1TU1tmp.multiply(Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,FYtmp,zero);
1541 
1542  // AU1TU = UTAU;
1543  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TUtmp( Teuchos::View, *AU1TU_, recycleBlocks_, recycleBlocks_ );
1544  AU1TUtmp.assign(UTAUtmp);
1545 
1546  // dold = D(end);
1547  dold = Dtmp(numBlocks_-1,0);
1548 
1549  // indicate that updated recycle space now defined
1550  existU1_ = true;
1551 
1552  // Indicate the size of the P, Beta structures generated this cycle
1553  lastp = numBlocks_;
1554  lastBeta = numBlocks_-1;
1555  }
1556  else { // Have U and U1
1557  Teuchos::SerialDenseMatrix<int,ScalarType> Alphatmp( Teuchos::View, *Alpha_, numBlocks_, 1 );
1558  Teuchos::SerialDenseMatrix<int,ScalarType> Betatmp( Teuchos::View, *Beta_, numBlocks_+1, 1 );
1559  Teuchos::SerialDenseMatrix<int,ScalarType> Dtmp( Teuchos::View, *D_, numBlocks_, 1 );
1560  Teuchos::SerialDenseMatrix<int,ScalarType> APTAPtmp( Teuchos::View, *APTAP_, numBlocks_, numBlocks_ );
1561  for (int ii=0; ii<numBlocks_; ii++) {
1562  APTAPtmp(ii,ii) = (Dtmp(ii,0) / Alphatmp(ii,0))*(1 + Betatmp(ii+1,0));
1563  if (ii > 0) {
1564  APTAPtmp(ii-1,ii) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1565  APTAPtmp(ii,ii-1) = -Dtmp(ii,0)/Alphatmp(ii-1,0);
1566  }
1567  }
1568 
1569  Teuchos::SerialDenseMatrix<int,ScalarType> L2tmp( Teuchos::View, *L2_, numBlocks_+1, numBlocks_ );
1570  for(int ii=0;ii<numBlocks_;ii++) {
1571  L2tmp(ii,ii) = 1./Alphatmp(ii,0);
1572  L2tmp(ii+1,ii) = -1./Alphatmp(ii,0);
1573  }
1574 
1575  // M(end,1) = dold*(-Beta(1)/Alpha(1));
1576  // AU1TAP = Y'*[AU1TU*Delta*L2; M];
1577  Teuchos::SerialDenseMatrix<int,ScalarType> DeltaL2( Teuchos::View, *DeltaL2_, recycleBlocks_, numBlocks_ );
1578  Teuchos::SerialDenseMatrix<int,ScalarType> Deltatmp( Teuchos::View, *Delta_, recycleBlocks_, numBlocks_+1 );
1579  DeltaL2.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Deltatmp,L2tmp,zero);
1580  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TUDeltaL2( Teuchos::View, *AU1TUDeltaL2_, recycleBlocks_, numBlocks_ );
1581  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TUtmp( Teuchos::View, *AU1TU_, recycleBlocks_, recycleBlocks_ );
1582  AU1TUDeltaL2.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,AU1TUtmp,DeltaL2,zero);
1583  Teuchos::SerialDenseMatrix<int,ScalarType> Y1( Teuchos::View, *Y_, recycleBlocks_, recycleBlocks_ );
1584  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAPtmp( Teuchos::View, *AU1TAP_, recycleBlocks_, numBlocks_ );
1585  AU1TAPtmp.putScalar(zero);
1586  AU1TAPtmp.multiply(Teuchos::TRANS,Teuchos::NO_TRANS,one,Y1,AU1TUDeltaL2,zero);
1587  Teuchos::SerialDenseMatrix<int,ScalarType> Y2( Teuchos::View, *Y_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1588  ScalarType val = dold * (-Betatmp(0,0)/Alphatmp(0,0));
1589  for(int ii=0;ii<recycleBlocks_;ii++) {
1590  AU1TAPtmp(ii,0) += Y2(numBlocks_-1,ii)*val;
1591  }
1592 
1593  // AU1TU = Y1'*AU1TU
1594  Teuchos::SerialDenseMatrix<int,ScalarType> Y1TAU1TU( Teuchos::View, *GY_, recycleBlocks_, recycleBlocks_ );
1595  Y1TAU1TU.multiply(Teuchos::TRANS,Teuchos::NO_TRANS,one,Y1,AU1TUtmp,zero);
1596  AU1TUtmp.assign(Y1TAU1TU);
1597 
1598  // F = [AU1TU1 zeros(k,m); zeros(m,k) diag(D)];
1599  Teuchos::SerialDenseMatrix<int,ScalarType> Ftmp( Teuchos::View, *F_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1600  Teuchos::SerialDenseMatrix<int,ScalarType> F11( Teuchos::View, *F_, recycleBlocks_, recycleBlocks_ );
1601  Teuchos::SerialDenseMatrix<int,ScalarType> F12( Teuchos::View, *F_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1602  Teuchos::SerialDenseMatrix<int,ScalarType> F21( Teuchos::View, *F_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1603  Teuchos::SerialDenseMatrix<int,ScalarType> F22( Teuchos::View, *F_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1604  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TU1tmp( Teuchos::View, *AU1TU1_, recycleBlocks_, recycleBlocks_ );
1605  F11.assign(AU1TU1tmp);
1606  for(int ii=0;ii<numBlocks_;ii++) {
1607  F22(ii,ii) = Dtmp(ii,0);
1608  }
1609 
1610  // G = [AU1TAU1 AU1TAP; AU1TAP' APTAP];
1611  Teuchos::SerialDenseMatrix<int,ScalarType> Gtmp( Teuchos::View, *G_, (numBlocks_+recycleBlocks_), (numBlocks_+recycleBlocks_) );
1612  Teuchos::SerialDenseMatrix<int,ScalarType> G11( Teuchos::View, *G_, recycleBlocks_, recycleBlocks_ );
1613  Teuchos::SerialDenseMatrix<int,ScalarType> G12( Teuchos::View, *G_, recycleBlocks_, numBlocks_, 0, recycleBlocks_ );
1614  Teuchos::SerialDenseMatrix<int,ScalarType> G21( Teuchos::View, *G_, numBlocks_, recycleBlocks_, recycleBlocks_, 0 );
1615  Teuchos::SerialDenseMatrix<int,ScalarType> G22( Teuchos::View, *G_, numBlocks_, numBlocks_, recycleBlocks_, recycleBlocks_ );
1616  Teuchos::SerialDenseMatrix<int,ScalarType> AU1TAU1tmp( Teuchos::View, *AU1TAU1_, recycleBlocks_, recycleBlocks_ );
1617  G11.assign(AU1TAU1tmp);
1618  G12.assign(AU1TAPtmp);
1619  // G21 = G12'; (no transpose operator exists for SerialDenseMatrix; Do copy manually)
1620  for (int ii=0;ii<recycleBlocks_;++ii)
1621  for (int jj=0;jj<numBlocks_;++jj)
1622  G21(jj,ii) = G12(ii,jj);
1623  G22.assign(APTAPtmp);
1624 
1625  // compute harmonic Ritz vectors
1626  Teuchos::SerialDenseMatrix<int,ScalarType> Ytmp( Teuchos::View, *Y_, (recycleBlocks_+numBlocks_), recycleBlocks_ );
1627  getHarmonicVecs(Ftmp,Gtmp,Ytmp);
1628 
1629  // U1 = [U1 P(:,2:end-1)]*Y;
1630  index.resize( numBlocks_ );
1631  for (int ii=0; ii<numBlocks_; ++ii) { index[ii] = ii+1; }
1632  Teuchos::RCP<const MV> Ptmp = MVT::CloneView( *P_, index );
1633  index.resize( recycleBlocks_ );
1634  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1635  Teuchos::RCP<MV> PY2tmp = MVT::CloneViewNonConst( *PY2_, index );
1636  index.resize( recycleBlocks_ );
1637  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1638  Teuchos::RCP<MV> U1tmp = MVT::CloneViewNonConst( *U1_, index );
1639  index.resize( recycleBlocks_ );
1640  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1641  Teuchos::RCP<MV> U1Y1tmp = MVT::CloneViewNonConst( *U1Y1_, index );
1642  MVT::MvTimesMatAddMv( one, *Ptmp, Y2, zero, *PY2tmp );
1643  MVT::MvTimesMatAddMv( one, *U1tmp, Y1, zero, *U1Y1tmp );
1644  MVT::MvAddMv(one,*U1Y1tmp, one, *PY2tmp, *U1tmp);
1645 
1646  // Precompute some variables for next cycle
1647 
1648  // AU1TAU1 = Y'*G*Y;
1649  Teuchos::SerialDenseMatrix<int,ScalarType> GYtmp( Teuchos::View, *GY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1650  GYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Gtmp,Ytmp,zero);
1651  AU1TAU1tmp.multiply(Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,GYtmp,zero);
1652 
1653  // AU1TU1 = Y'*F*Y;
1654  Teuchos::SerialDenseMatrix<int,ScalarType> FYtmp( Teuchos::View, *FY_, (numBlocks_+recycleBlocks_), recycleBlocks_ );
1655  FYtmp.multiply(Teuchos::NO_TRANS,Teuchos::NO_TRANS,one,Ftmp,Ytmp,zero);
1656  AU1TU1tmp.multiply(Teuchos::TRANS,Teuchos::NO_TRANS,one,Ytmp,FYtmp,zero);
1657 
1658  // dold = D(end);
1659  dold = Dtmp(numBlocks_-1,0);
1660 
1661  // Indicate the size of the P, Beta structures generated this cycle
1662  lastp = numBlocks_+1;
1663  lastBeta = numBlocks_;
1664 
1665  }
1666  }
1667  } // if (recycleBlocks_ > 0)
1668 
1669  // Cleanup after end of cycle
1670 
1671  // P = P(:,end-1:end);
1672  index.resize( 2 );
1673  index[0] = lastp-1; index[1] = lastp;
1674  Teuchos::RCP<const MV> Ptmp2 = MVT::CloneView( *P_, index );
1675  index[0] = 0; index[1] = 1;
1676  MVT::SetBlock(*Ptmp2,index,*P_);
1677 
1678  // Beta = Beta(end);
1679  (*Beta_)(0,0) = (*Beta_)(lastBeta,0);
1680 
1681  // Delta = Delta(:,end);
1682  if (existU_) { // Delta only initialized if U exists
1683  Teuchos::SerialDenseMatrix<int,ScalarType> mu1( Teuchos::View, *Delta_, recycleBlocks_, 1, 0, 0 );
1684  Teuchos::SerialDenseMatrix<int,ScalarType> mu2( Teuchos::View, *Delta_, recycleBlocks_, 1, 0, numBlocks_ );
1685  mu1.assign(mu2);
1686  }
1687 
1688  // Now reinitialize state variables for next cycle
1689  newstate.P = Teuchos::null;
1690  index.resize( numBlocks_+1 );
1691  for (int ii=0; ii<(numBlocks_+1); ++ii) { index[ii] = ii+1; }
1692  newstate.P = MVT::CloneViewNonConst( *P_, index );
1693 
1694  newstate.Beta = Teuchos::null;
1695  newstate.Beta = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *Beta_, numBlocks_, 1, 1, 0 ) );
1696 
1697  newstate.Delta = Teuchos::null;
1698  newstate.Delta = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::View, *Delta_, recycleBlocks_, numBlocks_, 0, 1 ) );
1699 
1700  newstate.curDim = 1; // We have initialized the first search vector
1701 
1702  // Pass to iteration object
1703  rcg_iter->initialize(newstate);
1704 
1705  // increment cycle count
1706  cycle = cycle + 1;
1707 
1708  }
1710  //
1711  // we returned from iterate(), but none of our status tests Passed.
1712  // something is wrong, and it is probably our fault.
1713  //
1715  else {
1716  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
1717  "Belos::RCGSolMgr::solve(): Invalid return from RCGIter::iterate().");
1718  }
1719  }
1720  catch (const std::exception &e) {
1721  printer_->stream(Errors) << "Error! Caught std::exception in RCGIter::iterate() at iteration "
1722  << rcg_iter->getNumIters() << std::endl
1723  << e.what() << std::endl;
1724  throw;
1725  }
1726  }
1727 
1728  // Inform the linear problem that we are finished with this block linear system.
1729  problem_->setCurrLS();
1730 
1731  // Update indices for the linear systems to be solved.
1732  numRHS2Solve -= 1;
1733  if ( numRHS2Solve > 0 ) {
1734  currIdx[0]++;
1735  // Set the next indices.
1736  problem_->setLSIndex( currIdx );
1737  }
1738  else {
1739  currIdx.resize( numRHS2Solve );
1740  }
1741 
1742  // Update the recycle space for the next linear system
1743  if (existU1_) { // be sure updated recycle space was created
1744  // U = U1
1745  index.resize(recycleBlocks_);
1746  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1747  MVT::SetBlock(*U1_,index,*U_);
1748  // Set flag indicating recycle space is now defined
1749  existU_ = true;
1750  if (numRHS2Solve > 0) { // also update AU, UTAU, and AUTAU
1751  // Free pointers in newstate
1752  newstate.P = Teuchos::null;
1753  newstate.Ap = Teuchos::null;
1754  newstate.r = Teuchos::null;
1755  newstate.z = Teuchos::null;
1756  newstate.U = Teuchos::null;
1757  newstate.AU = Teuchos::null;
1758  newstate.Alpha = Teuchos::null;
1759  newstate.Beta = Teuchos::null;
1760  newstate.D = Teuchos::null;
1761  newstate.Delta = Teuchos::null;
1762  newstate.LUUTAU = Teuchos::null;
1763  newstate.ipiv = Teuchos::null;
1764  newstate.rTz_old = Teuchos::null;
1765 
1766  // Reinitialize AU, UTAU, AUTAU
1767  index.resize(recycleBlocks_);
1768  for (int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1769  Teuchos::RCP<const MV> Utmp = MVT::CloneView( *U_, index );
1770  index.resize(recycleBlocks_);
1771  for (int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1772  Teuchos::RCP<MV> AUtmp = MVT::CloneViewNonConst( *AU_, index );
1773  // Initialize AU
1774  problem_->applyOp( *Utmp, *AUtmp );
1775  // Initialize UTAU
1776  Teuchos::SerialDenseMatrix<int,ScalarType> UTAUtmp( Teuchos::View, *UTAU_, recycleBlocks_, recycleBlocks_ );
1777  MVT::MvTransMv( one, *Utmp, *AUtmp, UTAUtmp );
1778  // Initialize AUTAU ( AUTAU = AU'*(M\AU) )
1779  Teuchos::SerialDenseMatrix<int,ScalarType> AUTAUtmp( Teuchos::View, *AUTAU_, recycleBlocks_, recycleBlocks_ );
1780  if ( precObj != Teuchos::null ) {
1781  index.resize(recycleBlocks_);
1782  for (int i=0; i<recycleBlocks_; ++i) { index[i] = i; }
1783  index.resize(recycleBlocks_);
1784  for (int ii=0; ii<recycleBlocks_; ++ii) { index[ii] = ii; }
1785  Teuchos::RCP<MV> LeftPCAU = MVT::CloneViewNonConst( *U1_, index ); // use U1 as temp storage
1786  OPT::Apply( *precObj, *AUtmp, *LeftPCAU );
1787  MVT::MvTransMv( one, *AUtmp, *LeftPCAU, AUTAUtmp );
1788  } else {
1789  MVT::MvTransMv( one, *AUtmp, *AUtmp, AUTAUtmp );
1790  }
1791  } // if (numRHS2Solve > 0)
1792 
1793  } // if (existU1)
1794  }// while ( numRHS2Solve > 0 )
1795 
1796  }
1797 
1798  // print final summary
1799  sTest_->print( printer_->stream(FinalSummary) );
1800 
1801  // print timing information
1802 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1803  // Calling summarize() can be expensive, so don't call unless the
1804  // user wants to print out timing details. summarize() will do all
1805  // the work even if it's passed a "black hole" output stream.
1806  if (verbosity_ & TimingDetails)
1807  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1808 #endif
1809 
1810  // get iteration information for this solve
1811  numIters_ = maxIterTest_->getNumIters();
1812 
1813  // Save the convergence test value ("achieved tolerance") for this solve.
1814  {
1815  using Teuchos::rcp_dynamic_cast;
1816  typedef StatusTestGenResNorm<ScalarType,MV,OP> conv_test_type;
1817  // testValues is nonnull and not persistent.
1818  const std::vector<MagnitudeType>* pTestValues =
1819  rcp_dynamic_cast<conv_test_type>(convTest_)->getTestValue();
1820 
1821  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1822  "Belos::RCGSolMgr::solve(): The convergence test's getTestValue() "
1823  "method returned NULL. Please report this bug to the Belos developers.");
1824 
1825  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1826  "Belos::RCGSolMgr::solve(): The convergence test's getTestValue() "
1827  "method returned a vector of length zero. Please report this bug to the "
1828  "Belos developers.");
1829 
1830  // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
1831  // achieved tolerances for all vectors in the current solve(), or
1832  // just for the vectors from the last deflation?
1833  achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1834  }
1835 
1836  if (!isConverged) {
1837  return Unconverged; // return from RCGSolMgr::solve()
1838  }
1839  return Converged; // return from RCGSolMgr::solve()
1840 }
1841 
1842 // Compute the harmonic eigenpairs of the projected, dense system.
1843 template<class ScalarType, class MV, class OP>
1847  // order of F,G
1848  int n = F.numCols();
1849 
1850  // The LAPACK interface
1852 
1853  // Magnitude of harmonic Ritz values
1854  std::vector<MagnitudeType> w(n);
1855 
1856  // Sorted order of harmonic Ritz values
1857  std::vector<int> iperm(n);
1858 
1859  // Compute k smallest harmonic Ritz pairs
1860  // SUBROUTINE DSYGV( ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK, LWORK, INFO )
1861  int itype = 1; // solve A*x = (lambda)*B*x
1862  char jobz='V'; // compute eigenvalues and eigenvectors
1863  char uplo='U'; // since F,G symmetric, reference only their upper triangular data
1864  std::vector<ScalarType> work(1);
1865  int lwork = -1;
1866  int info = 0;
1867  // since SYGV destroys workspace, create copies of F,G
1868  Teuchos::SerialDenseMatrix<int,ScalarType> F2( Teuchos::Copy, *F_, F_->numRows(), F_->numCols() );
1869  Teuchos::SerialDenseMatrix<int,ScalarType> G2( Teuchos::Copy, *G_, G_->numRows(), G_->numCols() );
1870 
1871  // query for optimal workspace size
1872  lapack.SYGV(itype, jobz, uplo, n, G2.values(), G2.stride(), F2.values(), F2.stride(), &w[0], &work[0], lwork, &info);
1874  "Belos::RCGSolMgr::solve(): LAPACK SYGV failed to query optimal work size.");
1875  lwork = (int)work[0];
1876  work.resize(lwork);
1877  lapack.SYGV(itype, jobz, uplo, n, G2.values(), G2.stride(), F2.values(), F2.stride(), &w[0], &work[0], lwork, &info);
1879  "Belos::RCGSolMgr::solve(): LAPACK SYGV failed to compute eigensolutions.");
1880 
1881 
1882  // Construct magnitude of each harmonic Ritz value
1883  this->sort(w,n,iperm);
1884 
1885  // Select recycledBlocks_ smallest eigenvectors
1886  for( int i=0; i<recycleBlocks_; i++ ) {
1887  for( int j=0; j<n; j++ ) {
1888  Y(j,i) = G2(j,iperm[i]);
1889  }
1890  }
1891 
1892 }
1893 
1894 // This method sorts list of n floating-point numbers and return permutation vector
1895 template<class ScalarType, class MV, class OP>
1896 void RCGSolMgr<ScalarType,MV,OP>::sort(std::vector<ScalarType>& dlist, int n, std::vector<int>& iperm)
1897 {
1898  int l, r, j, i, flag;
1899  int RR2;
1900  double dRR, dK;
1901 
1902  // Initialize the permutation vector.
1903  for(j=0;j<n;j++)
1904  iperm[j] = j;
1905 
1906  if (n <= 1) return;
1907 
1908  l = n / 2 + 1;
1909  r = n - 1;
1910  l = l - 1;
1911  dRR = dlist[l - 1];
1912  dK = dlist[l - 1];
1913 
1914  RR2 = iperm[l - 1];
1915  while (r != 0) {
1916  j = l;
1917  flag = 1;
1918 
1919  while (flag == 1) {
1920  i = j;
1921  j = j + j;
1922 
1923  if (j > r + 1)
1924  flag = 0;
1925  else {
1926  if (j < r + 1)
1927  if (dlist[j] > dlist[j - 1]) j = j + 1;
1928 
1929  if (dlist[j - 1] > dK) {
1930  dlist[i - 1] = dlist[j - 1];
1931  iperm[i - 1] = iperm[j - 1];
1932  }
1933  else {
1934  flag = 0;
1935  }
1936  }
1937  }
1938  dlist[i - 1] = dRR;
1939  iperm[i - 1] = RR2;
1940  if (l == 1) {
1941  dRR = dlist [r];
1942  RR2 = iperm[r];
1943  dK = dlist[r];
1944  dlist[r] = dlist[0];
1945  iperm[r] = iperm[0];
1946  r = r - 1;
1947  }
1948  else {
1949  l = l - 1;
1950  dRR = dlist[l - 1];
1951  RR2 = iperm[l - 1];
1952  dK = dlist[l - 1];
1953  }
1954  }
1955  dlist[0] = dRR;
1956  iperm[0] = RR2;
1957 }
1958 
1959 // This method requires the solver manager to return a std::string that describes itself.
1960 template<class ScalarType, class MV, class OP>
1962 {
1963  std::ostringstream oss;
1964  oss << "Belos::RCGSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
1965  return oss.str();
1966 }
1967 
1968 } // end Belos namespace
1969 
1970 #endif /* BELOS_RCG_SOLMGR_HPP */
ScalarType * values() const
Teuchos::RCP< MV > r
The current residual.
Collection of types and exceptions used within the Belos solvers.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > rTz_old
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
Teuchos::RCP< MV > P
The current Krylov basis.
Teuchos::RCP< std::vector< int > > ipiv
Data from LU factorization of U^T A U.
Class which manages the output and verbosity of the Belos solvers.
void SYGV(const OrdinalType itype, const char JOBZ, const char UPLO, const OrdinalType n, ScalarType *A, const OrdinalType lda, ScalarType *B, const OrdinalType ldb, ScalarType *W, ScalarType *WORK, const OrdinalType lwork, OrdinalType *info) const
bool is_null(const boost::shared_ptr< T > &p)
RCGSolMgrRecyclingFailure is thrown when any problem occurs in using/creating the recycling subspace...
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver&#39;s iterate() routine unti...
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
Teuchos::RCP< MV > AU
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)
static RCP< Time > getNewCounter(const std::string &name)
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
Teuchos::RCP< MV > U
The recycled subspace and its image.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > LUUTAU
The LU factorization of the matrix U^T A U.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
A factory class for generating StatusTestOutput objects.
The Belos::RCGSolMgr provides a powerful and fully-featured solver manager over the RCG (Recycling Co...
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Beta
This class implements the RCG iteration, where a single-std::vector Krylov subspace is constructed...
void GETRS(const char TRANS, const OrdinalType n, const OrdinalType nrhs, const ScalarType *A, const OrdinalType lda, const OrdinalType *IPIV, ScalarType *B, const OrdinalType ldb, OrdinalType *info) const
An implementation of StatusTestResNorm using a family of residual norms.
int scale(const ScalarType alpha)
An extension of the MultiVecTraits class that adds a new vector length method.
Belos::StatusTest class for specifying a maximum number of iterations.
static std::string name()
std::string description() const
Method to return description of the RCG solver manager.
int getNumIters() const
Get the iteration count for the most recent call to solve().
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters the solver manager should use to solve the linear problem.
A factory class for generating StatusTestOutput objects.
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
RCGSolMgrLinearProblemFailure(const std::string &what_arg)
RCGSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i.e.
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
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="")
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
bool isParameter(const std::string &name) const
Structure to contain pointers to RCGIter state variables.
Belos concrete class for performing the RCG iteration.
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class...
A Belos::StatusTest class for specifying a maximum number of iterations.
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:200
bool existU
Flag to indicate the recycle space should be used.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Pure virtual base class which describes the basic interface for a solver manager. ...
Teuchos::RCP< MV > z
The current preconditioned residual.
Teuchos::RCP< MV > Ap
A times current search vector.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
bool isLOADetected() const
Return whether a loss of accuracy was detected by this solver during the most current solve...
RCGSolMgr()
Empty constructor for RCGSolMgr. This constructor takes no arguments and sets the default values for ...
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:149
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Iterated Classical Gram-Schmidt (ICGS) implementation of the Belos::OrthoManager class.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Alpha
Coefficients arising in RCG iteration.
OrdinalType numCols() const
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > create(const Teuchos::RCP< OutputManager< ScalarType > > &printer, Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test, int mod, int printStates)
Create the StatusTestOutput object specified by the outputStyle.
virtual ~RCGSolMgr()
Destructor.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
int curDim
The current dimension of the reduction.
RCGSolMgrLAPACKFailure(const std::string &what_arg)
A class for extending the status testing capabilities of Belos via logical combinations.
Class which defines basic traits for the operator type.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > D
Parent class to all Belos exceptions.
Definition: BelosTypes.hpp:60
void GESV(const OrdinalType n, const OrdinalType nrhs, ScalarType *A, const OrdinalType lda, OrdinalType *IPIV, ScalarType *B, const OrdinalType ldb, OrdinalType *info) const
RCGSolMgrRecyclingFailure(const std::string &what_arg)
Belos header file which uses auto-configuration information to include necessary C++ headers...
RCGSolMgrLAPACKFailure is thrown when a nonzero value is retuned from an LAPACK call.
SerialDenseMatrix< OrdinalType, ScalarType > & assign(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Delta
Solutions to local least-squares problems.
OrdinalType stride() const