Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosBlockGmresSolMgr.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_BLOCK_GMRES_SOLMGR_HPP
43 #define BELOS_BLOCK_GMRES_SOLMGR_HPP
44 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosTypes.hpp"
51 
52 #include "BelosLinearProblem.hpp"
53 #include "BelosSolverManager.hpp"
54 
55 #include "BelosGmresIteration.hpp"
56 #include "BelosBlockGmresIter.hpp"
57 #include "BelosBlockFGmresIter.hpp"
64 #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 
83 namespace Belos {
84 
86 
87 
95  BlockGmresSolMgrLinearProblemFailure(const std::string& what_arg) : BelosError(what_arg)
96  {}};
97 
105  BlockGmresSolMgrOrthoFailure(const std::string& what_arg) : BelosError(what_arg)
106  {}};
107 
124 template<class ScalarType, class MV, class OP>
125 class BlockGmresSolMgr : public SolverManager<ScalarType,MV,OP> {
126 
127 private:
132  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
134 
135 public:
136 
138 
139 
146 
163 
165  virtual ~BlockGmresSolMgr() {};
167 
169 
170 
174  return *problem_;
175  }
176 
180 
184 
191  return Teuchos::tuple(timerSolve_);
192  }
193 
204  MagnitudeType achievedTol() const {
205  return achievedTol_;
206  }
207 
209  int getNumIters() const {
210  return numIters_;
211  }
212 
216  bool isLOADetected() const { return loaDetected_; }
217 
219 
221 
222 
224  void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) { problem_ = problem; isSTSet_ = false; }
225 
228 
230 
232 
233 
237  void reset( const ResetType type ) { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
239 
241 
242 
260  ReturnType solve();
261 
263 
266 
268  std::string description() const;
269 
271 
272 private:
273 
274  // Method for checking current status test against defined linear problem.
275  bool checkStatusTest();
276 
277  // Linear problem.
279 
280  // Output manager.
282  Teuchos::RCP<std::ostream> outputStream_;
283 
284  // Status test.
288  Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > expConvTest_, impConvTest_;
290 
291  // Orthogonalization manager.
293 
294  // Current parameter list.
296 
297  // Default solver values.
298  static const MagnitudeType convtol_default_;
299  static const MagnitudeType orthoKappa_default_;
300  static const int maxRestarts_default_;
301  static const int maxIters_default_;
302  static const bool adaptiveBlockSize_default_;
303  static const bool showMaxResNormOnly_default_;
304  static const bool flexibleGmres_default_;
305  static const bool expResTest_default_;
306  static const int blockSize_default_;
307  static const int numBlocks_default_;
308  static const int verbosity_default_;
309  static const int outputStyle_default_;
310  static const int outputFreq_default_;
311  static const std::string impResScale_default_;
312  static const std::string expResScale_default_;
313  static const std::string label_default_;
314  static const std::string orthoType_default_;
315  static const Teuchos::RCP<std::ostream> outputStream_default_;
316 
317  // Current solver values.
318  MagnitudeType convtol_, orthoKappa_, achievedTol_;
319  int maxRestarts_, maxIters_, numIters_;
320  int blockSize_, numBlocks_, verbosity_, outputStyle_, outputFreq_;
321  bool adaptiveBlockSize_, showMaxResNormOnly_, isFlexible_, expResTest_;
322  std::string orthoType_;
323  std::string impResScale_, expResScale_;
324 
325  // Timers.
326  std::string label_;
327  Teuchos::RCP<Teuchos::Time> timerSolve_;
328 
329  // Internal state variables.
330  bool isSet_, isSTSet_;
331  bool loaDetected_;
332 };
333 
334 
335 // Default solver values.
336 template<class ScalarType, class MV, class OP>
337 const typename BlockGmresSolMgr<ScalarType,MV,OP>::MagnitudeType BlockGmresSolMgr<ScalarType,MV,OP>::convtol_default_ = 1e-8;
338 
339 template<class ScalarType, class MV, class OP>
340 const typename BlockGmresSolMgr<ScalarType,MV,OP>::MagnitudeType BlockGmresSolMgr<ScalarType,MV,OP>::orthoKappa_default_ = -1.0;
341 
342 template<class ScalarType, class MV, class OP>
343 const int BlockGmresSolMgr<ScalarType,MV,OP>::maxRestarts_default_ = 20;
344 
345 template<class ScalarType, class MV, class OP>
346 const int BlockGmresSolMgr<ScalarType,MV,OP>::maxIters_default_ = 1000;
347 
348 template<class ScalarType, class MV, class OP>
349 const bool BlockGmresSolMgr<ScalarType,MV,OP>::adaptiveBlockSize_default_ = true;
350 
351 template<class ScalarType, class MV, class OP>
352 const bool BlockGmresSolMgr<ScalarType,MV,OP>::showMaxResNormOnly_default_ = false;
353 
354 template<class ScalarType, class MV, class OP>
355 const bool BlockGmresSolMgr<ScalarType,MV,OP>::flexibleGmres_default_ = false;
356 
357 template<class ScalarType, class MV, class OP>
358 const bool BlockGmresSolMgr<ScalarType,MV,OP>::expResTest_default_ = false;
359 
360 template<class ScalarType, class MV, class OP>
361 const int BlockGmresSolMgr<ScalarType,MV,OP>::blockSize_default_ = 1;
362 
363 template<class ScalarType, class MV, class OP>
364 const int BlockGmresSolMgr<ScalarType,MV,OP>::numBlocks_default_ = 300;
365 
366 template<class ScalarType, class MV, class OP>
367 const int BlockGmresSolMgr<ScalarType,MV,OP>::verbosity_default_ = Belos::Errors;
368 
369 template<class ScalarType, class MV, class OP>
370 const int BlockGmresSolMgr<ScalarType,MV,OP>::outputStyle_default_ = Belos::General;
371 
372 template<class ScalarType, class MV, class OP>
373 const int BlockGmresSolMgr<ScalarType,MV,OP>::outputFreq_default_ = -1;
374 
375 template<class ScalarType, class MV, class OP>
376 const std::string BlockGmresSolMgr<ScalarType,MV,OP>::impResScale_default_ = "Norm of Preconditioned Initial Residual";
377 
378 template<class ScalarType, class MV, class OP>
379 const std::string BlockGmresSolMgr<ScalarType,MV,OP>::expResScale_default_ = "Norm of Initial Residual";
380 
381 template<class ScalarType, class MV, class OP>
382 const std::string BlockGmresSolMgr<ScalarType,MV,OP>::label_default_ = "Belos";
383 
384 template<class ScalarType, class MV, class OP>
385 const std::string BlockGmresSolMgr<ScalarType,MV,OP>::orthoType_default_ = "DGKS";
386 
387 template<class ScalarType, class MV, class OP>
388 const Teuchos::RCP<std::ostream> BlockGmresSolMgr<ScalarType,MV,OP>::outputStream_default_ = Teuchos::rcp(&std::cout,false);
389 
390 
391 // Empty Constructor
392 template<class ScalarType, class MV, class OP>
394  outputStream_(outputStream_default_),
395  convtol_(convtol_default_),
396  orthoKappa_(orthoKappa_default_),
397  achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
398  maxRestarts_(maxRestarts_default_),
399  maxIters_(maxIters_default_),
400  numIters_(0),
401  blockSize_(blockSize_default_),
402  numBlocks_(numBlocks_default_),
403  verbosity_(verbosity_default_),
404  outputStyle_(outputStyle_default_),
405  outputFreq_(outputFreq_default_),
406  adaptiveBlockSize_(adaptiveBlockSize_default_),
407  showMaxResNormOnly_(showMaxResNormOnly_default_),
408  isFlexible_(flexibleGmres_default_),
409  expResTest_(expResTest_default_),
410  orthoType_(orthoType_default_),
411  impResScale_(impResScale_default_),
412  expResScale_(expResScale_default_),
413  label_(label_default_),
414  isSet_(false),
415  isSTSet_(false),
416  loaDetected_(false)
417 {}
418 
419 
420 // Basic Constructor
421 template<class ScalarType, class MV, class OP>
425  problem_(problem),
426  outputStream_(outputStream_default_),
427  convtol_(convtol_default_),
428  orthoKappa_(orthoKappa_default_),
429  achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
430  maxRestarts_(maxRestarts_default_),
431  maxIters_(maxIters_default_),
432  numIters_(0),
433  blockSize_(blockSize_default_),
434  numBlocks_(numBlocks_default_),
435  verbosity_(verbosity_default_),
436  outputStyle_(outputStyle_default_),
437  outputFreq_(outputFreq_default_),
438  adaptiveBlockSize_(adaptiveBlockSize_default_),
439  showMaxResNormOnly_(showMaxResNormOnly_default_),
440  isFlexible_(flexibleGmres_default_),
441  expResTest_(expResTest_default_),
442  orthoType_(orthoType_default_),
443  impResScale_(impResScale_default_),
444  expResScale_(expResScale_default_),
445  label_(label_default_),
446  isSet_(false),
447  isSTSet_(false),
448  loaDetected_(false)
449 {
450 
451  TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument, "Problem not given to solver manager.");
452 
453  // If the parameter list pointer is null, then set the current parameters to the default parameter list.
454  if ( !is_null(pl) ) {
455  setParameters( pl );
456  }
457 
458 }
459 
460 
461 template<class ScalarType, class MV, class OP>
464 {
466  if (is_null(validPL)) {
467  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
468  pl->set("Convergence Tolerance", convtol_default_,
469  "The relative residual tolerance that needs to be achieved by the\n"
470  "iterative solver in order for the linear system to be declared converged." );
471  pl->set("Maximum Restarts", maxRestarts_default_,
472  "The maximum number of restarts allowed for each\n"
473  "set of RHS solved.");
474  pl->set(
475  "Maximum Iterations", maxIters_default_,
476  "The maximum number of block iterations allowed for each\n"
477  "set of RHS solved.");
478  pl->set("Num Blocks", numBlocks_default_,
479  "The maximum number of blocks allowed in the Krylov subspace\n"
480  "for each set of RHS solved.");
481  pl->set("Block Size", blockSize_default_,
482  "The number of vectors in each block. This number times the\n"
483  "number of blocks is the total Krylov subspace dimension.");
484  pl->set("Adaptive Block Size", adaptiveBlockSize_default_,
485  "Whether the solver manager should adapt the block size\n"
486  "based on the number of RHS to solve.");
487  pl->set("Verbosity", verbosity_default_,
488  "What type(s) of solver information should be outputted\n"
489  "to the output stream.");
490  pl->set("Output Style", outputStyle_default_,
491  "What style is used for the solver information outputted\n"
492  "to the output stream.");
493  pl->set("Output Frequency", outputFreq_default_,
494  "How often convergence information should be outputted\n"
495  "to the output stream.");
496  pl->set("Output Stream", outputStream_default_,
497  "A reference-counted pointer to the output stream where all\n"
498  "solver output is sent.");
499  pl->set("Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
500  "When convergence information is printed, only show the maximum\n"
501  "relative residual norm when the block size is greater than one.");
502  pl->set("Flexible Gmres", flexibleGmres_default_,
503  "Whether the solver manager should use the flexible variant\n"
504  "of GMRES.");
505  pl->set("Explicit Residual Test", expResTest_default_,
506  "Whether the explicitly computed residual should be used in the convergence test.");
507  pl->set("Implicit Residual Scaling", impResScale_default_,
508  "The type of scaling used in the implicit residual convergence test.");
509  pl->set("Explicit Residual Scaling", expResScale_default_,
510  "The type of scaling used in the explicit residual convergence test.");
511  pl->set("Timer Label", label_default_,
512  "The string to use as a prefix for the timer labels.");
513  // pl->set("Restart Timers", restartTimers_);
514  pl->set("Orthogonalization", orthoType_default_,
515  "The type of orthogonalization to use: DGKS, ICGS, or IMGS.");
516  pl->set("Orthogonalization Constant",orthoKappa_default_,
517  "The constant used by DGKS orthogonalization to determine\n"
518  "whether another step of classical Gram-Schmidt is necessary.");
519  validPL = pl;
520  }
521  return validPL;
522 }
523 
524 
525 template<class ScalarType, class MV, class OP>
527 {
528 
529  // Create the internal parameter list if ones doesn't already exist.
530  if (params_ == Teuchos::null) {
531  params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) );
532  }
533  else {
534  params->validateParameters(*getValidParameters());
535  }
536 
537  // Check for maximum number of restarts
538  if (params->isParameter("Maximum Restarts")) {
539  maxRestarts_ = params->get("Maximum Restarts",maxRestarts_default_);
540 
541  // Update parameter in our list.
542  params_->set("Maximum Restarts", maxRestarts_);
543  }
544 
545  // Check for maximum number of iterations
546  if (params->isParameter("Maximum Iterations")) {
547  maxIters_ = params->get("Maximum Iterations",maxIters_default_);
548 
549  // Update parameter in our list and in status test.
550  params_->set("Maximum Iterations", maxIters_);
551  if (maxIterTest_!=Teuchos::null)
552  maxIterTest_->setMaxIters( maxIters_ );
553  }
554 
555  // Check for blocksize
556  if (params->isParameter("Block Size")) {
557  blockSize_ = params->get("Block Size",blockSize_default_);
558  TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ <= 0, std::invalid_argument,
559  "Belos::BlockGmresSolMgr: \"Block Size\" must be strictly positive.");
560 
561  // Update parameter in our list.
562  params_->set("Block Size", blockSize_);
563  }
564 
565  // Check if the blocksize should be adaptive
566  if (params->isParameter("Adaptive Block Size")) {
567  adaptiveBlockSize_ = params->get("Adaptive Block Size",adaptiveBlockSize_default_);
568 
569  // Update parameter in our list.
570  params_->set("Adaptive Block Size", adaptiveBlockSize_);
571  }
572 
573  // Check for the maximum number of blocks.
574  if (params->isParameter("Num Blocks")) {
575  numBlocks_ = params->get("Num Blocks",numBlocks_default_);
576  TEUCHOS_TEST_FOR_EXCEPTION(numBlocks_ <= 0, std::invalid_argument,
577  "Belos::BlockGmresSolMgr: \"Num Blocks\" must be strictly positive.");
578 
579  // Update parameter in our list.
580  params_->set("Num Blocks", numBlocks_);
581  }
582 
583  // Check to see if the timer label changed.
584  if (params->isParameter("Timer Label")) {
585  std::string tempLabel = params->get("Timer Label", label_default_);
586 
587  // Update parameter in our list, solver timer, and orthogonalization label
588  if (tempLabel != label_) {
589  label_ = tempLabel;
590  params_->set("Timer Label", label_);
591  std::string solveLabel = label_ + ": BlockGmresSolMgr total solve time";
592 #ifdef BELOS_TEUCHOS_TIME_MONITOR
593  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
594 #endif
595  if (ortho_ != Teuchos::null) {
596  ortho_->setLabel( label_ );
597  }
598  }
599  }
600 
601  // Determine whether this solver should be "flexible".
602  if (params->isParameter("Flexible Gmres")) {
603  isFlexible_ = Teuchos::getParameter<bool>(*params,"Flexible Gmres");
604  params_->set("Flexible Gmres", isFlexible_);
605  if (isFlexible_ && expResTest_) {
606  // Use an implicit convergence test if the Gmres solver is flexible
607  isSTSet_ = false;
608  }
609  }
610 
611 
612  // Check if the orthogonalization changed.
613  if (params->isParameter("Orthogonalization")) {
614  std::string tempOrthoType = params->get("Orthogonalization",orthoType_default_);
615  TEUCHOS_TEST_FOR_EXCEPTION( tempOrthoType != "DGKS" && tempOrthoType != "ICGS" && tempOrthoType != "IMGS",
616  std::invalid_argument,
617  "Belos::BlockGmresSolMgr: \"Orthogonalization\" must be either \"DGKS\", \"ICGS\", or \"IMGS\".");
618  if (tempOrthoType != orthoType_) {
619  orthoType_ = tempOrthoType;
620  // Create orthogonalization manager
621  if (orthoType_=="DGKS") {
622  if (orthoKappa_ <= 0) {
623  ortho_ = Teuchos::rcp( new DGKSOrthoManager<ScalarType,MV,OP>( label_ ) );
624  }
625  else {
626  ortho_ = Teuchos::rcp( new DGKSOrthoManager<ScalarType,MV,OP>( label_ ) );
627  Teuchos::rcp_dynamic_cast<DGKSOrthoManager<ScalarType,MV,OP> >(ortho_)->setDepTol( orthoKappa_ );
628  }
629  }
630  else if (orthoType_=="ICGS") {
631  ortho_ = Teuchos::rcp( new ICGSOrthoManager<ScalarType,MV,OP>( label_ ) );
632  }
633  else if (orthoType_=="IMGS") {
634  ortho_ = Teuchos::rcp( new IMGSOrthoManager<ScalarType,MV,OP>( label_ ) );
635  }
636  }
637  }
638 
639  // Check which orthogonalization constant to use.
640  if (params->isParameter("Orthogonalization Constant")) {
641  orthoKappa_ = params->get("Orthogonalization Constant",orthoKappa_default_);
642 
643  // Update parameter in our list.
644  params_->set("Orthogonalization Constant",orthoKappa_);
645  if (orthoType_=="DGKS") {
646  if (orthoKappa_ > 0 && ortho_ != Teuchos::null) {
647  Teuchos::rcp_dynamic_cast<DGKSOrthoManager<ScalarType,MV,OP> >(ortho_)->setDepTol( orthoKappa_ );
648  }
649  }
650  }
651 
652  // Check for a change in verbosity level
653  if (params->isParameter("Verbosity")) {
654  if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
655  verbosity_ = params->get("Verbosity", verbosity_default_);
656  } else {
657  verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
658  }
659 
660  // Update parameter in our list.
661  params_->set("Verbosity", verbosity_);
662  if (printer_ != Teuchos::null)
663  printer_->setVerbosity(verbosity_);
664  }
665 
666  // Check for a change in output style
667  if (params->isParameter("Output Style")) {
668  if (Teuchos::isParameterType<int>(*params,"Output Style")) {
669  outputStyle_ = params->get("Output Style", outputStyle_default_);
670  } else {
671  outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
672  }
673 
674  // Reconstruct the convergence test if the explicit residual test is not being used.
675  params_->set("Output Style", outputStyle_);
676  if (outputTest_ != Teuchos::null) {
677  isSTSet_ = false;
678  }
679  }
680 
681  // output stream
682  if (params->isParameter("Output Stream")) {
683  outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
684 
685  // Update parameter in our list.
686  params_->set("Output Stream", outputStream_);
687  if (printer_ != Teuchos::null)
688  printer_->setOStream( outputStream_ );
689  }
690 
691  // frequency level
692  if (verbosity_ & Belos::StatusTestDetails) {
693  if (params->isParameter("Output Frequency")) {
694  outputFreq_ = params->get("Output Frequency", outputFreq_default_);
695  }
696 
697  // Update parameter in out list and output status test.
698  params_->set("Output Frequency", outputFreq_);
699  if (outputTest_ != Teuchos::null)
700  outputTest_->setOutputFrequency( outputFreq_ );
701  }
702 
703  // Create output manager if we need to.
704  if (printer_ == Teuchos::null) {
705  printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
706  }
707 
708  // Check for convergence tolerance
709  if (params->isParameter("Convergence Tolerance")) {
710  convtol_ = params->get("Convergence Tolerance",convtol_default_);
711 
712  // Update parameter in our list and residual tests.
713  params_->set("Convergence Tolerance", convtol_);
714  if (impConvTest_ != Teuchos::null)
715  impConvTest_->setTolerance( convtol_ );
716  if (expConvTest_ != Teuchos::null)
717  expConvTest_->setTolerance( convtol_ );
718  }
719 
720  // Check for a change in scaling, if so we need to build new residual tests.
721  if (params->isParameter("Implicit Residual Scaling")) {
722  std::string tempImpResScale = Teuchos::getParameter<std::string>( *params, "Implicit Residual Scaling" );
723 
724  // Only update the scaling if it's different.
725  if (impResScale_ != tempImpResScale) {
726  Belos::ScaleType impResScaleType = convertStringToScaleType( tempImpResScale );
727  impResScale_ = tempImpResScale;
728 
729  // Update parameter in our list and residual tests
730  params_->set("Implicit Residual Scaling", impResScale_);
731  if (impConvTest_ != Teuchos::null) {
732  try {
733  impConvTest_->defineScaleForm( impResScaleType, Belos::TwoNorm );
734  }
735  catch (std::exception& e) {
736  // Make sure the convergence test gets constructed again.
737  isSTSet_ = false;
738  }
739  }
740  }
741  }
742 
743  if (params->isParameter("Explicit Residual Scaling")) {
744  std::string tempExpResScale = Teuchos::getParameter<std::string>( *params, "Explicit Residual Scaling" );
745 
746  // Only update the scaling if it's different.
747  if (expResScale_ != tempExpResScale) {
748  Belos::ScaleType expResScaleType = convertStringToScaleType( tempExpResScale );
749  expResScale_ = tempExpResScale;
750 
751  // Update parameter in our list and residual tests
752  params_->set("Explicit Residual Scaling", expResScale_);
753  if (expConvTest_ != Teuchos::null) {
754  try {
755  expConvTest_->defineScaleForm( expResScaleType, Belos::TwoNorm );
756  }
757  catch (std::exception& e) {
758  // Make sure the convergence test gets constructed again.
759  isSTSet_ = false;
760  }
761  }
762  }
763  }
764 
765  if (params->isParameter("Explicit Residual Test")) {
766  expResTest_ = Teuchos::getParameter<bool>( *params,"Explicit Residual Test" );
767 
768  // Reconstruct the convergence test if the explicit residual test is not being used.
769  params_->set("Explicit Residual Test", expResTest_);
770  if (expConvTest_ == Teuchos::null) {
771  isSTSet_ = false;
772  }
773  }
774 
775 
776  if (params->isParameter("Show Maximum Residual Norm Only")) {
777  showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
778 
779  // Update parameter in our list and residual tests
780  params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
781  if (impConvTest_ != Teuchos::null)
782  impConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
783  if (expConvTest_ != Teuchos::null)
784  expConvTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
785  }
786 
787  // Create orthogonalization manager if we need to.
788  if (ortho_ == Teuchos::null) {
789  if (orthoType_=="DGKS") {
790  if (orthoKappa_ <= 0) {
791  ortho_ = Teuchos::rcp( new DGKSOrthoManager<ScalarType,MV,OP>( label_ ) );
792  }
793  else {
794  ortho_ = Teuchos::rcp( new DGKSOrthoManager<ScalarType,MV,OP>( label_ ) );
795  Teuchos::rcp_dynamic_cast<DGKSOrthoManager<ScalarType,MV,OP> >(ortho_)->setDepTol( orthoKappa_ );
796  }
797  }
798  else if (orthoType_=="ICGS") {
799  ortho_ = Teuchos::rcp( new ICGSOrthoManager<ScalarType,MV,OP>( label_ ) );
800  }
801  else if (orthoType_=="IMGS") {
802  ortho_ = Teuchos::rcp( new IMGSOrthoManager<ScalarType,MV,OP>( label_ ) );
803  }
804  else {
805  TEUCHOS_TEST_FOR_EXCEPTION(orthoType_!="ICGS"&&orthoType_!="DGKS"&&orthoType_!="IMGS",std::logic_error,
806  "Belos::BlockGmresSolMgr(): Invalid orthogonalization type.");
807  }
808  }
809 
810  // Create the timer if we need to.
811  if (timerSolve_ == Teuchos::null) {
812  std::string solveLabel = label_ + ": BlockGmresSolMgr total solve time";
813 #ifdef BELOS_TEUCHOS_TIME_MONITOR
814  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
815 #endif
816  }
817 
818  // Inform the solver manager that the current parameters were set.
819  isSet_ = true;
820 }
821 
822 // Check the status test versus the defined linear problem
823 template<class ScalarType, class MV, class OP>
825 
826  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
827  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestGenResNorm_t;
828  typedef Belos::StatusTestImpResNorm<ScalarType,MV,OP> StatusTestImpResNorm_t;
829 
830  // Basic test checks maximum iterations and native residual.
831  maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
832 
833  // If there is a left preconditioner, we create a combined status test that checks the implicit
834  // and then explicit residual norm to see if we have convergence.
835  if (!Teuchos::is_null(problem_->getLeftPrec()) && !isFlexible_) {
836  expResTest_ = true;
837  }
838 
839  if (expResTest_) {
840 
841  // Implicit residual test, using the native residual to determine if convergence was achieved.
842  Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
843  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_ ) );
844  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
845  tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
846  impConvTest_ = tmpImpConvTest;
847 
848  // Explicit residual test once the native residual is below the tolerance
849  Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
850  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_ ) );
851  tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit, Belos::TwoNorm );
852  tmpExpConvTest->defineScaleForm( convertStringToScaleType(expResScale_), Belos::TwoNorm );
853  tmpExpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
854  expConvTest_ = tmpExpConvTest;
855 
856  // The convergence test is a combination of the "cheap" implicit test and explicit test.
857  convTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
858  }
859  else {
860 
861  if (isFlexible_) {
862  // Implicit residual test, using the native residual to determine if convergence was achieved.
863  Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
864  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_ ) );
865  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
866  tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
867  impConvTest_ = tmpImpConvTest;
868  }
869  else {
870  // Implicit residual test, using the native residual to determine if convergence was achieved.
871  // Use test that checks for loss of accuracy.
872  Teuchos::RCP<StatusTestImpResNorm_t> tmpImpConvTest =
873  Teuchos::rcp( new StatusTestImpResNorm_t( convtol_ ) );
874  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
875  tmpImpConvTest->setShowMaxResNormOnly( showMaxResNormOnly_ );
876  impConvTest_ = tmpImpConvTest;
877  }
878 
879  // Set the explicit and total convergence test to this implicit test that checks for accuracy loss.
880  expConvTest_ = impConvTest_;
881  convTest_ = impConvTest_;
882  }
883 
884  // Create the status test.
885  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
886 
887  // Create the status test output class.
888  // This class manages and formats the output from the status test.
889  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
890  outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
891 
892  // Set the solver string for the output test
893  std::string solverDesc = " Block Gmres ";
894  if (isFlexible_)
895  solverDesc = "Flexible" + solverDesc;
896  outputTest_->setSolverDesc( solverDesc );
897 
898  // The status test is now set.
899  isSTSet_ = true;
900 
901  return false;
902 }
903 
904 // solve()
905 template<class ScalarType, class MV, class OP>
907 
908  // Set the current parameters if they were not set before.
909  // NOTE: This may occur if the user generated the solver manager with the default constructor and
910  // then didn't set any parameters using setParameters().
911  if (!isSet_) {
912  setParameters(Teuchos::parameterList(*getValidParameters()));
913  }
914 
916 
918  "Belos::BlockGmresSolMgr::solve(): Linear problem is not a valid object.");
919 
921  "Belos::BlockGmresSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
922 
923  if (isFlexible_) {
924  TEUCHOS_TEST_FOR_EXCEPTION(problem_->getRightPrec()==Teuchos::null,BlockGmresSolMgrLinearProblemFailure,
925  "Belos::BlockGmresSolMgr::solve(): Linear problem does not have a preconditioner required for flexible GMRES, call setRightPrec().");
926  }
927 
928  if (!isSTSet_ || (!expResTest_ && !Teuchos::is_null(problem_->getLeftPrec())) ) {
930  "Belos::BlockGmresSolMgr::solve(): Linear problem and requested status tests are incompatible.");
931  }
932 
933  // Create indices for the linear systems to be solved.
934  int startPtr = 0;
935  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
936  int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
937 
938  std::vector<int> currIdx;
939  // If an adaptive block size is allowed then only the linear systems that need to be solved are solved.
940  // Otherwise, the index set is generated that informs the linear problem that some linear systems are augmented.
941  if ( adaptiveBlockSize_ ) {
942  blockSize_ = numCurrRHS;
943  currIdx.resize( numCurrRHS );
944  for (int i=0; i<numCurrRHS; ++i)
945  { currIdx[i] = startPtr+i; }
946 
947  }
948  else {
949  currIdx.resize( blockSize_ );
950  for (int i=0; i<numCurrRHS; ++i)
951  { currIdx[i] = startPtr+i; }
952  for (int i=numCurrRHS; i<blockSize_; ++i)
953  { currIdx[i] = -1; }
954  }
955 
956  // Inform the linear problem of the current linear system to solve.
957  problem_->setLSIndex( currIdx );
958 
960  // Parameter list
962  plist.set("Block Size",blockSize_);
963 
964  ptrdiff_t dim = MVText::GetGlobalLength( *(problem_->getRHS()) );
965  if (blockSize_*static_cast<ptrdiff_t>(numBlocks_) > dim) {
966  int tmpNumBlocks = 0;
967  if (blockSize_ == 1)
968  tmpNumBlocks = dim / blockSize_; // Allow for a good breakdown.
969  else
970  tmpNumBlocks = ( dim - blockSize_) / blockSize_; // Allow for restarting.
971  printer_->stream(Warnings) <<
972  "Belos::BlockGmresSolMgr::solve(): Warning! Requested Krylov subspace dimension is larger than operator dimension!"
973  << std::endl << " The maximum number of blocks allowed for the Krylov subspace will be adjusted to " << tmpNumBlocks << std::endl;
974  plist.set("Num Blocks",tmpNumBlocks);
975  }
976  else
977  plist.set("Num Blocks",numBlocks_);
978 
979  // Reset the status test.
980  outputTest_->reset();
981  loaDetected_ = false;
982 
983  // Assume convergence is achieved, then let any failed convergence set this to false.
984  bool isConverged = true;
985 
987  // BlockGmres solver
988 
990 
991  if (isFlexible_)
992  block_gmres_iter = Teuchos::rcp( new BlockFGmresIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,ortho_,plist) );
993  else
994  block_gmres_iter = Teuchos::rcp( new BlockGmresIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,ortho_,plist) );
995 
996  // Enter solve() iterations
997  {
998 #ifdef BELOS_TEUCHOS_TIME_MONITOR
999  Teuchos::TimeMonitor slvtimer(*timerSolve_);
1000 #endif
1001 
1002  while ( numRHS2Solve > 0 ) {
1003 
1004  // Set the current number of blocks and blocksize with the Gmres iteration.
1005  if (blockSize_*numBlocks_ > dim) {
1006  int tmpNumBlocks = 0;
1007  if (blockSize_ == 1)
1008  tmpNumBlocks = dim / blockSize_; // Allow for a good breakdown.
1009  else
1010  tmpNumBlocks = ( dim - blockSize_) / blockSize_; // Allow for restarting.
1011  block_gmres_iter->setSize( blockSize_, tmpNumBlocks );
1012  }
1013  else
1014  block_gmres_iter->setSize( blockSize_, numBlocks_ );
1015 
1016  // Reset the number of iterations.
1017  block_gmres_iter->resetNumIters();
1018 
1019  // Reset the number of calls that the status test output knows about.
1020  outputTest_->resetNumCalls();
1021 
1022  // Create the first block in the current Krylov basis.
1023  Teuchos::RCP<MV> V_0;
1024  if (isFlexible_) {
1025  // Load the correct residual if the system is augmented
1026  if (currIdx[blockSize_-1] == -1) {
1027  V_0 = MVT::Clone( *(problem_->getInitResVec()), blockSize_ );
1028  problem_->computeCurrResVec( &*V_0 );
1029  }
1030  else {
1031  V_0 = MVT::CloneCopy( *(problem_->getInitResVec()), currIdx );
1032  }
1033  }
1034  else {
1035  // Load the correct residual if the system is augmented
1036  if (currIdx[blockSize_-1] == -1) {
1037  V_0 = MVT::Clone( *(problem_->getInitPrecResVec()), blockSize_ );
1038  problem_->computeCurrPrecResVec( &*V_0 );
1039  }
1040  else {
1041  V_0 = MVT::CloneCopy( *(problem_->getInitPrecResVec()), currIdx );
1042  }
1043  }
1044 
1045  // Get a matrix to hold the orthonormalization coefficients.
1047  Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1048 
1049  // Orthonormalize the new V_0
1050  int rank = ortho_->normalize( *V_0, z_0 );
1052  "Belos::BlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors.");
1053 
1054  // Set the new state and initialize the solver.
1056  newstate.V = V_0;
1057  newstate.z = z_0;
1058  newstate.curDim = 0;
1059  block_gmres_iter->initializeGmres(newstate);
1060  int numRestarts = 0;
1061 
1062  while(1) {
1063  // tell block_gmres_iter to iterate
1064  try {
1065  block_gmres_iter->iterate();
1066 
1068  //
1069  // check convergence first
1070  //
1072  if ( convTest_->getStatus() == Passed ) {
1073  if ( expConvTest_->getLOADetected() ) {
1074  // we don't have convergence
1075  loaDetected_ = true;
1076  printer_->stream(Warnings) <<
1077  "Belos::BlockGmresSolMgr::solve(): Warning! Solver has experienced a loss of accuracy!" << std::endl;
1078  isConverged = false;
1079  }
1080  break; // break from while(1){block_gmres_iter->iterate()}
1081  }
1083  //
1084  // check for maximum iterations
1085  //
1087  else if ( maxIterTest_->getStatus() == Passed ) {
1088  // we don't have convergence
1089  isConverged = false;
1090  break; // break from while(1){block_gmres_iter->iterate()}
1091  }
1093  //
1094  // check for restarting, i.e. the subspace is full
1095  //
1097  else if ( block_gmres_iter->getCurSubspaceDim() == block_gmres_iter->getMaxSubspaceDim() ) {
1098 
1099  if ( numRestarts >= maxRestarts_ ) {
1100  isConverged = false;
1101  break; // break from while(1){block_gmres_iter->iterate()}
1102  }
1103  numRestarts++;
1104 
1105  printer_->stream(Debug) << " Performing restart number " << numRestarts << " of " << maxRestarts_ << std::endl << std::endl;
1106 
1107  // Update the linear problem.
1108  Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1109  if (isFlexible_) {
1110  // Update the solution manually, since the preconditioning doesn't need to be undone.
1111  Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1112  MVT::MvAddMv( 1.0, *curX, 1.0, *update, *curX );
1113  }
1114  else
1115  problem_->updateSolution( update, true );
1116 
1117  // Get the state.
1118  GmresIterationState<ScalarType,MV> oldState = block_gmres_iter->getState();
1119 
1120  // Compute the restart std::vector.
1121  // Get a view of the current Krylov basis.
1122  V_0 = MVT::Clone( *(oldState.V), blockSize_ );
1123  if (isFlexible_)
1124  problem_->computeCurrResVec( &*V_0 );
1125  else
1126  problem_->computeCurrPrecResVec( &*V_0 );
1127 
1128  // Get a view of the first block of the Krylov basis.
1129  z_0 = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,ScalarType>( blockSize_, blockSize_ ) );
1130 
1131  // Orthonormalize the new V_0
1132  rank = ortho_->normalize( *V_0, z_0 );
1134  "Belos::BlockGmresSolMgr::solve(): Failed to compute initial block of orthonormal vectors after restart.");
1135 
1136  // Set the new state and initialize the solver.
1137  newstate.V = V_0;
1138  newstate.z = z_0;
1139  newstate.curDim = 0;
1140  block_gmres_iter->initializeGmres(newstate);
1141 
1142  } // end of restarting
1143 
1145  //
1146  // we returned from iterate(), but none of our status tests Passed.
1147  // something is wrong, and it is probably our fault.
1148  //
1150 
1151  else {
1152  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
1153  "Belos::BlockGmresSolMgr::solve(): Invalid return from BlockGmresIter::iterate().");
1154  }
1155  }
1156  catch (const GmresIterationOrthoFailure &e) {
1157  // If the block size is not one, it's not considered a lucky breakdown.
1158  if (blockSize_ != 1) {
1159  printer_->stream(Errors) << "Error! Caught std::exception in BlockGmresIter::iterate() at iteration "
1160  << block_gmres_iter->getNumIters() << std::endl
1161  << e.what() << std::endl;
1162  if (convTest_->getStatus() != Passed)
1163  isConverged = false;
1164  break;
1165  }
1166  else {
1167  // If the block size is one, try to recover the most recent least-squares solution
1168  block_gmres_iter->updateLSQR( block_gmres_iter->getCurSubspaceDim() );
1169 
1170  // Check to see if the most recent least-squares solution yielded convergence.
1171  sTest_->checkStatus( &*block_gmres_iter );
1172  if (convTest_->getStatus() != Passed)
1173  isConverged = false;
1174  break;
1175  }
1176  }
1177  catch (const std::exception &e) {
1178  printer_->stream(Errors) << "Error! Caught std::exception in BlockGmresIter::iterate() at iteration "
1179  << block_gmres_iter->getNumIters() << std::endl
1180  << e.what() << std::endl;
1181  throw;
1182  }
1183  }
1184 
1185  // Compute the current solution.
1186  // Update the linear problem.
1187  if (isFlexible_) {
1188  // Update the solution manually, since the preconditioning doesn't need to be undone.
1189  Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1190  Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1191  // Update the solution only if there is a valid update from the iteration
1192  if (update != Teuchos::null)
1193  MVT::MvAddMv( 1.0, *curX, 1.0, *update, *curX );
1194  }
1195  else {
1196  // Attempt to get the current solution from the residual status test, if it has one.
1197  if ( !Teuchos::is_null(expConvTest_->getSolution()) ) {
1198  Teuchos::RCP<MV> newX = expConvTest_->getSolution();
1199  Teuchos::RCP<MV> curX = problem_->getCurrLHSVec();
1200  MVT::MvAddMv( 0.0, *newX, 1.0, *newX, *curX );
1201  }
1202  else {
1203  Teuchos::RCP<MV> update = block_gmres_iter->getCurrentUpdate();
1204  problem_->updateSolution( update, true );
1205  }
1206  }
1207 
1208  // Inform the linear problem that we are finished with this block linear system.
1209  problem_->setCurrLS();
1210 
1211  // Update indices for the linear systems to be solved.
1212  startPtr += numCurrRHS;
1213  numRHS2Solve -= numCurrRHS;
1214  if ( numRHS2Solve > 0 ) {
1215  numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
1216 
1217  if ( adaptiveBlockSize_ ) {
1218  blockSize_ = numCurrRHS;
1219  currIdx.resize( numCurrRHS );
1220  for (int i=0; i<numCurrRHS; ++i)
1221  { currIdx[i] = startPtr+i; }
1222  }
1223  else {
1224  currIdx.resize( blockSize_ );
1225  for (int i=0; i<numCurrRHS; ++i)
1226  { currIdx[i] = startPtr+i; }
1227  for (int i=numCurrRHS; i<blockSize_; ++i)
1228  { currIdx[i] = -1; }
1229  }
1230  // Set the next indices.
1231  problem_->setLSIndex( currIdx );
1232  }
1233  else {
1234  currIdx.resize( numRHS2Solve );
1235  }
1236 
1237  }// while ( numRHS2Solve > 0 )
1238 
1239  }
1240 
1241  // print final summary
1242  sTest_->print( printer_->stream(FinalSummary) );
1243 
1244  // print timing information
1245 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1246  // Calling summarize() can be expensive, so don't call unless the
1247  // user wants to print out timing details. summarize() will do all
1248  // the work even if it's passed a "black hole" output stream.
1249  if (verbosity_ & TimingDetails)
1250  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
1251 #endif
1252 
1253  // get iteration information for this solve
1254  numIters_ = maxIterTest_->getNumIters();
1255 
1256  // Save the convergence test value ("achieved tolerance") for this
1257  // solve. This requires a bit more work than for BlockCGSolMgr,
1258  // since for this solver, convTest_ may either be a single residual
1259  // norm test, or a combination of two residual norm tests. In the
1260  // latter case, the master convergence test convTest_ is a SEQ combo
1261  // of the implicit resp. explicit tests. If the implicit test never
1262  // passes, then the explicit test won't ever be executed. This
1263  // manifests as expConvTest_->getTestValue()->size() < 1. We deal
1264  // with this case by using the values returned by
1265  // impConvTest_->getTestValue().
1266  {
1267  // We'll fetch the vector of residual norms one way or the other.
1268  const std::vector<MagnitudeType>* pTestValues = NULL;
1269  if (expResTest_) {
1270  pTestValues = expConvTest_->getTestValue();
1271  if (pTestValues == NULL || pTestValues->size() < 1) {
1272  pTestValues = impConvTest_->getTestValue();
1273  }
1274  }
1275  else {
1276  // Only the implicit residual norm test is being used.
1277  pTestValues = impConvTest_->getTestValue();
1278  }
1279  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
1280  "Belos::BlockGmresSolMgr::solve(): The implicit convergence test's "
1281  "getTestValue() method returned NULL. Please report this bug to the "
1282  "Belos developers.");
1283  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
1284  "Belos::BlockGmresSolMgr::solve(): The implicit convergence test's "
1285  "getTestValue() method returned a vector of length zero. Please report "
1286  "this bug to the Belos developers.");
1287 
1288  // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
1289  // achieved tolerances for all vectors in the current solve(), or
1290  // just for the vectors from the last deflation?
1291  achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
1292  }
1293 
1294  if (!isConverged || loaDetected_) {
1295  return Unconverged; // return from BlockGmresSolMgr::solve()
1296  }
1297  return Converged; // return from BlockGmresSolMgr::solve()
1298 }
1299 
1300 // This method requires the solver manager to return a std::string that describes itself.
1301 template<class ScalarType, class MV, class OP>
1303 {
1304  std::ostringstream oss;
1305  oss << "Belos::BlockGmresSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
1306  oss << "{";
1307  if (isFlexible_) {
1308  oss << "Variant=\'Flexible\', ";
1309  }
1310  oss << "Ortho Type='"<<orthoType_<<"\', Block Size=" <<blockSize_;
1311  oss << ", Num Blocks=" <<numBlocks_<< ", Max Restarts=" << maxRestarts_;
1312  oss << "}";
1313  return oss.str();
1314 }
1315 
1316 } // end Belos namespace
1317 
1318 #endif /* BELOS_BLOCK_GMRES_SOLMGR_HPP */
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition: BelosTypes.cpp:93
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
Collection of types and exceptions used within the Belos solvers.
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
Class which manages the output and verbosity of the Belos solvers.
bool is_null(const boost::shared_ptr< T > &p)
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
ScaleType
The type of scaling to use on the residual norm value.
Definition: BelosTypes.hpp:119
This class implements the block GMRES iteration, where a block Krylov subspace is constructed...
Convergence test using the implicit residual norm(s), with an explicit residual norm(s) check for los...
Teuchos::RCP< const MV > V
The current Krylov basis.
T & get(const std::string &name, T def_value)
Virtual base class for StatusTest that printing status tests.
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)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > z
The current right-hand side of the least squares system RY = Z.
An implementation of StatusTestResNorm using a family of residual norms.
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
BlockGmresSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
Structure to contain pointers to GmresIteration state variables.
An extension of the MultiVecTraits class that adds a new vector length method.
Belos::StatusTest class for specifying a maximum number of iterations.
Interface to Block GMRES and Flexible GMRES.
static std::string name()
virtual ~BlockGmresSolMgr()
Destructor.
A factory class for generating StatusTestOutput objects.
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
std::string description() const
Method to return description of the block GMRES solver manager.
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
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
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. ...
int curDim
The current dimension of the reduction.
BlockGmresSolMgrLinearProblemFailure(const std::string &what_arg)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
This class implements the block flexible GMRES iteration, where a block Krylov subspace is constructe...
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 ...
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver&#39;s iterate() routine unti...
Belos concrete class for performing the block GMRES iteration.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
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
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
int getNumIters() const
Get the iteration count for the most recent call to solve().
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest for specifying an implicit residual norm stopping criteria that checks for loss of ...
BlockGmresSolMgr()
Empty constructor for BlockGmresSolMgr. This constructor takes no arguments and sets the default valu...
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
BlockGmresSolMgrOrthoFailure(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.
Parent class to all Belos exceptions.
Definition: BelosTypes.hpp:60
BlockGmresSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate ortho...
Pure virtual base class which augments the basic interface for a Gmres linear solver iteration...
GmresIterationOrthoFailure is thrown when the GmresIteration object is unable to compute independent ...
Belos header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Get current linear problem being solved for in this object.
Belos concrete class for performing the block, flexible GMRES iteration.
bool isLOADetected() const
Return whether a loss of accuracy was detected by this solver during the most current solve...
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters the solver manager should use to solve the linear problem.