Belos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosPseudoBlockStochasticCGSolMgr.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_STOCHASTIC_CG_SOLMGR_HPP
43 #define BELOS_PSEUDO_BLOCK_STOCHASTIC_CG_SOLMGR_HPP
44 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosTypes.hpp"
51 
52 #include "BelosLinearProblem.hpp"
53 #include "BelosSolverManager.hpp"
54 
58 #include "BelosStatusTestCombo.hpp"
60 #include "BelosOutputManager.hpp"
61 #ifdef BELOS_TEUCHOS_TIME_MONITOR
62 #include "Teuchos_TimeMonitor.hpp"
63 #endif
64 
74 namespace Belos {
75 
77 
78 
86  PseudoBlockStochasticCGSolMgrLinearProblemFailure(const std::string& what_arg) : BelosError(what_arg)
87  {}};
88 
89  template<class ScalarType, class MV, class OP>
90  class PseudoBlockStochasticCGSolMgr : public SolverManager<ScalarType,MV,OP> {
91 
92  private:
98 
99  public:
100 
102 
103 
110 
122 
125 
129  }
131 
133 
134 
135  const LinearProblem<ScalarType,MV,OP>& getProblem() const override {
136  return *problem_;
137  }
138 
142 
146 
153  return Teuchos::tuple(timerSolve_);
154  }
155 
157  int getNumIters() const override {
158  return numIters_;
159  }
160 
164  bool isLOADetected() const override { return false; }
165 
167 
169 
170 
172  void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) override { problem_ = problem; }
173 
175  void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
176 
178 
180 
181 
185  void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
187 
189 
190 
208  ReturnType solve() override;
209 
211 
214 
217 
219  std::string description() const override;
220 
222 
223  private:
224 
225  // Linear problem.
227 
228  // Output manager.
231 
232  // Status test.
237 
238  // Current parameter list.
240 
247 
248  // Default solver values.
249  static constexpr int maxIters_default_ = 1000;
250  static constexpr bool assertPositiveDefiniteness_default_ = true;
251  static constexpr bool showMaxResNormOnly_default_ = false;
252  static constexpr int verbosity_default_ = Belos::Errors;
253  static constexpr int outputStyle_default_ = Belos::General;
254  static constexpr int outputFreq_default_ = -1;
255  static constexpr int defQuorum_default_ = 1;
256  static constexpr const char * resScale_default_ = "Norm of Initial Residual";
257  static constexpr const char * label_default_ = "Belos";
258 
259  // Current solver values.
264  std::string resScale_;
265 
266  // Timers.
267  std::string label_;
269 
270  // Internal state variables.
271  bool isSet_;
272 
273  // Stashed copy of the stochastic vector
275 
276  };
277 
278 
279 // Empty Constructor
280 template<class ScalarType, class MV, class OP>
282  outputStream_(Teuchos::rcpFromRef(std::cout)),
283  convtol_(DefaultSolverParameters::convTol),
284  maxIters_(maxIters_default_),
285  numIters_(0),
286  verbosity_(verbosity_default_),
287  outputStyle_(outputStyle_default_),
288  outputFreq_(outputFreq_default_),
289  defQuorum_(defQuorum_default_),
290  assertPositiveDefiniteness_(assertPositiveDefiniteness_default_),
291  showMaxResNormOnly_(showMaxResNormOnly_default_),
292  resScale_(resScale_default_),
293  label_(label_default_),
294  isSet_(false)
295 {}
296 
297 // Basic Constructor
298 template<class ScalarType, class MV, class OP>
302  problem_(problem),
303  outputStream_(Teuchos::rcpFromRef(std::cout)),
304  convtol_(DefaultSolverParameters::convTol),
305  maxIters_(maxIters_default_),
306  numIters_(0),
307  verbosity_(verbosity_default_),
308  outputStyle_(outputStyle_default_),
309  outputFreq_(outputFreq_default_),
310  defQuorum_(defQuorum_default_),
311  assertPositiveDefiniteness_(assertPositiveDefiniteness_default_),
312  showMaxResNormOnly_(showMaxResNormOnly_default_),
313  resScale_(resScale_default_),
314  label_(label_default_),
315  isSet_(false)
316 {
318  problem_.is_null (), std::invalid_argument,
319  "Belos::PseudoBlockStochasticCGSolMgr two-argument constructor: "
320  "'problem' is null. You must supply a non-null Belos::LinearProblem "
321  "instance when calling this constructor.");
322 
323  if (! pl.is_null ()) {
324  // Set the parameters using the list that was passed in.
325  setParameters (pl);
326  }
327 }
328 
329 template<class ScalarType, class MV, class OP>
331 {
333  using Teuchos::parameterList;
334  using Teuchos::RCP;
335 
336  RCP<const ParameterList> defaultParams = getValidParameters();
337 
338  // Create the internal parameter list if one doesn't already exist.
339  if (params_.is_null()) {
340  params_ = parameterList (*defaultParams);
341  } else {
342  params->validateParameters (*defaultParams);
343  }
344 
345  // Check for maximum number of iterations
346  if (params->isParameter("Maximum Iterations")) {
347  maxIters_ = params->get("Maximum Iterations",maxIters_default_);
348 
349  // Update parameter in our list and in status test.
350  params_->set("Maximum Iterations", maxIters_);
351  if (maxIterTest_!=Teuchos::null)
352  maxIterTest_->setMaxIters( maxIters_ );
353  }
354 
355  // Check if positive definiteness assertions are to be performed
356  if (params->isParameter("Assert Positive Definiteness")) {
357  assertPositiveDefiniteness_ = params->get("Assert Positive Definiteness",assertPositiveDefiniteness_default_);
358 
359  // Update parameter in our list.
360  params_->set("Assert Positive Definiteness", assertPositiveDefiniteness_);
361  }
362 
363  // Check to see if the timer label changed.
364  if (params->isParameter("Timer Label")) {
365  std::string tempLabel = params->get("Timer Label", label_default_);
366 
367  // Update parameter in our list and solver timer
368  if (tempLabel != label_) {
369  label_ = tempLabel;
370  params_->set("Timer Label", label_);
371  std::string solveLabel = label_ + ": PseudoBlockStochasticCGSolMgr total solve time";
372 #ifdef BELOS_TEUCHOS_TIME_MONITOR
373  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
374 #endif
375  }
376  }
377 
378  // Check for a change in verbosity level
379  if (params->isParameter("Verbosity")) {
380  if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
381  verbosity_ = params->get("Verbosity", verbosity_default_);
382  } else {
383  verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
384  }
385 
386  // Update parameter in our list.
387  params_->set("Verbosity", verbosity_);
388  if (printer_ != Teuchos::null)
389  printer_->setVerbosity(verbosity_);
390  }
391 
392  // Check for a change in output style
393  if (params->isParameter("Output Style")) {
394  if (Teuchos::isParameterType<int>(*params,"Output Style")) {
395  outputStyle_ = params->get("Output Style", outputStyle_default_);
396  } else {
397  outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
398  }
399 
400  // Reconstruct the convergence test if the explicit residual test is not being used.
401  params_->set("Output Style", outputStyle_);
402  outputTest_ = Teuchos::null;
403  }
404 
405  // output stream
406  if (params->isParameter("Output Stream")) {
407  outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
408 
409  // Update parameter in our list.
410  params_->set("Output Stream", outputStream_);
411  if (printer_ != Teuchos::null)
412  printer_->setOStream( outputStream_ );
413  }
414 
415  // frequency level
416  if (verbosity_ & Belos::StatusTestDetails) {
417  if (params->isParameter("Output Frequency")) {
418  outputFreq_ = params->get("Output Frequency", outputFreq_default_);
419  }
420 
421  // Update parameter in out list and output status test.
422  params_->set("Output Frequency", outputFreq_);
423  if (outputTest_ != Teuchos::null)
424  outputTest_->setOutputFrequency( outputFreq_ );
425  }
426 
427  // Create output manager if we need to.
428  if (printer_ == Teuchos::null) {
429  printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
430  }
431 
432  // Convergence
433  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
434  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestResNorm_t;
435 
436  // Check for convergence tolerance
437  if (params->isParameter("Convergence Tolerance")) {
438  if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
439  convtol_ = params->get ("Convergence Tolerance",
440  static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
441  }
442  else {
443  convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
444  }
445 
446  // Update parameter in our list and residual tests.
447  params_->set("Convergence Tolerance", convtol_);
448  if (convTest_ != Teuchos::null)
449  convTest_->setTolerance( convtol_ );
450  }
451 
452  if (params->isParameter("Show Maximum Residual Norm Only")) {
453  showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
454 
455  // Update parameter in our list and residual tests
456  params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
457  if (convTest_ != Teuchos::null)
458  convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
459  }
460 
461  // Check for a change in scaling, if so we need to build new residual tests.
462  bool newResTest = false;
463  {
464  // "Residual Scaling" is the old parameter name; "Implicit
465  // Residual Scaling" is the new name. We support both options for
466  // backwards compatibility.
467  std::string tempResScale = resScale_;
468  bool implicitResidualScalingName = false;
469  if (params->isParameter ("Residual Scaling")) {
470  tempResScale = params->get<std::string> ("Residual Scaling");
471  }
472  else if (params->isParameter ("Implicit Residual Scaling")) {
473  tempResScale = params->get<std::string> ("Implicit Residual Scaling");
474  implicitResidualScalingName = true;
475  }
476 
477  // Only update the scaling if it's different.
478  if (resScale_ != tempResScale) {
479  Belos::ScaleType resScaleType = convertStringToScaleType( tempResScale );
480  resScale_ = tempResScale;
481 
482  // Update parameter in our list and residual tests, using the
483  // given parameter name.
484  if (implicitResidualScalingName) {
485  params_->set ("Implicit Residual Scaling", resScale_);
486  }
487  else {
488  params_->set ("Residual Scaling", resScale_);
489  }
490 
491  if (! convTest_.is_null()) {
492  try {
493  convTest_->defineScaleForm( resScaleType, Belos::TwoNorm );
494  }
495  catch (std::exception& e) {
496  // Make sure the convergence test gets constructed again.
497  newResTest = true;
498  }
499  }
500  }
501  }
502 
503  // Get the deflation quorum, or number of converged systems before deflation is allowed
504  if (params->isParameter("Deflation Quorum")) {
505  defQuorum_ = params->get("Deflation Quorum", defQuorum_);
506  params_->set("Deflation Quorum", defQuorum_);
507  if (convTest_ != Teuchos::null)
508  convTest_->setQuorum( defQuorum_ );
509  }
510 
511  // Create status tests if we need to.
512 
513  // Basic test checks maximum iterations and native residual.
514  if (maxIterTest_ == Teuchos::null)
515  maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
516 
517  // Implicit residual test, using the native residual to determine if convergence was achieved.
518  if (convTest_ == Teuchos::null || newResTest) {
519  convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, defQuorum_, showMaxResNormOnly_ ) );
520  convTest_->defineScaleForm( convertStringToScaleType( resScale_ ), Belos::TwoNorm );
521  }
522 
523  if (sTest_ == Teuchos::null || newResTest)
524  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
525 
526  if (outputTest_ == Teuchos::null || newResTest) {
527 
528  // Create the status test output class.
529  // This class manages and formats the output from the status test.
530  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
531  outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
532 
533  // Set the solver string for the output test
534  std::string solverDesc = " Pseudo Block CG ";
535  outputTest_->setSolverDesc( solverDesc );
536 
537  }
538 
539  // Create the timer if we need to.
540  if (timerSolve_ == Teuchos::null) {
541  std::string solveLabel = label_ + ": PseudoBlockStochasticCGSolMgr total solve time";
542 #ifdef BELOS_TEUCHOS_TIME_MONITOR
543  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
544 #endif
545  }
546 
547  // Inform the solver manager that the current parameters were set.
548  isSet_ = true;
549 }
550 
551 
552 template<class ScalarType, class MV, class OP>
555 {
557  using Teuchos::parameterList;
558  using Teuchos::RCP;
559 
560  if (validParams_.is_null()) {
561  // Set all the valid parameters and their default values.
562 
563  // The static_cast is to resolve an issue with older clang versions which
564  // would cause the constexpr to link fail. With c++17 the problem is resolved.
565  RCP<ParameterList> pl = parameterList ();
566  pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
567  "The relative residual tolerance that needs to be achieved by the\n"
568  "iterative solver in order for the linera system to be declared converged.");
569  pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
570  "The maximum number of block iterations allowed for each\n"
571  "set of RHS solved.");
572  pl->set("Assert Positive Definiteness", static_cast<bool>(assertPositiveDefiniteness_default_),
573  "Whether or not to assert that the linear operator\n"
574  "and the preconditioner are indeed positive definite.");
575  pl->set("Verbosity", static_cast<int>(verbosity_default_),
576  "What type(s) of solver information should be outputted\n"
577  "to the output stream.");
578  pl->set("Output Style", static_cast<int>(outputStyle_default_),
579  "What style is used for the solver information outputted\n"
580  "to the output stream.");
581  pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
582  "How often convergence information should be outputted\n"
583  "to the output stream.");
584  pl->set("Deflation Quorum", static_cast<int>(defQuorum_default_),
585  "The number of linear systems that need to converge before\n"
586  "they are deflated. This number should be <= block size.");
587  pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
588  "A reference-counted pointer to the output stream where all\n"
589  "solver output is sent.");
590  pl->set("Show Maximum Residual Norm Only", static_cast<bool>(showMaxResNormOnly_default_),
591  "When convergence information is printed, only show the maximum\n"
592  "relative residual norm when the block size is greater than one.");
593  pl->set("Implicit Residual Scaling", resScale_default_,
594  "The type of scaling used in the residual convergence test.");
595  // We leave the old name as a valid parameter for backwards
596  // compatibility (so that validateParametersAndSetDefaults()
597  // doesn't raise an exception if it encounters "Residual
598  // Scaling"). The new name was added for compatibility with other
599  // solvers, none of which use "Residual Scaling".
600  pl->set("Residual Scaling", resScale_default_,
601  "The type of scaling used in the residual convergence test. This "
602  "name is deprecated; the new name is \"Implicit Residual Scaling\".");
603  pl->set("Timer Label", static_cast<const char *>(label_default_),
604  "The string to use as a prefix for the timer labels.");
605  validParams_ = pl;
606  }
607  return validParams_;
608 }
609 
610 
611 // solve()
612 template<class ScalarType, class MV, class OP>
614 
615  // Set the current parameters if they were not set before.
616  // NOTE: This may occur if the user generated the solver manager with the default constructor and
617  // then didn't set any parameters using setParameters().
618  if (!isSet_) { setParameters( params_ ); }
619 
621  "Belos::PseudoBlockStochasticCGSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
622 
623  // Create indices for the linear systems to be solved.
624  int startPtr = 0;
625  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
626  int numCurrRHS = numRHS2Solve;
627 
628  std::vector<int> currIdx( numRHS2Solve ), currIdx2( numRHS2Solve );
629  for (int i=0; i<numRHS2Solve; ++i) {
630  currIdx[i] = startPtr+i;
631  currIdx2[i]=i;
632  }
633 
634  // Inform the linear problem of the current linear system to solve.
635  problem_->setLSIndex( currIdx );
636 
638  // Parameter list
640 
641  plist.set("Assert Positive Definiteness",assertPositiveDefiniteness_);
642 
643  // Reset the status test.
644  outputTest_->reset();
645 
646  // Assume convergence is achieved, then let any failed convergence set this to false.
647  bool isConverged = true;
648 
650  // Pseudo-Block CG solver
651 
653  = Teuchos::rcp( new PseudoBlockStochasticCGIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,plist) );
654 
655  // Enter solve() iterations
656  {
657 #ifdef BELOS_TEUCHOS_TIME_MONITOR
658  Teuchos::TimeMonitor slvtimer(*timerSolve_);
659 #endif
660 
661  while ( numRHS2Solve > 0 ) {
662 
663  // Reset the active / converged vectors from this block
664  std::vector<int> convRHSIdx;
665  std::vector<int> currRHSIdx( currIdx );
666  currRHSIdx.resize(numCurrRHS);
667 
668  // Reset the number of iterations.
669  block_cg_iter->resetNumIters();
670 
671  // Reset the number of calls that the status test output knows about.
672  outputTest_->resetNumCalls();
673 
674  // Get the current residual for this block of linear systems.
675  Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
676 
677  // Get a new state struct and initialize the solver.
679  newState.R = R_0;
680  block_cg_iter->initializeCG(newState);
681 
682  while(1) {
683 
684  // tell block_gmres_iter to iterate
685  try {
686  block_cg_iter->iterate();
687 
689  //
690  // check convergence first
691  //
693  if ( convTest_->getStatus() == Passed ) {
694 
695  // Figure out which linear systems converged.
696  std::vector<int> convIdx = Teuchos::rcp_dynamic_cast<StatusTestGenResNorm<ScalarType,MV,OP> >(convTest_)->convIndices();
697 
698  // If the number of converged linear systems is equal to the
699  // number of current linear systems, then we are done with this block.
700  if (convIdx.size() == currRHSIdx.size())
701  break; // break from while(1){block_cg_iter->iterate()}
702 
703  // Inform the linear problem that we are finished with this current linear system.
704  problem_->setCurrLS();
705 
706  // Reset currRHSIdx to have the right-hand sides that are left to converge for this block.
707  int have = 0;
708  std::vector<int> unconvIdx(currRHSIdx.size());
709  for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
710  bool found = false;
711  for (unsigned int j=0; j<convIdx.size(); ++j) {
712  if (currRHSIdx[i] == convIdx[j]) {
713  found = true;
714  break;
715  }
716  }
717  if (!found) {
718  currIdx2[have] = currIdx2[i];
719  currRHSIdx[have++] = currRHSIdx[i];
720  }
721  }
722  currRHSIdx.resize(have);
723  currIdx2.resize(have);
724 
725  // Set the remaining indices after deflation.
726  problem_->setLSIndex( currRHSIdx );
727 
728  // Get the current residual vector.
729  std::vector<MagnitudeType> norms;
730  R_0 = MVT::CloneCopy( *(block_cg_iter->getNativeResiduals(&norms)),currIdx2 );
731  for (int i=0; i<have; ++i) { currIdx2[i] = i; }
732 
733  // Set the new state and initialize the solver.
735  defstate.R = R_0;
736  block_cg_iter->initializeCG(defstate);
737  }
738 
740  //
741  // check for maximum iterations
742  //
744  else if ( maxIterTest_->getStatus() == Passed ) {
745  // we don't have convergence
746  isConverged = false;
747  break; // break from while(1){block_cg_iter->iterate()}
748  }
749 
751  //
752  // we returned from iterate(), but none of our status tests Passed.
753  // something is wrong, and it is probably our fault.
754  //
756 
757  else {
758  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
759  "Belos::PseudoBlockStochasticCGSolMgr::solve(): Invalid return from PseudoBlockStochasticCGIter::iterate().");
760  }
761  }
762  catch (const std::exception &e) {
763  printer_->stream(Errors) << "Error! Caught std::exception in PseudoBlockStochasticCGIter::iterate() at iteration "
764  << block_cg_iter->getNumIters() << std::endl
765  << e.what() << std::endl;
766  throw;
767  }
768  }
769 
770  // Inform the linear problem that we are finished with this block linear system.
771  problem_->setCurrLS();
772 
773  // Update indices for the linear systems to be solved.
774  startPtr += numCurrRHS;
775  numRHS2Solve -= numCurrRHS;
776 
777  if ( numRHS2Solve > 0 ) {
778 
779  numCurrRHS = numRHS2Solve;
780  currIdx.resize( numCurrRHS );
781  currIdx2.resize( numCurrRHS );
782  for (int i=0; i<numCurrRHS; ++i)
783  { currIdx[i] = startPtr+i; currIdx2[i] = i; }
784 
785  // Set the next indices.
786  problem_->setLSIndex( currIdx );
787  }
788  else {
789  currIdx.resize( numRHS2Solve );
790  }
791 
792  }// while ( numRHS2Solve > 0 )
793 
794  }
795 
796  // get the final stochastic vector
797  Y_=block_cg_iter->getStochasticVector();
798 
799 
800  // print final summary
801  sTest_->print( printer_->stream(FinalSummary) );
802 
803  // print timing information
804 #ifdef BELOS_TEUCHOS_TIME_MONITOR
805  // Calling summarize() can be expensive, so don't call unless the
806  // user wants to print out timing details. summarize() will do all
807  // the work even if it's passed a "black hole" output stream.
808  if (verbosity_ & TimingDetails)
809  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
810 #endif
811 
812  // get iteration information for this solve
813  numIters_ = maxIterTest_->getNumIters();
814 
815  if (!isConverged ) {
816  return Unconverged; // return from PseudoBlockStochasticCGSolMgr::solve()
817  }
818  return Converged; // return from PseudoBlockStochasticCGSolMgr::solve()
819 }
820 
821 // This method requires the solver manager to return a std::string that describes itself.
822 template<class ScalarType, class MV, class OP>
824 {
825  std::ostringstream oss;
826  oss << "Belos::PseudoBlockStochasticCGSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
827  oss << "{";
828  oss << "}";
829  return oss.str();
830 }
831 
832 } // end Belos namespace
833 
834 #endif /* BELOS_PSEUDO_BLOCK_CG_SOLMGR_HPP */
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition: BelosTypes.cpp:106
Collection of types and exceptions used within the Belos solvers.
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve...
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
Teuchos::RCP< OutputManager< ScalarType > > printer_
Class which manages the output and verbosity of the Belos solvers.
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
ScaleType
The type of scaling to use on the residual norm value.
Definition: BelosTypes.hpp:120
Teuchos::RCP< const Teuchos::ParameterList > validParams_
List of valid parameters and their default values.
T & get(ParameterList &l, const std::string &name)
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)
bool is_null(const std::shared_ptr< T > &p)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
A factory class for generating StatusTestOutput objects.
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > convTest_
int getNumIters() const override
Get the iteration count for the most recent call to solve().
std::string description() const override
Method to return description of the block CG solver manager.
An implementation of StatusTestResNorm using a family of residual norms.
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
static const double convTol
Default convergence tolerance.
Definition: BelosTypes.hpp:293
Belos::StatusTest class for specifying a maximum number of iterations.
static std::string name()
A factory class for generating StatusTestOutput objects.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
bool isParameter(const std::string &name) const
A Belos::StatusTest class for specifying a maximum number of iterations.
Belos concrete class for performing the stochastic pseudo-block CG iteration.
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:206
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. ...
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="", const bool ignoreZeroTimers=false)
bool is_null(const RCP< T > &p)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers 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.
Teuchos::RCP< const MV > R
The current residual.
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:155
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > outputTest_
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
Teuchos::RCP< Teuchos::ParameterList > params_
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
PseudoBlockStochasticCGSolMgr()
Empty constructor for BlockStochasticCGSolMgr. This constructor takes no arguments and sets the defau...
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.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver&#39;s iterate() routine unti...
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
This class implements the stochastic pseudo-block CG iteration, where the basic stochastic CG algorit...
The Belos::PseudoBlockStochasticCGSolMgr provides a powerful and fully-featured solver manager over t...
bool isType(const std::string &name) const
Teuchos::RCP< MV > getStochasticVector()
Get a copy of the final stochastic vector.
A class for extending the status testing capabilities of Belos via logical combinations.
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
Definition: BelosTypes.hpp:60
Default parameters common to most Belos solvers.
Definition: BelosTypes.hpp:283
Belos header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > sTest_
PseudoBlockStochasticCGSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
Teuchos::RCP< StatusTestMaxIters< ScalarType, MV, OP > > maxIterTest_
Structure to contain pointers to CGIteration state variables.