Belos Version of the Day
Loading...
Searching...
No Matches
BelosPseudoBlockStochasticCGSolMgr.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Belos: Block Linear Solvers Package
4//
5// Copyright 2004-2016 NTESS and the Belos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef BELOS_PSEUDO_BLOCK_STOCHASTIC_CG_SOLMGR_HPP
11#define BELOS_PSEUDO_BLOCK_STOCHASTIC_CG_SOLMGR_HPP
12
17#include "BelosConfigDefs.hpp"
18#include "BelosTypes.hpp"
19
22
31
32#ifdef BELOS_TEUCHOS_TIME_MONITOR
33#include "Teuchos_TimeMonitor.hpp"
34#endif
35
45namespace Belos {
46
48
49
59
60 template<class ScalarType, class MV, class OP, class DM = DefaultDenseMatrix<int,ScalarType>>
61 class PseudoBlockStochasticCGSolMgr : public SolverManager<ScalarType,MV,OP,DM> {
62
63 private:
66 typedef Teuchos::ScalarTraits<ScalarType> SCT;
67 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
68 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
69
70 public:
71
73
74
81
92 const Teuchos::RCP<Teuchos::ParameterList> &pl );
93
96
98 Teuchos::RCP<SolverManager<ScalarType, MV, OP, DM> > clone () const override {
100 }
102
104
105
107 return *problem_;
108 }
109
112 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const override;
113
116 Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const override { return params_; }
117
123 Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers() const {
124 return Teuchos::tuple(timerSolve_);
125 }
126
128 int getNumIters() const override {
129 return numIters_;
130 }
131
135 bool isLOADetected() const override { return false; }
136
138
140
141
143 void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > &problem ) override { problem_ = problem; }
144
146 void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
147
149
151
152
156 void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
158
160
161
179 ReturnType solve() override;
180
182
184 Teuchos::RCP<MV> getStochasticVector() { return Y_;}
185
188
190 std::string description() const override;
191
193
194 private:
195
196 // Linear problem.
197 Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > problem_;
198
199 // Output manager.
200 Teuchos::RCP<OutputManager<ScalarType> > printer_;
201 Teuchos::RCP<std::ostream> outputStream_;
202
203 // Status test.
204 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > sTest_;
205 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP,DM> > maxIterTest_;
206 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP,DM> > convTest_;
207 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP,DM> > outputTest_;
208
209 // Current parameter list.
210 Teuchos::RCP<Teuchos::ParameterList> params_;
211
217 mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
218
219 // Default solver values.
220 static constexpr int maxIters_default_ = 1000;
221 static constexpr bool assertPositiveDefiniteness_default_ = true;
222 static constexpr bool showMaxResNormOnly_default_ = false;
223 static constexpr int verbosity_default_ = Belos::Errors;
224 static constexpr int outputStyle_default_ = Belos::General;
225 static constexpr int outputFreq_default_ = -1;
226 static constexpr int defQuorum_default_ = 1;
227 static constexpr const char * resScale_default_ = "Norm of Initial Residual";
228 static constexpr const char * label_default_ = "Belos";
229
230 // Current solver values.
231 MagnitudeType convtol_;
232 int maxIters_, numIters_;
233 int verbosity_, outputStyle_, outputFreq_, defQuorum_;
234 bool assertPositiveDefiniteness_, showMaxResNormOnly_;
235 std::string resScale_;
236
237 // Timers.
238 std::string label_;
239 Teuchos::RCP<Teuchos::Time> timerSolve_;
240
241 // Internal state variables.
242 bool isSet_;
243
244 // Stashed copy of the stochastic vector
245 Teuchos::RCP<MV> Y_;
246
247 };
248
249
250// Empty Constructor
251template<class ScalarType, class MV, class OP, class DM>
253 outputStream_(Teuchos::rcpFromRef(std::cout)),
254 convtol_(DefaultSolverParameters::convTol),
255 maxIters_(maxIters_default_),
256 numIters_(0),
257 verbosity_(verbosity_default_),
258 outputStyle_(outputStyle_default_),
259 outputFreq_(outputFreq_default_),
260 defQuorum_(defQuorum_default_),
261 assertPositiveDefiniteness_(assertPositiveDefiniteness_default_),
262 showMaxResNormOnly_(showMaxResNormOnly_default_),
263 resScale_(resScale_default_),
264 label_(label_default_),
265 isSet_(false)
266{}
267
268// Basic Constructor
269template<class ScalarType, class MV, class OP, class DM>
272 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
273 problem_(problem),
274 outputStream_(Teuchos::rcpFromRef(std::cout)),
275 convtol_(DefaultSolverParameters::convTol),
276 maxIters_(maxIters_default_),
277 numIters_(0),
278 verbosity_(verbosity_default_),
279 outputStyle_(outputStyle_default_),
280 outputFreq_(outputFreq_default_),
281 defQuorum_(defQuorum_default_),
282 assertPositiveDefiniteness_(assertPositiveDefiniteness_default_),
283 showMaxResNormOnly_(showMaxResNormOnly_default_),
284 resScale_(resScale_default_),
285 label_(label_default_),
286 isSet_(false)
287{
289 problem_.is_null (), std::invalid_argument,
290 "Belos::PseudoBlockStochasticCGSolMgr two-argument constructor: "
291 "'problem' is null. You must supply a non-null Belos::LinearProblem "
292 "instance when calling this constructor.");
293
294 if (! pl.is_null ()) {
295 // Set the parameters using the list that was passed in.
297 }
298}
299
300template<class ScalarType, class MV, class OP, class DM>
301void PseudoBlockStochasticCGSolMgr<ScalarType,MV,OP,DM>::setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params )
302{
303 using Teuchos::ParameterList;
304 using Teuchos::parameterList;
305 using Teuchos::RCP;
306
307 RCP<const ParameterList> defaultParams = getValidParameters();
308
309 // Create the internal parameter list if one doesn't already exist.
310 if (params_.is_null()) {
311 params_ = parameterList (*defaultParams);
312 } else {
313 params->validateParameters (*defaultParams);
314 }
315
316 // Check for maximum number of iterations
317 if (params->isParameter("Maximum Iterations")) {
318 maxIters_ = params->get("Maximum Iterations",maxIters_default_);
319
320 // Update parameter in our list and in status test.
321 params_->set("Maximum Iterations", maxIters_);
322 if (maxIterTest_!=Teuchos::null)
323 maxIterTest_->setMaxIters( maxIters_ );
324 }
325
326 // Check if positive definiteness assertions are to be performed
327 if (params->isParameter("Assert Positive Definiteness")) {
328 assertPositiveDefiniteness_ = params->get("Assert Positive Definiteness",assertPositiveDefiniteness_default_);
329
330 // Update parameter in our list.
331 params_->set("Assert Positive Definiteness", assertPositiveDefiniteness_);
332 }
333
334 // Check to see if the timer label changed.
335 if (params->isParameter("Timer Label")) {
336 std::string tempLabel = params->get("Timer Label", label_default_);
337
338 // Update parameter in our list and solver timer
339 if (tempLabel != label_) {
340 label_ = tempLabel;
341 params_->set("Timer Label", label_);
342 std::string solveLabel = label_ + ": PseudoBlockStochasticCGSolMgr total solve time";
343#ifdef BELOS_TEUCHOS_TIME_MONITOR
344 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
345#endif
346 }
347 }
348
349 // Check for a change in verbosity level
350 if (params->isParameter("Verbosity")) {
351 if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
352 verbosity_ = params->get("Verbosity", verbosity_default_);
353 } else {
354 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
355 }
356
357 // Update parameter in our list.
358 params_->set("Verbosity", verbosity_);
359 if (printer_ != Teuchos::null)
360 printer_->setVerbosity(verbosity_);
361 }
362
363 // Check for a change in output style
364 if (params->isParameter("Output Style")) {
365 if (Teuchos::isParameterType<int>(*params,"Output Style")) {
366 outputStyle_ = params->get("Output Style", outputStyle_default_);
367 } else {
368 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
369 }
370
371 // Reconstruct the convergence test if the explicit residual test is not being used.
372 params_->set("Output Style", outputStyle_);
373 outputTest_ = Teuchos::null;
374 }
375
376 // output stream
377 if (params->isParameter("Output Stream")) {
378 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
379
380 // Update parameter in our list.
381 params_->set("Output Stream", outputStream_);
382 if (printer_ != Teuchos::null)
383 printer_->setOStream( outputStream_ );
384 }
385
386 // frequency level
387 if (verbosity_ & Belos::StatusTestDetails) {
388 if (params->isParameter("Output Frequency")) {
389 outputFreq_ = params->get("Output Frequency", outputFreq_default_);
390 }
391
392 // Update parameter in out list and output status test.
393 params_->set("Output Frequency", outputFreq_);
394 if (outputTest_ != Teuchos::null)
395 outputTest_->setOutputFrequency( outputFreq_ );
396 }
397
398 // Create output manager if we need to.
399 if (printer_ == Teuchos::null) {
400 printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
401 }
402
403 // Convergence
404 typedef Belos::StatusTestCombo<ScalarType,MV,OP,DM> StatusTestCombo_t;
405 typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP,DM> StatusTestResNorm_t;
406
407 // Check for convergence tolerance
408 if (params->isParameter("Convergence Tolerance")) {
409 if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
410 convtol_ = params->get ("Convergence Tolerance",
411 static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
412 }
413 else {
414 convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
415 }
416
417 // Update parameter in our list and residual tests.
418 params_->set("Convergence Tolerance", convtol_);
419 if (convTest_ != Teuchos::null)
420 convTest_->setTolerance( convtol_ );
421 }
422
423 if (params->isParameter("Show Maximum Residual Norm Only")) {
424 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
425
426 // Update parameter in our list and residual tests
427 params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
428 if (convTest_ != Teuchos::null)
429 convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
430 }
431
432 // Check for a change in scaling, if so we need to build new residual tests.
433 bool newResTest = false;
434 {
435 // "Residual Scaling" is the old parameter name; "Implicit
436 // Residual Scaling" is the new name. We support both options for
437 // backwards compatibility.
438 std::string tempResScale = resScale_;
439 bool implicitResidualScalingName = false;
440 if (params->isParameter ("Residual Scaling")) {
441 tempResScale = params->get<std::string> ("Residual Scaling");
442 }
443 else if (params->isParameter ("Implicit Residual Scaling")) {
444 tempResScale = params->get<std::string> ("Implicit Residual Scaling");
446 }
447
448 // Only update the scaling if it's different.
449 if (resScale_ != tempResScale) {
451 resScale_ = tempResScale;
452
453 // Update parameter in our list and residual tests, using the
454 // given parameter name.
456 params_->set ("Implicit Residual Scaling", resScale_);
457 }
458 else {
459 params_->set ("Residual Scaling", resScale_);
460 }
461
462 if (! convTest_.is_null()) {
463 try {
464 convTest_->defineScaleForm( resScaleType, Belos::TwoNorm );
465 }
466 catch (std::exception& e) {
467 // Make sure the convergence test gets constructed again.
468 newResTest = true;
469 }
470 }
471 }
472 }
473
474 // Get the deflation quorum, or number of converged systems before deflation is allowed
475 if (params->isParameter("Deflation Quorum")) {
476 defQuorum_ = params->get("Deflation Quorum", defQuorum_);
477 params_->set("Deflation Quorum", defQuorum_);
478 if (convTest_ != Teuchos::null)
479 convTest_->setQuorum( defQuorum_ );
480 }
481
482 // Create status tests if we need to.
483
484 // Basic test checks maximum iterations and native residual.
485 if (maxIterTest_ == Teuchos::null)
486 maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP,DM>( maxIters_ ) );
487
488 // Implicit residual test, using the native residual to determine if convergence was achieved.
489 if (convTest_ == Teuchos::null || newResTest) {
490 convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, defQuorum_, showMaxResNormOnly_ ) );
491 convTest_->defineScaleForm( convertStringToScaleType( resScale_ ), Belos::TwoNorm );
492 }
493
494 if (sTest_ == Teuchos::null || newResTest)
495 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
496
497 if (outputTest_ == Teuchos::null || newResTest) {
498
499 // Create the status test output class.
500 // This class manages and formats the output from the status test.
502 outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
503
504 // Set the solver string for the output test
505 std::string solverDesc = " Pseudo Block CG ";
506 outputTest_->setSolverDesc( solverDesc );
507
508 }
509
510 // Create the timer if we need to.
511 if (timerSolve_ == Teuchos::null) {
512 std::string solveLabel = label_ + ": PseudoBlockStochasticCGSolMgr total solve time";
513#ifdef BELOS_TEUCHOS_TIME_MONITOR
514 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
515#endif
516 }
517
518 // Inform the solver manager that the current parameters were set.
519 isSet_ = true;
520}
521
522
523template<class ScalarType, class MV, class OP, class DM>
524Teuchos::RCP<const Teuchos::ParameterList>
526{
527 using Teuchos::ParameterList;
528 using Teuchos::parameterList;
529 using Teuchos::RCP;
530
531 if (validParams_.is_null()) {
532 // Set all the valid parameters and their default values.
533
534 // The static_cast is to resolve an issue with older clang versions which
535 // would cause the constexpr to link fail. With c++17 the problem is resolved.
537 pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
538 "The relative residual tolerance that needs to be achieved by the\n"
539 "iterative solver in order for the linera system to be declared converged.");
540 pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
541 "The maximum number of block iterations allowed for each\n"
542 "set of RHS solved.");
543 pl->set("Assert Positive Definiteness", static_cast<bool>(assertPositiveDefiniteness_default_),
544 "Whether or not to assert that the linear operator\n"
545 "and the preconditioner are indeed positive definite.");
546 pl->set("Verbosity", static_cast<int>(verbosity_default_),
547 "What type(s) of solver information should be outputted\n"
548 "to the output stream.");
549 pl->set("Output Style", static_cast<int>(outputStyle_default_),
550 "What style is used for the solver information outputted\n"
551 "to the output stream.");
552 pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
553 "How often convergence information should be outputted\n"
554 "to the output stream.");
555 pl->set("Deflation Quorum", static_cast<int>(defQuorum_default_),
556 "The number of linear systems that need to converge before\n"
557 "they are deflated. This number should be <= block size.");
558 pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
559 "A reference-counted pointer to the output stream where all\n"
560 "solver output is sent.");
561 pl->set("Show Maximum Residual Norm Only", static_cast<bool>(showMaxResNormOnly_default_),
562 "When convergence information is printed, only show the maximum\n"
563 "relative residual norm when the block size is greater than one.");
564 pl->set("Implicit Residual Scaling", resScale_default_,
565 "The type of scaling used in the residual convergence test.");
566 // We leave the old name as a valid parameter for backwards
567 // compatibility (so that validateParametersAndSetDefaults()
568 // doesn't raise an exception if it encounters "Residual
569 // Scaling"). The new name was added for compatibility with other
570 // solvers, none of which use "Residual Scaling".
571 pl->set("Residual Scaling", resScale_default_,
572 "The type of scaling used in the residual convergence test. This "
573 "name is deprecated; the new name is \"Implicit Residual Scaling\".");
574 pl->set("Timer Label", static_cast<const char *>(label_default_),
575 "The string to use as a prefix for the timer labels.");
576 validParams_ = pl;
577 }
578 return validParams_;
579}
580
581
582// solve()
583template<class ScalarType, class MV, class OP, class DM>
586
587 // Set the current parameters if they were not set before.
588 // NOTE: This may occur if the user generated the solver manager with the default constructor and
589 // then didn't set any parameters using setParameters().
590 if (!isSet_) { setParameters( params_ ); }
591
593 "Belos::PseudoBlockStochasticCGSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
594
595 // Create indices for the linear systems to be solved.
596 int startPtr = 0;
597 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
599
600 std::vector<int> currIdx( numRHS2Solve ), currIdx2( numRHS2Solve );
601 for (int i=0; i<numRHS2Solve; ++i) {
602 currIdx[i] = startPtr+i;
603 currIdx2[i]=i;
604 }
605
606 // Inform the linear problem of the current linear system to solve.
607 problem_->setLSIndex( currIdx );
608
610 // Parameter list
611 Teuchos::ParameterList plist;
612
613 plist.set("Assert Positive Definiteness",assertPositiveDefiniteness_);
614
615 // Reset the status test.
616 outputTest_->reset();
617
618 // Assume convergence is achieved, then let any failed convergence set this to false.
619 bool isConverged = true;
620
622 // Pseudo-Block CG solver
623
624 Teuchos::RCP<PseudoBlockStochasticCGIter<ScalarType,MV,OP,DM> > block_cg_iter
625 = Teuchos::rcp( new PseudoBlockStochasticCGIter<ScalarType,MV,OP,DM>(problem_,printer_,outputTest_,plist) );
626
627 // Enter solve() iterations
628 {
629#ifdef BELOS_TEUCHOS_TIME_MONITOR
630 Teuchos::TimeMonitor slvtimer(*timerSolve_);
631#endif
632
633 while ( numRHS2Solve > 0 ) {
634
635 // Reset the active / converged vectors from this block
636 std::vector<int> convRHSIdx;
637 std::vector<int> currRHSIdx( currIdx );
638 currRHSIdx.resize(numCurrRHS);
639
640 // Reset the number of iterations.
641 block_cg_iter->resetNumIters();
642
643 // Reset the number of calls that the status test output knows about.
644 outputTest_->resetNumCalls();
645
646 // Get the current residual for this block of linear systems.
647 Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
648
649 // Get a new state struct and initialize the solver.
651 newState.R = R_0;
652 block_cg_iter->initializeCG(newState);
653
654 while(1) {
655
656 // tell block_gmres_iter to iterate
657 try {
658 block_cg_iter->iterate();
659
661 //
662 // check convergence first
663 //
665 if ( convTest_->getStatus() == Passed ) {
666
667 // Figure out which linear systems converged.
668 std::vector<int> convIdx = Teuchos::rcp_dynamic_cast<StatusTestGenResNorm<ScalarType,MV,OP,DM> >(convTest_)->convIndices();
669
670 // If the number of converged linear systems is equal to the
671 // number of current linear systems, then we are done with this block.
672 if (convIdx.size() == currRHSIdx.size())
673 break; // break from while(1){block_cg_iter->iterate()}
674
675 // Inform the linear problem that we are finished with this current linear system.
676 problem_->setCurrLS();
677
678 // Reset currRHSIdx to have the right-hand sides that are left to converge for this block.
679 int have = 0;
680 std::vector<int> unconvIdx(currRHSIdx.size());
681 for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
682 bool found = false;
683 for (unsigned int j=0; j<convIdx.size(); ++j) {
684 if (currRHSIdx[i] == convIdx[j]) {
685 found = true;
686 break;
687 }
688 }
689 if (!found) {
692 }
693 }
694 currRHSIdx.resize(have);
695 currIdx2.resize(have);
696
697 // Set the remaining indices after deflation.
698 problem_->setLSIndex( currRHSIdx );
699
700 // Get the current residual vector.
701 std::vector<MagnitudeType> norms;
702 R_0 = MVT::CloneCopy( *(block_cg_iter->getNativeResiduals(&norms)),currIdx2 );
703 for (int i=0; i<have; ++i) { currIdx2[i] = i; }
704
705 // Set the new state and initialize the solver.
707 defstate.R = R_0;
708 block_cg_iter->initializeCG(defstate);
709 }
710
712 //
713 // check for maximum iterations
714 //
716 else if ( maxIterTest_->getStatus() == Passed ) {
717 // we don't have convergence
719 isConverged = false;
720 break; // break from while(1){block_cg_iter->iterate()}
721 }
722
724 //
725 // we returned from iterate(), but none of our status tests Passed.
726 // something is wrong, and it is probably our fault.
727 //
729
730 else {
732 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
733 "Belos::PseudoBlockStochasticCGSolMgr::solve(): Invalid return from PseudoBlockStochasticCGIter::iterate().");
734 }
735 }
736 catch (const std::exception &e) {
738 printer_->stream(Errors) << "Error! Caught std::exception in PseudoBlockStochasticCGIter::iterate() at iteration "
739 << block_cg_iter->getNumIters() << std::endl
740 << e.what() << std::endl;
741 throw;
742 }
743 }
744
745 // Inform the linear problem that we are finished with this block linear system.
746 problem_->setCurrLS();
747
748 // Update indices for the linear systems to be solved.
751
752 if ( numRHS2Solve > 0 ) {
753
755 currIdx.resize( numCurrRHS );
756 currIdx2.resize( numCurrRHS );
757 for (int i=0; i<numCurrRHS; ++i)
758 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
759
760 // Set the next indices.
761 problem_->setLSIndex( currIdx );
762 }
763 else {
764 currIdx.resize( numRHS2Solve );
765 }
766
767 }// while ( numRHS2Solve > 0 )
768
769 }
770
771 // get the final stochastic vector
772 Y_=block_cg_iter->getStochasticVector();
773
774
775 // print final summary
776 sTest_->print( printer_->stream(FinalSummary) );
777
778 // print timing information
779#ifdef BELOS_TEUCHOS_TIME_MONITOR
780 // Calling summarize() can be expensive, so don't call unless the
781 // user wants to print out timing details. summarize() will do all
782 // the work even if it's passed a "black hole" output stream.
783 if (verbosity_ & TimingDetails)
784 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
785#endif
786
787 // get iteration information for this solve
788 numIters_ = maxIterTest_->getNumIters();
789
790 if (!isConverged ) {
791 return retType; // return from PseudoBlockStochasticCGSolMgr::solve()
792 }
793 return Converged; // return from PseudoBlockStochasticCGSolMgr::solve()
794}
795
796// This method requires the solver manager to return a std::string that describes itself.
797template<class ScalarType, class MV, class OP, class DM>
799{
800 std::ostringstream oss;
801 oss << "Belos::PseudoBlockStochasticCGSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
802 oss << "{";
803 oss << "}";
804 return oss.str();
805}
806
807} // end Belos namespace
808
809#endif /* BELOS_PSEUDO_BLOCK_CG_SOLMGR_HPP */
Belos header file which uses auto-configuration information to include necessary C++ headers.
Full specialization of Belos::DenseMatTraits for Kokkos::DualView with arbitrary scalarType....
Class which describes the linear problem to be solved by the iterative solver.
Class which manages the output and verbosity of the Belos solvers.
Belos concrete class for performing the stochastic pseudo-block CG iteration.
Pure virtual base class which describes the basic interface for a solver manager.
Belos::StatusTest for logically combining several status tests.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Full specialization of Belos::DenseMatTraits for Teuchos::SerialDenseMatrix with ordinal type int and...
Collection of types and exceptions used within the Belos solvers.
Parent class to all Belos exceptions.
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
The Belos::PseudoBlockStochasticCGSolMgr provides a powerful and fully-featured solver manager over t...
std::string description() const override
Method to return description of the block CG solver manager.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
Teuchos::RCP< MV > getStochasticVector()
Get a copy of the final stochastic vector.
Teuchos::RCP< SolverManager< ScalarType, MV, OP, DM > > clone() const override
clone for Inverted Injection (DII)
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
PseudoBlockStochasticCGSolMgr()
Empty constructor for BlockStochasticCGSolMgr. This constructor takes no arguments and sets the defau...
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem) override
Set the linear problem that needs to be solved.
int getNumIters() const override
Get the iteration count for the most recent call to solve().
PseudoBlockStochasticCGSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
@ StatusTestDetails
@ FinalSummary
@ TimingDetails
ReturnType
Whether the Belos solve converged for all linear systems.
@ MaxItersReached
@ NonspecificException
@ InconsistentState
@ Undetermined
ScaleType
The type of scaling to use on the residual norm value.
ResetType
How to reset the solver.
Default parameters common to most Belos solvers.
static const double convTol
Default convergence tolerance.

Generated for Belos by doxygen 1.9.8