Belos  Version of the Day
BelosPseudoBlockGmresSolMgr.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_SOLMGR_HPP
43 #define BELOS_PSEUDO_BLOCK_GMRES_SOLMGR_HPP
44 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosTypes.hpp"
51 
52 #include "BelosLinearProblem.hpp"
53 #include "BelosSolverManager.hpp"
54 
59 #ifdef HAVE_BELOS_TSQR
60 # include "BelosTsqrOrthoManager.hpp"
61 #endif // HAVE_BELOS_TSQR
65 #include "BelosStatusTestCombo.hpp"
67 #include "BelosOutputManager.hpp"
68 #include "Teuchos_BLAS.hpp"
69 #ifdef BELOS_TEUCHOS_TIME_MONITOR
70 #include "Teuchos_TimeMonitor.hpp"
71 #endif
72 
80 namespace Belos {
81 
83 
84 
92  PseudoBlockGmresSolMgrLinearProblemFailure(const std::string& what_arg) : BelosError(what_arg)
93  {}};
94 
102  PseudoBlockGmresSolMgrOrthoFailure(const std::string& what_arg) : BelosError(what_arg)
103  {}};
104 
128  template<class ScalarType, class MV, class OP>
129  class PseudoBlockGmresSolMgr : public SolverManager<ScalarType,MV,OP> {
130 
131  private:
134  typedef Teuchos::ScalarTraits<ScalarType> SCT;
135  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
136  typedef Teuchos::ScalarTraits<MagnitudeType> MT;
137 
138  public:
139 
141 
142 
151 
255  PseudoBlockGmresSolMgr( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem,
256  const Teuchos::RCP<Teuchos::ParameterList> &pl );
257 
261 
263 
264 
266  return *problem_;
267  }
268 
270  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
271 
273  Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const { return params_; }
274 
280  Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers() const {
281  return Teuchos::tuple(timerSolve_);
282  }
283 
294  MagnitudeType achievedTol() const {
295  return achievedTol_;
296  }
297 
299  int getNumIters() const {
300  return numIters_;
301  }
302 
358  bool isLOADetected() const { return loaDetected_; }
359 
361 
363 
364 
366  void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
367  problem_ = problem;
368  }
369 
371  void setParameters (const Teuchos::RCP<Teuchos::ParameterList> &params);
372 
379  virtual void setUserConvStatusTest(
380  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &userConvStatusTest
381  );
382 
384 
386 
387 
391  void reset( const ResetType type ) { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
393 
395 
396 
414  ReturnType solve();
415 
417 
420 
422  std::string description() const;
423 
425 
426  private:
427 
442  bool checkStatusTest();
443 
445  Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
446 
447  // Output manager.
448  Teuchos::RCP<OutputManager<ScalarType> > printer_;
449  Teuchos::RCP<std::ostream> outputStream_;
450 
451  // Status tests.
452  Teuchos::RCP<StatusTest<ScalarType,MV,OP> > userConvStatusTest_;
453  Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
454  Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
455  Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
456  Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > impConvTest_, expConvTest_;
457  Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
458 
459  // Orthogonalization manager.
460  Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > ortho_;
461 
462  // Current parameter list.
463  Teuchos::RCP<Teuchos::ParameterList> params_;
464 
465  // Default solver values.
466  static const MagnitudeType convtol_default_;
467  static const MagnitudeType orthoKappa_default_;
468  static const int maxRestarts_default_;
469  static const int maxIters_default_;
470  static const bool showMaxResNormOnly_default_;
471  static const int blockSize_default_;
472  static const int numBlocks_default_;
473  static const int verbosity_default_;
474  static const int outputStyle_default_;
475  static const int outputFreq_default_;
476  static const int defQuorum_default_;
477  static const std::string impResScale_default_;
478  static const std::string expResScale_default_;
479  static const std::string label_default_;
480  static const std::string orthoType_default_;
481  static const Teuchos::RCP<std::ostream> outputStream_default_;
482 
483  // Current solver values.
484  MagnitudeType convtol_, orthoKappa_, achievedTol_;
485  int maxRestarts_, maxIters_, numIters_;
486  int blockSize_, numBlocks_, verbosity_, outputStyle_, outputFreq_, defQuorum_;
487  bool showMaxResNormOnly_;
488  std::string orthoType_;
489  std::string impResScale_, expResScale_;
490 
491  // Timers.
492  std::string label_;
493  Teuchos::RCP<Teuchos::Time> timerSolve_;
494 
495  // Internal state variables.
496  bool isSet_, isSTSet_, expResTest_;
497  bool loaDetected_;
498  };
499 
500 
501 // Default solver values.
502 template<class ScalarType, class MV, class OP>
503 const typename PseudoBlockGmresSolMgr<ScalarType,MV,OP>::MagnitudeType PseudoBlockGmresSolMgr<ScalarType,MV,OP>::convtol_default_ = 1e-8;
504 
505 template<class ScalarType, class MV, class OP>
506 const typename PseudoBlockGmresSolMgr<ScalarType,MV,OP>::MagnitudeType PseudoBlockGmresSolMgr<ScalarType,MV,OP>::orthoKappa_default_ = -1.0;
507 
508 template<class ScalarType, class MV, class OP>
510 
511 template<class ScalarType, class MV, class OP>
513 
514 template<class ScalarType, class MV, class OP>
516 
517 template<class ScalarType, class MV, class OP>
519 
520 template<class ScalarType, class MV, class OP>
522 
523 template<class ScalarType, class MV, class OP>
525 
526 template<class ScalarType, class MV, class OP>
528 
529 template<class ScalarType, class MV, class OP>
531 
532 template<class ScalarType, class MV, class OP>
534 
535 template<class ScalarType, class MV, class OP>
536 const std::string PseudoBlockGmresSolMgr<ScalarType,MV,OP>::impResScale_default_ = "Norm of Preconditioned Initial Residual";
537 
538 template<class ScalarType, class MV, class OP>
539 const std::string PseudoBlockGmresSolMgr<ScalarType,MV,OP>::expResScale_default_ = "Norm of Initial Residual";
540 
541 template<class ScalarType, class MV, class OP>
543 
544 template<class ScalarType, class MV, class OP>
546 
547 template<class ScalarType, class MV, class OP>
548 const Teuchos::RCP<std::ostream> PseudoBlockGmresSolMgr<ScalarType,MV,OP>::outputStream_default_ = Teuchos::rcp(&std::cout,false);
549 
550 
551 // Empty Constructor
552 template<class ScalarType, class MV, class OP>
554  outputStream_(outputStream_default_),
555  convtol_(convtol_default_),
556  orthoKappa_(orthoKappa_default_),
557  achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
558  maxRestarts_(maxRestarts_default_),
559  maxIters_(maxIters_default_),
560  numIters_(0),
561  blockSize_(blockSize_default_),
562  numBlocks_(numBlocks_default_),
563  verbosity_(verbosity_default_),
564  outputStyle_(outputStyle_default_),
565  outputFreq_(outputFreq_default_),
566  defQuorum_(defQuorum_default_),
567  showMaxResNormOnly_(showMaxResNormOnly_default_),
568  orthoType_(orthoType_default_),
569  impResScale_(impResScale_default_),
570  expResScale_(expResScale_default_),
571  label_(label_default_),
572  isSet_(false),
573  isSTSet_(false),
574  expResTest_(false),
575  loaDetected_(false)
576 {}
577 
578 // Basic Constructor
579 template<class ScalarType, class MV, class OP>
582  const Teuchos::RCP<Teuchos::ParameterList> &pl) :
583  problem_(problem),
584  outputStream_(outputStream_default_),
585  convtol_(convtol_default_),
586  orthoKappa_(orthoKappa_default_),
587  achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
588  maxRestarts_(maxRestarts_default_),
589  maxIters_(maxIters_default_),
590  numIters_(0),
591  blockSize_(blockSize_default_),
592  numBlocks_(numBlocks_default_),
593  verbosity_(verbosity_default_),
594  outputStyle_(outputStyle_default_),
595  outputFreq_(outputFreq_default_),
596  defQuorum_(defQuorum_default_),
597  showMaxResNormOnly_(showMaxResNormOnly_default_),
598  orthoType_(orthoType_default_),
599  impResScale_(impResScale_default_),
600  expResScale_(expResScale_default_),
601  label_(label_default_),
602  isSet_(false),
603  isSTSet_(false),
604  expResTest_(false),
605  loaDetected_(false)
606 {
607  TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument, "Problem not given to solver manager.");
608 
609  // If the parameter list pointer is null, then set the current parameters to the default parameter list.
610  if (!is_null(pl)) {
611  // Set the parameters using the list that was passed in.
612  setParameters( pl );
613  }
614 }
615 
616 template<class ScalarType, class MV, class OP>
617 void
619 setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params)
620 {
621  using Teuchos::ParameterList;
622  using Teuchos::parameterList;
623  using Teuchos::rcp;
624  using Teuchos::rcp_dynamic_cast;
625 
626  // Create the internal parameter list if one doesn't already exist.
627  if (params_ == Teuchos::null) {
628  params_ = parameterList (*getValidParameters ());
629  } else {
630  params->validateParameters (*getValidParameters ());
631  }
632 
633  // Check for maximum number of restarts
634  if (params->isParameter ("Maximum Restarts")) {
635  maxRestarts_ = params->get ("Maximum Restarts", maxRestarts_default_);
636 
637  // Update parameter in our list.
638  params_->set ("Maximum Restarts", maxRestarts_);
639  }
640 
641  // Check for maximum number of iterations
642  if (params->isParameter ("Maximum Iterations")) {
643  maxIters_ = params->get ("Maximum Iterations", maxIters_default_);
644 
645  // Update parameter in our list and in status test.
646  params_->set ("Maximum Iterations", maxIters_);
647  if (! maxIterTest_.is_null ()) {
648  maxIterTest_->setMaxIters (maxIters_);
649  }
650  }
651 
652  // Check for blocksize
653  if (params->isParameter ("Block Size")) {
654  blockSize_ = params->get ("Block Size", blockSize_default_);
655  TEUCHOS_TEST_FOR_EXCEPTION(
656  blockSize_ <= 0, std::invalid_argument,
657  "Belos::PseudoBlockGmresSolMgr::setParameters: "
658  "The \"Block Size\" parameter must be strictly positive, "
659  "but you specified a value of " << blockSize_ << ".");
660 
661  // Update parameter in our list.
662  params_->set ("Block Size", blockSize_);
663  }
664 
665  // Check for the maximum number of blocks.
666  if (params->isParameter ("Num Blocks")) {
667  numBlocks_ = params->get ("Num Blocks", numBlocks_default_);
668  TEUCHOS_TEST_FOR_EXCEPTION(
669  numBlocks_ <= 0, std::invalid_argument,
670  "Belos::PseudoBlockGmresSolMgr::setParameters: "
671  "The \"Num Blocks\" parameter must be strictly positive, "
672  "but you specified a value of " << numBlocks_ << ".");
673 
674  // Update parameter in our list.
675  params_->set ("Num Blocks", numBlocks_);
676  }
677 
678  // Check to see if the timer label changed.
679  if (params->isParameter ("Timer Label")) {
680  const std::string tempLabel = params->get ("Timer Label", label_default_);
681 
682  // Update parameter in our list and solver timer
683  if (tempLabel != label_) {
684  label_ = tempLabel;
685  params_->set ("Timer Label", label_);
686  const std::string solveLabel =
687  label_ + ": PseudoBlockGmresSolMgr total solve time";
688 #ifdef BELOS_TEUCHOS_TIME_MONITOR
689  timerSolve_ = Teuchos::TimeMonitor::getNewCounter (solveLabel);
690 #endif // BELOS_TEUCHOS_TIME_MONITOR
691  if (ortho_ != Teuchos::null) {
692  ortho_->setLabel( label_ );
693  }
694  }
695  }
696 
697  // Check if the orthogonalization changed.
698  if (params->isParameter ("Orthogonalization")) {
699  std::string tempOrthoType = params->get ("Orthogonalization", orthoType_default_);
700 #ifdef HAVE_BELOS_TSQR
701  TEUCHOS_TEST_FOR_EXCEPTION(
702  tempOrthoType != "DGKS" && tempOrthoType != "ICGS" &&
703  tempOrthoType != "IMGS" && tempOrthoType != "TSQR",
704  std::invalid_argument,
705  "Belos::PseudoBlockGmresSolMgr::setParameters: "
706  "The \"Orthogonalization\" parameter must be one of \"DGKS\", \"ICGS\", "
707  "\"IMGS\", or \"TSQR\".");
708 #else
709  TEUCHOS_TEST_FOR_EXCEPTION(
710  tempOrthoType != "DGKS" && tempOrthoType != "ICGS" &&
711  tempOrthoType != "IMGS",
712  std::invalid_argument,
713  "Belos::PseudoBlockGmresSolMgr::setParameters: "
714  "The \"Orthogonalization\" parameter must be one of \"DGKS\", \"ICGS\", "
715  "or \"IMGS\".");
716 #endif // HAVE_BELOS_TSQR
717 
718  if (tempOrthoType != orthoType_) {
719  orthoType_ = tempOrthoType;
720  // Create orthogonalization manager
721  if (orthoType_ == "DGKS") {
722  typedef DGKSOrthoManager<ScalarType, MV, OP> ortho_type;
723  if (orthoKappa_ <= 0) {
724  ortho_ = rcp (new ortho_type (label_));
725  }
726  else {
727  ortho_ = rcp (new ortho_type (label_));
728  rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
729  }
730  }
731  else if (orthoType_ == "ICGS") {
732  typedef ICGSOrthoManager<ScalarType, MV, OP> ortho_type;
733  ortho_ = rcp (new ortho_type (label_));
734  }
735  else if (orthoType_ == "IMGS") {
736  typedef IMGSOrthoManager<ScalarType, MV, OP> ortho_type;
737  ortho_ = rcp (new ortho_type (label_));
738  }
739 #ifdef HAVE_BELOS_TSQR
740  else if (orthoType_ == "TSQR") {
741  typedef TsqrMatOrthoManager<ScalarType, MV, OP> ortho_type;
742  ortho_ = rcp (new ortho_type (label_));
743  }
744 #endif // HAVE_BELOS_TSQR
745  }
746  }
747 
748  // Check which orthogonalization constant to use.
749  if (params->isParameter ("Orthogonalization Constant")) {
750  orthoKappa_ = params->get ("Orthogonalization Constant", orthoKappa_default_);
751 
752  // Update parameter in our list.
753  params_->set ("Orthogonalization Constant", orthoKappa_);
754  if (orthoType_ == "DGKS") {
755  if (orthoKappa_ > 0 && ! ortho_.is_null ()) {
756  typedef DGKSOrthoManager<ScalarType, MV, OP> ortho_type;
757  rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
758  }
759  }
760  }
761 
762  // Check for a change in verbosity level
763  if (params->isParameter ("Verbosity")) {
764  if (Teuchos::isParameterType<int> (*params, "Verbosity")) {
765  verbosity_ = params->get ("Verbosity", verbosity_default_);
766  } else {
767  verbosity_ = (int) Teuchos::getParameter<Belos::MsgType> (*params, "Verbosity");
768  }
769 
770  // Update parameter in our list.
771  params_->set ("Verbosity", verbosity_);
772  if (! printer_.is_null ()) {
773  printer_->setVerbosity (verbosity_);
774  }
775  }
776 
777  // Check for a change in output style.
778  if (params->isParameter ("Output Style")) {
779  if (Teuchos::isParameterType<int> (*params, "Output Style")) {
780  outputStyle_ = params->get ("Output Style", outputStyle_default_);
781  } else {
782  outputStyle_ = (int) Teuchos::getParameter<Belos::OutputType> (*params, "Output Style");
783  }
784 
785  // Update parameter in our list.
786  params_->set ("Output Style", verbosity_);
787  if (! outputTest_.is_null ()) {
788  isSTSet_ = false;
789  }
790  }
791 
792  // output stream
793  if (params->isParameter ("Output Stream")) {
794  outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> > (*params, "Output Stream");
795 
796  // Update parameter in our list.
797  params_->set("Output Stream", outputStream_);
798  if (! printer_.is_null ()) {
799  printer_->setOStream (outputStream_);
800  }
801  }
802 
803  // frequency level
804  if (verbosity_ & Belos::StatusTestDetails) {
805  if (params->isParameter ("Output Frequency")) {
806  outputFreq_ = params->get ("Output Frequency", outputFreq_default_);
807  }
808 
809  // Update parameter in out list and output status test.
810  params_->set ("Output Frequency", outputFreq_);
811  if (! outputTest_.is_null ()) {
812  outputTest_->setOutputFrequency (outputFreq_);
813  }
814  }
815 
816  // Create output manager if we need to.
817  if (printer_.is_null ()) {
818  printer_ = rcp (new OutputManager<ScalarType> (verbosity_, outputStream_));
819  }
820 
821  // Convergence
822 
823  // Check for convergence tolerance
824  if (params->isParameter ("Convergence Tolerance")) {
825  convtol_ = params->get ("Convergence Tolerance", convtol_default_);
826 
827  // Update parameter in our list and residual tests.
828  params_->set ("Convergence Tolerance", convtol_);
829  if (! impConvTest_.is_null ()) {
830  impConvTest_->setTolerance (convtol_);
831  }
832  if (! expConvTest_.is_null ()) {
833  expConvTest_->setTolerance (convtol_);
834  }
835  }
836 
837  // Check for a change in scaling, if so we need to build new residual tests.
838  if (params->isParameter ("Implicit Residual Scaling")) {
839  const std::string tempImpResScale =
840  Teuchos::getParameter<std::string> (*params, "Implicit Residual Scaling");
841 
842  // Only update the scaling if it's different.
843  if (impResScale_ != tempImpResScale) {
844  Belos::ScaleType impResScaleType = convertStringToScaleType (tempImpResScale);
845  impResScale_ = tempImpResScale;
846 
847  // Update parameter in our list and residual tests
848  params_->set ("Implicit Residual Scaling", impResScale_);
849  if (! impConvTest_.is_null ()) {
850  try {
851  impConvTest_->defineScaleForm (impResScaleType, Belos::TwoNorm);
852  }
853  catch (std::exception& e) {
854  // Make sure the convergence test gets constructed again.
855  isSTSet_ = false;
856  }
857  }
858  }
859  }
860 
861  if (params->isParameter ("Explicit Residual Scaling")) {
862  const std::string tempExpResScale =
863  Teuchos::getParameter<std::string> (*params, "Explicit Residual Scaling");
864 
865  // Only update the scaling if it's different.
866  if (expResScale_ != tempExpResScale) {
867  Belos::ScaleType expResScaleType = convertStringToScaleType (tempExpResScale);
868  expResScale_ = tempExpResScale;
869 
870  // Update parameter in our list and residual tests
871  params_->set ("Explicit Residual Scaling", expResScale_);
872  if (! expConvTest_.is_null ()) {
873  try {
874  expConvTest_->defineScaleForm (expResScaleType, Belos::TwoNorm);
875  }
876  catch (std::exception& e) {
877  // Make sure the convergence test gets constructed again.
878  isSTSet_ = false;
879  }
880  }
881  }
882  }
883 
884 
885  if (params->isParameter ("Show Maximum Residual Norm Only")) {
886  showMaxResNormOnly_ =
887  Teuchos::getParameter<bool> (*params, "Show Maximum Residual Norm Only");
888 
889  // Update parameter in our list and residual tests
890  params_->set ("Show Maximum Residual Norm Only", showMaxResNormOnly_);
891  if (! impConvTest_.is_null ()) {
892  impConvTest_->setShowMaxResNormOnly (showMaxResNormOnly_);
893  }
894  if (! expConvTest_.is_null ()) {
895  expConvTest_->setShowMaxResNormOnly (showMaxResNormOnly_);
896  }
897  }
898 
899  // Create status tests if we need to.
900 
901  // Get the deflation quorum, or number of converged systems before deflation is allowed
902  if (params->isParameter("Deflation Quorum")) {
903  defQuorum_ = params->get("Deflation Quorum", defQuorum_);
904  TEUCHOS_TEST_FOR_EXCEPTION(
905  defQuorum_ > blockSize_, std::invalid_argument,
906  "Belos::PseudoBlockGmresSolMgr::setParameters: "
907  "The \"Deflation Quorum\" parameter (= " << defQuorum_ << ") must not be "
908  "larger than \"Block Size\" (= " << blockSize_ << ").");
909  params_->set ("Deflation Quorum", defQuorum_);
910  if (! impConvTest_.is_null ()) {
911  impConvTest_->setQuorum (defQuorum_);
912  }
913  if (! expConvTest_.is_null ()) {
914  expConvTest_->setQuorum (defQuorum_);
915  }
916  }
917 
918  // Create orthogonalization manager if we need to.
919  if (ortho_.is_null ()) {
920  if (orthoType_ == "DGKS") {
921  typedef DGKSOrthoManager<ScalarType, MV, OP> ortho_type;
922  if (orthoKappa_ <= 0) {
923  ortho_ = rcp (new ortho_type (label_));
924  }
925  else {
926  ortho_ = rcp (new ortho_type (label_));
927  rcp_dynamic_cast<ortho_type> (ortho_)->setDepTol (orthoKappa_);
928  }
929  }
930  else if (orthoType_ == "ICGS") {
931  typedef ICGSOrthoManager<ScalarType, MV, OP> ortho_type;
932  ortho_ = rcp (new ortho_type (label_));
933  }
934  else if (orthoType_ == "IMGS") {
935  typedef IMGSOrthoManager<ScalarType, MV, OP> ortho_type;
936  ortho_ = rcp (new ortho_type (label_));
937  }
938 #ifdef HAVE_BELOS_TSQR
939  else if (orthoType_ == "TSQR") {
940  typedef TsqrMatOrthoManager<ScalarType, MV, OP> ortho_type;
941  ortho_ = rcp (new ortho_type (label_));
942  }
943 #endif // HAVE_BELOS_TSQR
944  else {
945 #ifdef HAVE_BELOS_TSQR
946  TEUCHOS_TEST_FOR_EXCEPTION(
947  orthoType_ != "ICGS" && orthoType_ != "DGKS" &&
948  orthoType_ != "IMGS" && orthoType_ != "TSQR",
949  std::logic_error,
950  "Belos::PseudoBlockGmresSolMgr::setParameters(): "
951  "Invalid orthogonalization type \"" << orthoType_ << "\".");
952 #else
953  TEUCHOS_TEST_FOR_EXCEPTION(
954  orthoType_ != "ICGS" && orthoType_ != "DGKS" &&
955  orthoType_ != "IMGS",
956  std::logic_error,
957  "Belos::PseudoBlockGmresSolMgr::setParameters(): "
958  "Invalid orthogonalization type \"" << orthoType_ << "\".");
959 #endif // HAVE_BELOS_TSQR
960  }
961  }
962 
963  // Create the timer if we need to.
964  if (timerSolve_ == Teuchos::null) {
965  std::string solveLabel = label_ + ": PseudoBlockGmresSolMgr total solve time";
966 #ifdef BELOS_TEUCHOS_TIME_MONITOR
967  timerSolve_ = Teuchos::TimeMonitor::getNewCounter (solveLabel);
968 #endif
969  }
970 
971  // Inform the solver manager that the current parameters were set.
972  isSet_ = true;
973 }
974 
975 
976 template<class ScalarType, class MV, class OP>
977 void
979  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &userConvStatusTest
980  )
981 {
982  userConvStatusTest_ = userConvStatusTest;
983 }
984 
985 
986 template<class ScalarType, class MV, class OP>
987 Teuchos::RCP<const Teuchos::ParameterList>
989 {
990  static Teuchos::RCP<const Teuchos::ParameterList> validPL;
991  if (is_null(validPL)) {
992  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
993  // Set all the valid parameters and their default values.
994  pl= Teuchos::rcp( new Teuchos::ParameterList() );
995  pl->set("Convergence Tolerance", convtol_default_,
996  "The relative residual tolerance that needs to be achieved by the\n"
997  "iterative solver in order for the linear system to be declared converged.");
998  pl->set("Maximum Restarts", maxRestarts_default_,
999  "The maximum number of restarts allowed for each\n"
1000  "set of RHS solved.");
1001  pl->set("Maximum Iterations", maxIters_default_,
1002  "The maximum number of block iterations allowed for each\n"
1003  "set of RHS solved.");
1004  pl->set("Num Blocks", numBlocks_default_,
1005  "The maximum number of vectors allowed in the Krylov subspace\n"
1006  "for each set of RHS solved.");
1007  pl->set("Block Size", blockSize_default_,
1008  "The number of RHS solved simultaneously.");
1009  pl->set("Verbosity", verbosity_default_,
1010  "What type(s) of solver information should be outputted\n"
1011  "to the output stream.");
1012  pl->set("Output Style", outputStyle_default_,
1013  "What style is used for the solver information outputted\n"
1014  "to the output stream.");
1015  pl->set("Output Frequency", outputFreq_default_,
1016  "How often convergence information should be outputted\n"
1017  "to the output stream.");
1018  pl->set("Deflation Quorum", defQuorum_default_,
1019  "The number of linear systems that need to converge before\n"
1020  "they are deflated. This number should be <= block size.");
1021  pl->set("Output Stream", outputStream_default_,
1022  "A reference-counted pointer to the output stream where all\n"
1023  "solver output is sent.");
1024  pl->set("Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
1025  "When convergence information is printed, only show the maximum\n"
1026  "relative residual norm when the block size is greater than one.");
1027  pl->set("Implicit Residual Scaling", impResScale_default_,
1028  "The type of scaling used in the implicit residual convergence test.");
1029  pl->set("Explicit Residual Scaling", expResScale_default_,
1030  "The type of scaling used in the explicit residual convergence test.");
1031  pl->set("Timer Label", label_default_,
1032  "The string to use as a prefix for the timer labels.");
1033  // defaultParams_->set("Restart Timers", restartTimers_);
1034  pl->set("Orthogonalization", orthoType_default_,
1035  "The type of orthogonalization to use: DGKS, ICGS, IMGS.");
1036  pl->set("Orthogonalization Constant",orthoKappa_default_,
1037  "The constant used by DGKS orthogonalization to determine\n"
1038  "whether another step of classical Gram-Schmidt is necessary.");
1039  validPL = pl;
1040  }
1041  return validPL;
1042 }
1043 
1044 // Check the status test versus the defined linear problem
1045 template<class ScalarType, class MV, class OP>
1047 
1048  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
1049  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestGenResNorm_t;
1050  typedef Belos::StatusTestImpResNorm<ScalarType,MV,OP> StatusTestImpResNorm_t;
1051 
1052  // Basic test checks maximum iterations and native residual.
1053  maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
1054 
1055  // If there is a left preconditioner, we create a combined status test that checks the implicit
1056  // and then explicit residual norm to see if we have convergence.
1057  if ( !Teuchos::is_null(problem_->getLeftPrec()) ) {
1058  expResTest_ = true;
1059  }
1060 
1061  if (expResTest_) {
1062 
1063  // Implicit residual test, using the native residual to determine if convergence was achieved.
1064  Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
1065  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
1066  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
1067  tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1068  impConvTest_ = tmpImpConvTest;
1069 
1070  // Explicit residual test once the native residual is below the tolerance
1071  Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
1072  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
1073  tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit, Belos::TwoNorm );
1074  tmpExpConvTest->defineScaleForm( convertStringToScaleType(expResScale_), Belos::TwoNorm );
1075  tmpExpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1076  expConvTest_ = tmpExpConvTest;
1077 
1078  // The convergence test is a combination of the "cheap" implicit test and explicit test.
1079  convTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
1080  }
1081  else {
1082 
1083  // Implicit residual test, using the native residual to determine if convergence was achieved.
1084  // Use test that checks for loss of accuracy.
1085  Teuchos::RCP<StatusTestImpResNorm_t> tmpImpConvTest =
1086  Teuchos::rcp( new StatusTestImpResNorm_t( convtol_, defQuorum_ ) );
1087  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
1088  tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
1089  impConvTest_ = tmpImpConvTest;
1090 
1091  // Set the explicit and total convergence test to this implicit test that checks for accuracy loss.
1092  expConvTest_ = impConvTest_;
1093  convTest_ = impConvTest_;
1094  }
1095 
1096  if (nonnull(userConvStatusTest_) ) {
1097  // Override the overall convergence test with the users convergence test
1098  convTest_ = Teuchos::rcp(
1099  new StatusTestCombo_t( StatusTestCombo_t::SEQ, convTest_, userConvStatusTest_ ) );
1100  // NOTE: Above, you have to run the other convergence tests also because
1101  // the logic in this class depends on it. This is very unfortunate.
1102  }
1103 
1104  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
1105 
1106  // Create the status test output class.
1107  // This class manages and formats the output from the status test.
1108  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
1109  outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
1110 
1111  // Set the solver string for the output test
1112  std::string solverDesc = " Pseudo Block Gmres ";
1113  outputTest_->setSolverDesc( solverDesc );
1114 
1115 
1116  // The status test is now set.
1117  isSTSet_ = true;
1118 
1119  return false;
1120 }
1121 
1122 
1123 // solve()
1124 template<class ScalarType, class MV, class OP>
1126 
1127  // Set the current parameters if they were not set before.
1128  // NOTE: This may occur if the user generated the solver manager with the default constructor and
1129  // then didn't set any parameters using setParameters().
1130  if (!isSet_) { setParameters( params_ ); }
1131 
1132  Teuchos::BLAS<int,ScalarType> blas;
1133 
1134  TEUCHOS_TEST_FOR_EXCEPTION(!problem_->isProblemSet(),PseudoBlockGmresSolMgrLinearProblemFailure,
1135  "Belos::PseudoBlockGmresSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
1136 
1137  // Check if we have to create the status tests.
1138  if (!isSTSet_ || (!expResTest_ && !Teuchos::is_null(problem_->getLeftPrec())) ) {
1139  TEUCHOS_TEST_FOR_EXCEPTION( checkStatusTest(),PseudoBlockGmresSolMgrLinearProblemFailure,
1140  "Belos::BlockGmresSolMgr::solve(): Linear problem and requested status tests are incompatible.");
1141  }
1142 
1143  // Create indices for the linear systems to be solved.
1144  int startPtr = 0;
1145  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
1146  int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1147 
1148  std::vector<int> currIdx( numCurrRHS );
1149  blockSize_ = numCurrRHS;
1150  for (int i=0; i<numCurrRHS; ++i)
1151  { currIdx[i] = startPtr+i; }
1152 
1153  // Inform the linear problem of the current linear system to solve.
1154  problem_->setLSIndex( currIdx );
1155 
1157  // Parameter list
1158  Teuchos::ParameterList plist;
1159  plist.set("Num Blocks",numBlocks_);
1160 
1161  // Reset the status test.
1162  outputTest_->reset();
1163  loaDetected_ = false;
1164 
1165  // Assume convergence is achieved, then let any failed convergence set this to false.
1166  bool isConverged = true;
1167 
1169  // BlockGmres solver
1170 
1171  Teuchos::RCP<PseudoBlockGmresIter<ScalarType,MV,OP> > block_gmres_iter
1172  = Teuchos::rcp( new PseudoBlockGmresIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,ortho_,plist) );
1173 
1174  // Enter solve() iterations
1175  {
1176 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1177  Teuchos::TimeMonitor slvtimer(*timerSolve_);
1178 #endif
1179 
1180  while ( numRHS2Solve > 0 ) {
1181 
1182  // Reset the active / converged vectors from this block
1183  std::vector<int> convRHSIdx;
1184  std::vector<int> currRHSIdx( currIdx );
1185  currRHSIdx.resize(numCurrRHS);
1186 
1187  // Set the current number of blocks with the pseudo Gmres iteration.
1188  block_gmres_iter->setNumBlocks( numBlocks_ );
1189 
1190  // Reset the number of iterations.
1191  block_gmres_iter->resetNumIters();
1192 
1193  // Reset the number of calls that the status test output knows about.
1194  outputTest_->resetNumCalls();
1195 
1196  // Get a new state struct and initialize the solver.
1198 
1199  // Create the first block in the current Krylov basis for each right-hand side.
1200  std::vector<int> index(1);
1201  Teuchos::RCP<MV> tmpV, R_0 = MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1202  newState.V.resize( blockSize_ );
1203  newState.Z.resize( blockSize_ );
1204  for (int i=0; i<blockSize_; ++i) {
1205  index[0]=i;
1206  tmpV = MVT::CloneViewNonConst( *R_0, index );
1207 
1208  // Get a matrix to hold the orthonormalization coefficients.
1209  Teuchos::RCP<Teuchos::SerialDenseVector<int,ScalarType> > tmpZ
1210  = Teuchos::rcp( new Teuchos::SerialDenseVector<int,ScalarType>( 1 ));
1211 
1212  // Orthonormalize the new V_0
1213  int rank = ortho_->normalize( *tmpV, tmpZ );
1214  TEUCHOS_TEST_FOR_EXCEPTION(rank != 1, PseudoBlockGmresSolMgrOrthoFailure,
1215  "Belos::PseudoBlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors.");
1216 
1217  newState.V[i] = tmpV;
1218  newState.Z[i] = tmpZ;
1219  }
1220 
1221  newState.curDim = 0;
1222  block_gmres_iter->initialize(newState);
1223  int numRestarts = 0;
1224 
1225  while(1) {
1226 
1227  // tell block_gmres_iter to iterate
1228  try {
1229  block_gmres_iter->iterate();
1230 
1232  //
1233  // check convergence first
1234  //
1236  if ( convTest_->getStatus() == Passed ) {
1237 
1238  if ( expConvTest_->getLOADetected() ) {
1239  // Oops! There was a loss of accuracy (LOA) for one or
1240  // more right-hand sides. That means the implicit
1241  // (a.k.a. "native") residuals claim convergence,
1242  // whereas the explicit (hence expConvTest_, i.e.,
1243  // "explicit convergence test") residuals have not
1244  // converged.
1245  //
1246  // We choose to deal with this situation by deflating
1247  // out the affected right-hand sides and moving on.
1248  loaDetected_ = true;
1249  printer_->stream(Warnings) <<
1250  "Belos::PseudoBlockGmresSolMgr::solve(): Warning! Solver has experienced a loss of accuracy!" << std::endl;
1251  isConverged = false;
1252  }
1253 
1254  // Figure out which linear systems converged.
1255  std::vector<int> convIdx = expConvTest_->convIndices();
1256 
1257  // If the number of converged linear systems is equal to the
1258  // number of current linear systems, then we are done with this block.
1259  if (convIdx.size() == currRHSIdx.size())
1260  break; // break from while(1){block_gmres_iter->iterate()}
1261 
1262  // Get a new state struct and initialize the solver.
1264 
1265  // Inform the linear problem that we are finished with this current linear system.
1266  problem_->setCurrLS();
1267 
1268  // Get the state.
1269  PseudoBlockGmresIterState<ScalarType,MV> oldState = block_gmres_iter->getState();
1270  int curDim = oldState.curDim;
1271 
1272  // Get a new state struct and reset currRHSIdx to have the right-hand sides that
1273  // are left to converge for this block.
1274  int have = 0;
1275  std::vector<int> oldRHSIdx( currRHSIdx );
1276  std::vector<int> defRHSIdx;
1277  for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
1278  bool found = false;
1279  for (unsigned int j=0; j<convIdx.size(); ++j) {
1280  if (currRHSIdx[i] == convIdx[j]) {
1281  found = true;
1282  break;
1283  }
1284  }
1285  if (found) {
1286  defRHSIdx.push_back( i );
1287  }
1288  else {
1289  defState.V.push_back( Teuchos::rcp_const_cast<MV>( oldState.V[i] ) );
1290  defState.Z.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseVector<int,ScalarType> >( oldState.Z[i] ) );
1291  defState.H.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseMatrix<int,ScalarType> >( oldState.H[i] ) );
1292  defState.sn.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseVector<int,ScalarType> >( oldState.sn[i] ) );
1293  defState.cs.push_back( Teuchos::rcp_const_cast<Teuchos::SerialDenseVector<int,MagnitudeType> >(oldState.cs[i] ) );
1294  currRHSIdx[have] = currRHSIdx[i];
1295  have++;
1296  }
1297  }
1298  defRHSIdx.resize(currRHSIdx.size()-have);
1299  currRHSIdx.resize(have);
1300 
1301  // Compute the current solution that needs to be deflated if this solver has taken any steps.
1302  if (curDim) {
1303  Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1304  Teuchos::RCP<MV> defUpdate = MVT::CloneViewNonConst( *update, defRHSIdx );
1305 
1306  // Set the deflated indices so we can update the solution.
1307  problem_->setLSIndex( convIdx );
1308 
1309  // Update the linear problem.
1310  problem_->updateSolution( defUpdate, true );
1311  }
1312 
1313  // Set the remaining indices after deflation.
1314  problem_->setLSIndex( currRHSIdx );
1315 
1316  // Set the dimension of the subspace, which is the same as the old subspace size.
1317  defState.curDim = curDim;
1318 
1319  // Initialize the solver with the deflated system.
1320  block_gmres_iter->initialize(defState);
1321  }
1323  //
1324  // check for maximum iterations
1325  //
1327  else if ( maxIterTest_->getStatus() == Passed ) {
1328  // we don't have convergence
1329  isConverged = false;
1330  break; // break from while(1){block_gmres_iter->iterate()}
1331  }
1333  //
1334  // check for restarting, i.e. the subspace is full
1335  //
1337  else if ( block_gmres_iter->getCurSubspaceDim() == block_gmres_iter->getMaxSubspaceDim() ) {
1338 
1339  if ( numRestarts >= maxRestarts_ ) {
1340  isConverged = false;
1341  break; // break from while(1){block_gmres_iter->iterate()}
1342  }
1343  numRestarts++;
1344 
1345  printer_->stream(Debug) << " Performing restart number " << numRestarts << " of " << maxRestarts_ << std::endl << std::endl;
1346 
1347  // Update the linear problem.
1348  Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1349  problem_->updateSolution( update, true );
1350 
1351  // Get the state.
1352  PseudoBlockGmresIterState<ScalarType,MV> oldState = block_gmres_iter->getState();
1353 
1354  // Set the new state.
1356  newstate.V.resize(currRHSIdx.size());
1357  newstate.Z.resize(currRHSIdx.size());
1358 
1359  // Compute the restart vectors
1360  // NOTE: Force the linear problem to update the current residual since the solution was updated.
1361  R_0 = MVT::Clone( *(problem_->getInitPrecResVec()), currRHSIdx.size() );
1362  problem_->computeCurrPrecResVec( &*R_0 );
1363  for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
1364  index[0] = i; // index(1) vector declared on line 891
1365 
1366  tmpV = MVT::CloneViewNonConst( *R_0, index );
1367 
1368  // Get a matrix to hold the orthonormalization coefficients.
1369  Teuchos::RCP<Teuchos::SerialDenseVector<int,ScalarType> > tmpZ
1370  = Teuchos::rcp( new Teuchos::SerialDenseVector<int,ScalarType>( 1 ));
1371 
1372  // Orthonormalize the new V_0
1373  int rank = ortho_->normalize( *tmpV, tmpZ );
1374  TEUCHOS_TEST_FOR_EXCEPTION(rank != 1 ,PseudoBlockGmresSolMgrOrthoFailure,
1375  "Belos::PseudoBlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors after the restart.");
1376 
1377  newstate.V[i] = tmpV;
1378  newstate.Z[i] = tmpZ;
1379  }
1380 
1381  // Initialize the solver.
1382  newstate.curDim = 0;
1383  block_gmres_iter->initialize(newstate);
1384 
1385  } // end of restarting
1386 
1388  //
1389  // we returned from iterate(), but none of our status tests Passed.
1390  // something is wrong, and it is probably our fault.
1391  //
1393 
1394  else {
1395  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
1396  "Belos::PseudoBlockGmresSolMgr::solve(): Invalid return from PseudoBlockGmresIter::iterate().");
1397  }
1398  }
1399  catch (const PseudoBlockGmresIterOrthoFailure &e) {
1400 
1401  // Try to recover the most recent least-squares solution
1402  block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
1403 
1404  // Check to see if the most recent least-squares solution yielded convergence.
1405  sTest_->checkStatus( &*block_gmres_iter );
1406  if (convTest_->getStatus() != Passed)
1407  isConverged = false;
1408  break;
1409  }
1410  catch (const std::exception &e) {
1411  printer_->stream(Errors) << "Error! Caught std::exception in PseudoBlockGmresIter::iterate() at iteration "
1412  << block_gmres_iter->getNumIters() << std::endl
1413  << e.what() << std::endl;
1414  throw;
1415  }
1416  }
1417 
1418  // Compute the current solution.
1419  // Update the linear problem.
1420  if (nonnull(userConvStatusTest_)) {
1421  //std::cout << "\nnonnull(userConvStatusTest_)\n";
1422  Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1423  problem_->updateSolution( update, true );
1424  }
1425  else if (nonnull(expConvTest_->getSolution())) {
1426  //std::cout << "\nexpConvTest_->getSolution()\n";
1427  Teuchos::RCP<MV> newX = expConvTest_->getSolution();
1428  Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1429  MVT::MvAddMv( 0.0, *newX, 1.0, *newX, *curX );
1430  }
1431  else {
1432  //std::cout << "\nblock_gmres_iter->getCurrentUpdate()\n";
1433  Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1434  problem_->updateSolution( update, true );
1435  }
1436 
1437  // Inform the linear problem that we are finished with this block linear system.
1438  problem_->setCurrLS();
1439 
1440  // Update indices for the linear systems to be solved.
1441  startPtr += numCurrRHS;
1442  numRHS2Solve -= numCurrRHS;
1443  if ( numRHS2Solve > 0 ) {
1444  numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1445 
1446  blockSize_ = numCurrRHS;
1447  currIdx.resize( numCurrRHS );
1448  for (int i=0; i<numCurrRHS; ++i)
1449  { currIdx[i] = startPtr+i; }
1450 
1451  // Adapt the status test quorum if we need to.
1452  if (defQuorum_ > blockSize_) {
1453  if (impConvTest_ != Teuchos::null)
1454  impConvTest_->setQuorum( blockSize_ );
1455  if (expConvTest_ != Teuchos::null)
1456  expConvTest_->setQuorum( blockSize_ );
1457  }
1458 
1459  // Set the next indices.
1460  problem_->setLSIndex( currIdx );
1461  }
1462  else {
1463  currIdx.resize( numRHS2Solve );
1464  }
1465 
1466  }// while ( numRHS2Solve > 0 )
1467 
1468  }
1469 
1470  // print final summary
1471  sTest_->print( printer_->stream(FinalSummary) );
1472 
1473  // print timing information
1474 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1475  // Calling summarize() can be expensive, so don't call unless the
1476  // user wants to print out timing details. summarize() will do all
1477  // the work even if it's passed a "black hole" output stream.
1478  if (verbosity_ & TimingDetails)
1479  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1480 #endif
1481 
1482  // get iteration information for this solve
1483  numIters_ = maxIterTest_->getNumIters();
1484 
1485  // Save the convergence test value ("achieved tolerance") for this
1486  // solve. For this solver, convTest_ may either be a single
1487  // residual norm test, or a combination of two residual norm tests.
1488  // In the latter case, the master convergence test convTest_ is a
1489  // SEQ combo of the implicit resp. explicit tests. If the implicit
1490  // test never passes, then the explicit test won't ever be executed.
1491  // This manifests as expConvTest_->getTestValue()->size() < 1. We
1492  // deal with this case by using the values returned by
1493  // impConvTest_->getTestValue().
1494  {
1495  // We'll fetch the vector of residual norms one way or the other.
1496  const std::vector<MagnitudeType>* pTestValues = NULL;
1497  if (expResTest_) {
1498  pTestValues = expConvTest_->getTestValue();
1499  if (pTestValues == NULL || pTestValues->size() < 1) {
1500  pTestValues = impConvTest_->getTestValue();
1501  }
1502  }
1503  else {
1504  // Only the implicit residual norm test is being used.
1505  pTestValues = impConvTest_->getTestValue();
1506  }
1507  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1508  "Belos::PseudoBlockGmresSolMgr::solve(): The implicit convergence test's "
1509  "getTestValue() method returned NULL. Please report this bug to the "
1510  "Belos developers.");
1511  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1512  "Belos::PseudoBlockGmresSolMgr::solve(): The implicit convergence test's "
1513  "getTestValue() method returned a vector of length zero. Please report "
1514  "this bug to the Belos developers.");
1515 
1516  // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
1517  // achieved tolerances for all vectors in the current solve(), or
1518  // just for the vectors from the last deflation?
1519  achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1520  }
1521 
1522  if (!isConverged || loaDetected_) {
1523  return Unconverged; // return from PseudoBlockGmresSolMgr::solve()
1524  }
1525  return Converged; // return from PseudoBlockGmresSolMgr::solve()
1526 }
1527 
1528 // This method requires the solver manager to return a std::string that describes itself.
1529 template<class ScalarType, class MV, class OP>
1531 {
1532  std::ostringstream oss;
1533  oss << "Belos::PseudoBlockGmresSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
1534  oss << "{";
1535  oss << "Ortho Type='"<<orthoType_<<"\', Block Size=" <<blockSize_;
1536  oss << ", Num Blocks="<<numBlocks_<< ", Max Restarts=" << maxRestarts_;
1537  oss << "}";
1538  return oss.str();
1539 }
1540 
1541 } // end Belos namespace
1542 
1543 #endif /* BELOS_PSEUDO_BLOCK_GMRES_SOLMGR_HPP */
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition: BelosTypes.cpp:93
std::vector< Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > > H
The current Hessenberg matrix.
Collection of types and exceptions used within the Belos solvers.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
The current parameters for this solver.
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.
virtual void setUserConvStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &userConvStatusTest)
Set a custom status test.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters the solver manager should use to solve the linear problem.
ScaleType
The type of scaling to use on the residual norm value.
Definition: BelosTypes.hpp:119
Convergence test using the implicit residual norm(s), with an explicit residual norm(s) check for los...
PseudoBlockGmresSolMgrOrthoFailure(const std::string &what_arg)
A factory class for generating StatusTestOutput objects.
std::vector< Teuchos::RCP< const MV > > V
The current Krylov basis.
An implementation of StatusTestResNorm using a family of residual norms.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
Belos::StatusTest class for specifying a maximum number of iterations.
A pure virtual class for defining the status tests for the Belos iterative solvers.
Structure to contain pointers to PseudoBlockGmresIter state variables.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
A factory class for generating StatusTestOutput objects.
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class...
A Belos::StatusTest class for specifying a maximum number of iterations.
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:200
Pure virtual base class which describes the basic interface for a solver manager. ...
PseudoBlockGmresSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, MagnitudeType > > > cs
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
Interface to standard and "pseudoblock" GMRES.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
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.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
bool isLOADetected() const
Whether a "loss of accuracy" was detected during the last solve().
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
std::vector< Teuchos::RCP< const Teuchos::SerialDenseVector< int, ScalarType > > > Z
The current right-hand side of the least squares system RY = Z.
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.
Belos concrete class for performing the pseudo-block GMRES iteration.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest for specifying an implicit residual norm stopping criteria that checks for loss of ...
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
A class for extending the status testing capabilities of Belos via logical combinations.
Orthogonalization manager based on Tall Skinny QR (TSQR)
Class which defines basic traits for the operator type.
int curDim
The current dimension of the reduction.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem to solve.
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.
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver&#39;s iterate() routine unti...
MatOrthoManager subclass using TSQR or DGKS.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
A list of valid default parameters for this solver.
int getNumIters() const
Iteration count for the most recent call to solve().
Belos header file which uses auto-configuration information to include necessary C++ headers...
std::string description() const
Return a description of the pseudoblock GMRES solver manager.
This class implements the pseudo-block GMRES iteration, where a block Krylov subspace is constructed ...
PseudoBlockGmresIterOrthoFailure is thrown when the orthogonalization manager is unable to generate o...
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
PseudoBlockGmresSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate...