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
150 debugStatusTest_ = debugStatusTest;
151 // Force the cached status-test tree (and its output wrapper) to be rebuilt
152 // on the next solve so the debug test is wired into sTest_. This manager
153 // caches sTest_/outputTest_ behind null checks, so clear them and re-run
154 // setParameters.
155 sTest_ = Teuchos::null;
156 outputTest_ = Teuchos::null;
157 isSet_ = false;
158 }
159
161
163
164
168 void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
170
172
173
191 ReturnType solve() override;
192
194
196 Teuchos::RCP<MV> getStochasticVector() { return Y_;}
197
200
202 std::string description() const override;
203
205
206 private:
207
208 // Linear problem.
209 Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > problem_;
210
211 // Output manager.
212 Teuchos::RCP<OutputManager<ScalarType> > printer_;
213 Teuchos::RCP<std::ostream> outputStream_;
214
215 // Status test.
216 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > sTest_;
217 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP,DM> > maxIterTest_;
218 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP,DM> > convTest_;
219 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP,DM> > outputTest_;
220 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > debugStatusTest_;
221
222 // Current parameter list.
223 Teuchos::RCP<Teuchos::ParameterList> params_;
224
230 mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
231
232 // Default solver values.
233 static constexpr int maxIters_default_ = 1000;
234 static constexpr bool assertPositiveDefiniteness_default_ = true;
235 static constexpr bool showMaxResNormOnly_default_ = false;
236 static constexpr int verbosity_default_ = Belos::Errors;
237 static constexpr int outputStyle_default_ = Belos::General;
238 static constexpr int outputFreq_default_ = -1;
239 static constexpr int defQuorum_default_ = 1;
240 static constexpr const char * resScale_default_ = "Norm of Initial Residual";
241 static constexpr const char * label_default_ = "Belos";
242
243 // Current solver values.
244 MagnitudeType convtol_;
245 int maxIters_, numIters_;
246 int verbosity_, outputStyle_, outputFreq_, defQuorum_;
247 bool assertPositiveDefiniteness_, showMaxResNormOnly_;
248 std::string resScale_;
249
250 // Timers.
251 std::string label_;
252 Teuchos::RCP<Teuchos::Time> timerSolve_;
253
254 // Internal state variables.
255 bool isSet_;
256
257 // Stashed copy of the stochastic vector
258 Teuchos::RCP<MV> Y_;
259
260 };
261
262
263// Empty Constructor
264template<class ScalarType, class MV, class OP, class DM>
266 outputStream_(Teuchos::rcpFromRef(std::cout)),
267 convtol_(DefaultSolverParameters::convTol),
268 maxIters_(maxIters_default_),
269 numIters_(0),
270 verbosity_(verbosity_default_),
271 outputStyle_(outputStyle_default_),
272 outputFreq_(outputFreq_default_),
273 defQuorum_(defQuorum_default_),
274 assertPositiveDefiniteness_(assertPositiveDefiniteness_default_),
275 showMaxResNormOnly_(showMaxResNormOnly_default_),
276 resScale_(resScale_default_),
277 label_(label_default_),
278 isSet_(false)
279{}
280
281// Basic Constructor
282template<class ScalarType, class MV, class OP, class DM>
285 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
286 problem_(problem),
287 outputStream_(Teuchos::rcpFromRef(std::cout)),
288 convtol_(DefaultSolverParameters::convTol),
289 maxIters_(maxIters_default_),
290 numIters_(0),
291 verbosity_(verbosity_default_),
292 outputStyle_(outputStyle_default_),
293 outputFreq_(outputFreq_default_),
294 defQuorum_(defQuorum_default_),
295 assertPositiveDefiniteness_(assertPositiveDefiniteness_default_),
296 showMaxResNormOnly_(showMaxResNormOnly_default_),
297 resScale_(resScale_default_),
298 label_(label_default_),
299 isSet_(false)
300{
302 problem_.is_null (), std::invalid_argument,
303 "Belos::PseudoBlockStochasticCGSolMgr two-argument constructor: "
304 "'problem' is null. You must supply a non-null Belos::LinearProblem "
305 "instance when calling this constructor.");
306
307 if (! pl.is_null ()) {
308 // Set the parameters using the list that was passed in.
310 }
311}
312
313template<class ScalarType, class MV, class OP, class DM>
314void PseudoBlockStochasticCGSolMgr<ScalarType,MV,OP,DM>::setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params )
315{
316 using Teuchos::ParameterList;
317 using Teuchos::parameterList;
318 using Teuchos::RCP;
319
320 RCP<const ParameterList> defaultParams = getValidParameters();
321
322 // Create the internal parameter list if one doesn't already exist.
323 if (params_.is_null()) {
324 params_ = parameterList (*defaultParams);
325 } else {
326 params->validateParameters (*defaultParams);
327 }
328
329 // Check for maximum number of iterations
330 if (params->isParameter("Maximum Iterations")) {
331 maxIters_ = params->get("Maximum Iterations",maxIters_default_);
332
333 // Update parameter in our list and in status test.
334 params_->set("Maximum Iterations", maxIters_);
335 if (maxIterTest_!=Teuchos::null)
336 maxIterTest_->setMaxIters( maxIters_ );
337 }
338
339 // Check if positive definiteness assertions are to be performed
340 if (params->isParameter("Assert Positive Definiteness")) {
341 assertPositiveDefiniteness_ = params->get("Assert Positive Definiteness",assertPositiveDefiniteness_default_);
342
343 // Update parameter in our list.
344 params_->set("Assert Positive Definiteness", assertPositiveDefiniteness_);
345 }
346
347 // Check to see if the timer label changed.
348 if (params->isParameter("Timer Label")) {
349 std::string tempLabel = params->get("Timer Label", label_default_);
350
351 // Update parameter in our list and solver timer
352 if (tempLabel != label_) {
353 label_ = tempLabel;
354 params_->set("Timer Label", label_);
355 std::string solveLabel = label_ + ": PseudoBlockStochasticCGSolMgr total solve time";
356#ifdef BELOS_TEUCHOS_TIME_MONITOR
357 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
358#endif
359 }
360 }
361
362 // Check for a change in verbosity level
363 if (params->isParameter("Verbosity")) {
364 if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
365 verbosity_ = params->get("Verbosity", verbosity_default_);
366 } else {
367 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
368 }
369
370 // Update parameter in our list.
371 params_->set("Verbosity", verbosity_);
372 if (printer_ != Teuchos::null)
373 printer_->setVerbosity(verbosity_);
374 }
375
376 // Check for a change in output style
377 if (params->isParameter("Output Style")) {
378 if (Teuchos::isParameterType<int>(*params,"Output Style")) {
379 outputStyle_ = params->get("Output Style", outputStyle_default_);
380 } else {
381 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
382 }
383
384 // Reconstruct the convergence test if the explicit residual test is not being used.
385 params_->set("Output Style", outputStyle_);
386 outputTest_ = Teuchos::null;
387 }
388
389 // output stream
390 if (params->isParameter("Output Stream")) {
391 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
392
393 // Update parameter in our list.
394 params_->set("Output Stream", outputStream_);
395 if (printer_ != Teuchos::null)
396 printer_->setOStream( outputStream_ );
397 }
398
399 // frequency level
400 if (verbosity_ & Belos::StatusTestDetails) {
401 if (params->isParameter("Output Frequency")) {
402 outputFreq_ = params->get("Output Frequency", outputFreq_default_);
403 }
404
405 // Update parameter in out list and output status test.
406 params_->set("Output Frequency", outputFreq_);
407 if (outputTest_ != Teuchos::null)
408 outputTest_->setOutputFrequency( outputFreq_ );
409 }
410
411 // Create output manager if we need to.
412 if (printer_ == Teuchos::null) {
413 printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
414 }
415
416 // Convergence
417 typedef Belos::StatusTestCombo<ScalarType,MV,OP,DM> StatusTestCombo_t;
418 typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP,DM> StatusTestResNorm_t;
419
420 // Check for convergence tolerance
421 if (params->isParameter("Convergence Tolerance")) {
422 if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
423 convtol_ = params->get ("Convergence Tolerance",
424 static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
425 }
426 else {
427 convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
428 }
429
430 // Update parameter in our list and residual tests.
431 params_->set("Convergence Tolerance", convtol_);
432 if (convTest_ != Teuchos::null)
433 convTest_->setTolerance( convtol_ );
434 }
435
436 if (params->isParameter("Show Maximum Residual Norm Only")) {
437 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
438
439 // Update parameter in our list and residual tests
440 params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
441 if (convTest_ != Teuchos::null)
442 convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
443 }
444
445 // Check for a change in scaling, if so we need to build new residual tests.
446 bool newResTest = false;
447 {
448 // "Residual Scaling" is the old parameter name; "Implicit
449 // Residual Scaling" is the new name. We support both options for
450 // backwards compatibility.
451 std::string tempResScale = resScale_;
452 bool implicitResidualScalingName = false;
453 if (params->isParameter ("Residual Scaling")) {
454 tempResScale = params->get<std::string> ("Residual Scaling");
455 }
456 else if (params->isParameter ("Implicit Residual Scaling")) {
457 tempResScale = params->get<std::string> ("Implicit Residual Scaling");
459 }
460
461 // Only update the scaling if it's different.
462 if (resScale_ != tempResScale) {
464 resScale_ = tempResScale;
465
466 // Update parameter in our list and residual tests, using the
467 // given parameter name.
469 params_->set ("Implicit Residual Scaling", resScale_);
470 }
471 else {
472 params_->set ("Residual Scaling", resScale_);
473 }
474
475 if (! convTest_.is_null()) {
476 try {
477 convTest_->defineScaleForm( resScaleType, Belos::TwoNorm );
478 }
479 catch (std::exception& e) {
480 // Make sure the convergence test gets constructed again.
481 newResTest = true;
482 }
483 }
484 }
485 }
486
487 // Get the deflation quorum, or number of converged systems before deflation is allowed
488 if (params->isParameter("Deflation Quorum")) {
489 defQuorum_ = params->get("Deflation Quorum", defQuorum_);
490 params_->set("Deflation Quorum", defQuorum_);
491 if (convTest_ != Teuchos::null)
492 convTest_->setQuorum( defQuorum_ );
493 }
494
495 // Create status tests if we need to.
496
497 // Basic test checks maximum iterations and native residual.
498 if (maxIterTest_ == Teuchos::null)
499 maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP,DM>( maxIters_ ) );
500
501 // Implicit residual test, using the native residual to determine if convergence was achieved.
502 if (convTest_ == Teuchos::null || newResTest) {
503 convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, defQuorum_, showMaxResNormOnly_ ) );
504 convTest_->defineScaleForm( convertStringToScaleType( resScale_ ), Belos::TwoNorm );
505 }
506
507 if (sTest_ == Teuchos::null || newResTest) {
508 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
509 if (Teuchos::nonnull(debugStatusTest_)) {
510 // Add the debug convergence test, if it exists.
511 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, sTest_, debugStatusTest_ ) );
512 }
513 }
514
515 if (outputTest_ == Teuchos::null || newResTest) {
516
517 // Create the status test output class.
518 // This class manages and formats the output from the status test.
520 outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
521
522 // Set the solver string for the output test
523 std::string solverDesc = " Pseudo Block CG ";
524 outputTest_->setSolverDesc( solverDesc );
525
526 }
527
528 // Create the timer if we need to.
529 if (timerSolve_ == Teuchos::null) {
530 std::string solveLabel = label_ + ": PseudoBlockStochasticCGSolMgr total solve time";
531#ifdef BELOS_TEUCHOS_TIME_MONITOR
532 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
533#endif
534 }
535
536 // Inform the solver manager that the current parameters were set.
537 isSet_ = true;
538}
539
540
541template<class ScalarType, class MV, class OP, class DM>
542Teuchos::RCP<const Teuchos::ParameterList>
544{
545 using Teuchos::ParameterList;
546 using Teuchos::parameterList;
547 using Teuchos::RCP;
548
549 if (validParams_.is_null()) {
550 // Set all the valid parameters and their default values.
551
552 // The static_cast is to resolve an issue with older clang versions which
553 // would cause the constexpr to link fail. With c++17 the problem is resolved.
555 pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
556 "The relative residual tolerance that needs to be achieved by the\n"
557 "iterative solver in order for the linera system to be declared converged.");
558 pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
559 "The maximum number of block iterations allowed for each\n"
560 "set of RHS solved.");
561 pl->set("Assert Positive Definiteness", static_cast<bool>(assertPositiveDefiniteness_default_),
562 "Whether or not to assert that the linear operator\n"
563 "and the preconditioner are indeed positive definite.");
564 pl->set("Verbosity", static_cast<int>(verbosity_default_),
565 "What type(s) of solver information should be outputted\n"
566 "to the output stream.");
567 pl->set("Output Style", static_cast<int>(outputStyle_default_),
568 "What style is used for the solver information outputted\n"
569 "to the output stream.");
570 pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
571 "How often convergence information should be outputted\n"
572 "to the output stream.");
573 pl->set("Deflation Quorum", static_cast<int>(defQuorum_default_),
574 "The number of linear systems that need to converge before\n"
575 "they are deflated. This number should be <= block size.");
576 pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
577 "A reference-counted pointer to the output stream where all\n"
578 "solver output is sent.");
579 pl->set("Show Maximum Residual Norm Only", static_cast<bool>(showMaxResNormOnly_default_),
580 "When convergence information is printed, only show the maximum\n"
581 "relative residual norm when the block size is greater than one.");
582 pl->set("Implicit Residual Scaling", resScale_default_,
583 "The type of scaling used in the residual convergence test.");
584 // We leave the old name as a valid parameter for backwards
585 // compatibility (so that validateParametersAndSetDefaults()
586 // doesn't raise an exception if it encounters "Residual
587 // Scaling"). The new name was added for compatibility with other
588 // solvers, none of which use "Residual Scaling".
589 pl->set("Residual Scaling", resScale_default_,
590 "The type of scaling used in the residual convergence test. This "
591 "name is deprecated; the new name is \"Implicit Residual Scaling\".");
592 pl->set("Timer Label", static_cast<const char *>(label_default_),
593 "The string to use as a prefix for the timer labels.");
594 validParams_ = pl;
595 }
596 return validParams_;
597}
598
599
600// solve()
601template<class ScalarType, class MV, class OP, class DM>
604
605 // Set the current parameters if they were not set before.
606 // NOTE: This may occur if the user generated the solver manager with the default constructor and
607 // then didn't set any parameters using setParameters().
608 if (!isSet_) { setParameters( params_ ); }
609
611 "Belos::PseudoBlockStochasticCGSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
612
613 // Create indices for the linear systems to be solved.
614 int startPtr = 0;
615 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
617
618 std::vector<int> currIdx( numRHS2Solve ), currIdx2( numRHS2Solve );
619 for (int i=0; i<numRHS2Solve; ++i) {
620 currIdx[i] = startPtr+i;
621 currIdx2[i]=i;
622 }
623
624 // Inform the linear problem of the current linear system to solve.
625 problem_->setLSIndex( currIdx );
626
628 // Parameter list
629 Teuchos::ParameterList plist;
630
631 plist.set("Assert Positive Definiteness",assertPositiveDefiniteness_);
632
633 // Reset the status test.
634 outputTest_->reset();
635
636 // Assume convergence is achieved, then let any failed convergence set this to false.
637 bool isConverged = true;
638
640 // Pseudo-Block CG solver
641
642 Teuchos::RCP<PseudoBlockStochasticCGIter<ScalarType,MV,OP,DM> > block_cg_iter
643 = Teuchos::rcp( new PseudoBlockStochasticCGIter<ScalarType,MV,OP,DM>(problem_,printer_,outputTest_,plist) );
644
645 // Enter solve() iterations
646 {
647#ifdef BELOS_TEUCHOS_TIME_MONITOR
648 Teuchos::TimeMonitor slvtimer(*timerSolve_);
649#endif
650
651 while ( numRHS2Solve > 0 ) {
652
653 // Reset the active / converged vectors from this block
654 std::vector<int> convRHSIdx;
655 std::vector<int> currRHSIdx( currIdx );
656 currRHSIdx.resize(numCurrRHS);
657
658 // Reset the number of iterations.
659 block_cg_iter->resetNumIters();
660
661 // Reset the number of calls that the status test output knows about.
662 outputTest_->resetNumCalls();
663
664 // Get the current residual for this block of linear systems.
665 Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
666
667 // Get a new state struct and initialize the solver.
669 newState.R = R_0;
670 block_cg_iter->initializeCG(newState);
671
672 while(1) {
673
674 // tell block_gmres_iter to iterate
675 try {
676 block_cg_iter->iterate();
677
679 //
680 // check convergence first
681 //
683 if ( convTest_->getStatus() == Passed ) {
684
685 // Figure out which linear systems converged.
686 std::vector<int> convIdx = Teuchos::rcp_dynamic_cast<StatusTestGenResNorm<ScalarType,MV,OP,DM> >(convTest_)->convIndices();
687
688 // If the number of converged linear systems is equal to the
689 // number of current linear systems, then we are done with this block.
690 if (convIdx.size() == currRHSIdx.size())
691 break; // break from while(1){block_cg_iter->iterate()}
692
693 // Inform the linear problem that we are finished with this current linear system.
694 problem_->setCurrLS();
695
696 // Reset currRHSIdx to have the right-hand sides that are left to converge for this block.
697 int have = 0;
698 std::vector<int> unconvIdx(currRHSIdx.size());
699 for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
700 bool found = false;
701 for (unsigned int j=0; j<convIdx.size(); ++j) {
702 if (currRHSIdx[i] == convIdx[j]) {
703 found = true;
704 break;
705 }
706 }
707 if (!found) {
710 }
711 }
712 currRHSIdx.resize(have);
713 currIdx2.resize(have);
714
715 // Set the remaining indices after deflation.
716 problem_->setLSIndex( currRHSIdx );
717
718 // Get the current residual vector.
719 std::vector<MagnitudeType> norms;
720 R_0 = MVT::CloneCopy( *(block_cg_iter->getNativeResiduals(&norms)),currIdx2 );
721 for (int i=0; i<have; ++i) { currIdx2[i] = i; }
722
723 // Set the new state and initialize the solver.
725 defstate.R = R_0;
726 block_cg_iter->initializeCG(defstate);
727 }
728
730 //
731 // check for maximum iterations
732 //
734 else if ( maxIterTest_->getStatus() == Passed ) {
735 // we don't have convergence
737 isConverged = false;
738 break; // break from while(1){block_cg_iter->iterate()}
739 }
740
742 //
743 // a debug status test (if any) stopped the iteration
744 //
746 else if (Teuchos::nonnull(debugStatusTest_) &&
747 debugStatusTest_->getStatus() == Passed) {
748 // we don't have convergence, but a debug test asked us to stop
750 isConverged = false;
751 break; // break from while(1){block_cg_iter->iterate()}
752 }
753
755 //
756 // we returned from iterate(), but none of our status tests Passed.
757 // something is wrong, and it is probably our fault.
758 //
760
761 else {
763 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
764 "Belos::PseudoBlockStochasticCGSolMgr::solve(): Invalid return from PseudoBlockStochasticCGIter::iterate().");
765 }
766 }
767 catch (const std::exception &e) {
769 printer_->stream(Errors) << "Error! Caught std::exception in PseudoBlockStochasticCGIter::iterate() at iteration "
770 << block_cg_iter->getNumIters() << std::endl
771 << e.what() << std::endl;
772 throw;
773 }
774 }
775
776 // Inform the linear problem that we are finished with this block linear system.
777 problem_->setCurrLS();
778
779 // Update indices for the linear systems to be solved.
782
783 if ( numRHS2Solve > 0 ) {
784
786 currIdx.resize( numCurrRHS );
787 currIdx2.resize( numCurrRHS );
788 for (int i=0; i<numCurrRHS; ++i)
789 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
790
791 // Set the next indices.
792 problem_->setLSIndex( currIdx );
793 }
794 else {
795 currIdx.resize( numRHS2Solve );
796 }
797
798 }// while ( numRHS2Solve > 0 )
799
800 }
801
802 // get the final stochastic vector
803 Y_=block_cg_iter->getStochasticVector();
804
805
806 // print final summary
807 sTest_->print( printer_->stream(FinalSummary) );
808
809 // print timing information
810#ifdef BELOS_TEUCHOS_TIME_MONITOR
811 // Calling summarize() can be expensive, so don't call unless the
812 // user wants to print out timing details. summarize() will do all
813 // the work even if it's passed a "black hole" output stream.
814 if (verbosity_ & TimingDetails)
815 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
816#endif
817
818 // get iteration information for this solve
819 numIters_ = maxIterTest_->getNumIters();
820
821 if (!isConverged ) {
822 return retType; // return from PseudoBlockStochasticCGSolMgr::solve()
823 }
824 return Converged; // return from PseudoBlockStochasticCGSolMgr::solve()
825}
826
827// This method requires the solver manager to return a std::string that describes itself.
828template<class ScalarType, class MV, class OP, class DM>
830{
831 std::ostringstream oss;
832 oss << "Belos::PseudoBlockStochasticCGSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
833 oss << "{";
834 oss << "}";
835 return oss.str();
836}
837
838} // end Belos namespace
839
840#ifdef HAVE_BELOS_TPETRA
842
843#define BELOS_TPETRA_PSEUDOBLOCKSTOCHASTICCGSOLMGR_NOEXTERN_CALL(SC, LO, GO, NT) \
844 BELOS_TPETRA_CALL(Belos::PseudoBlockStochasticCGSolMgr, SC, LO, GO, NT)
845
846#define BELOS_TPETRA_PSEUDOBLOCKSTOCHASTICCGSOLMGR_EXTERN_CALL(SC, LO, GO, NT) \
847 BELOS_TPETRA_EXTERN_CALL(Belos::PseudoBlockStochasticCGSolMgr, SC, LO, GO, NT)
848
849TPETRA_INSTANTIATE_SLGN_NO_ORDINAL_SCALAR(BELOS_TPETRA_PSEUDOBLOCKSTOCHASTICCGSOLMGR_EXTERN_CALL)
850#endif
851
852
853#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...
void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP, DM > > &debugStatusTest) override
Set a debug status test, OR-combined into the top-level status test.
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.
@ Unconverged
@ 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