Template Numerical Library version\ main:ab3532f7
Loading...
Searching...
No Matches
TNL::Solvers::IterativeSolverMonitor< Real, Index > Class Template Reference

Object for monitoring convergence of iterative solvers. More...

#include <TNL/Solvers/IterativeSolverMonitor.h>

Inheritance diagram for TNL::Solvers::IterativeSolverMonitor< Real, Index >:
Collaboration diagram for TNL::Solvers::IterativeSolverMonitor< Real, Index >:

Public Types

using IndexType = Index
 A type for indexing.
 
using RealType = Real
 A type of the floating-point arithmetics.
 

Public Member Functions

 IterativeSolverMonitor ()=default
 Construct with no parameters.
 
void refresh () override
 Causes that the monitor prints out the status of the solver.
 
void setIterations (const IndexType &iterations)
 Set number of the current iteration.
 
void setNodesPerIteration (const IndexType &nodes)
 Set the number of nodes of the numerical mesh or lattice.
 
void setResidue (const RealType &residue)
 Set residue of the current approximation of the solution.
 
void setStage (const std::string &stage)
 This method can be used for naming a stage of the monitored solver.
 
void setTime (const RealType &time)
 Set the time of the simulated evolution if it is time dependent.
 
void setTimeStep (const RealType &timeStep)
 Set the time step for time dependent iterative solvers.
 
void setVerbose (const IndexType &verbose)
 Set up the verbosity of the monitor.
 
- Public Member Functions inherited from TNL::Solvers::SolverMonitor
 SolverMonitor ()=default
 Basic construct with no arguments.
 
bool isStopped () const
 Checks whether the main loop was stopped.
 
void runMainLoop ()
 Starts the main loop from which the method SolverMonitor::refresh is called in given time periods.
 
void setRefreshRate (const int &refreshRate)
 Set the time interval between two consecutive calls of SolverMonitor::refresh.
 
void setTimer (Timer &timer)
 Set a timer object for the solver monitor.
 
void stopMainLoop ()
 Stops the main loop of the monitor. See runMainLoop.
 

Protected Member Functions

int getLineWidth ()
 
- Protected Member Functions inherited from TNL::Solvers::SolverMonitor
double getElapsedTime ()
 

Protected Attributes

std::atomic_bool attributes_changed { false }
 
RealType elapsed_time_before_refresh = 0
 
IndexType iterations = 0
 
IndexType iterations_before_refresh = 0
 
RealType last_mlups = 0
 
IndexType nodesPerIteration = 0
 
RealType residue = 0
 
std::atomic_bool saved { false }
 
IndexType saved_iterations = 0
 
RealType saved_residue = 0
 
std::string saved_stage
 
RealType saved_time = 0
 
RealType saved_timeStep = 0
 
std::string stage
 
RealType time = 0
 
RealType timeStep = 0
 
IndexType verbose = 2
 
- Protected Attributes inherited from TNL::Solvers::SolverMonitor
std::atomic_bool started { false }
 
std::atomic_bool stopped { false }
 
std::atomic_int timeout_milliseconds { 500 }
 
Timertimer = nullptr
 

Detailed Description

template<typename Real = double, typename Index = int>
class TNL::Solvers::IterativeSolverMonitor< Real, Index >

Object for monitoring convergence of iterative solvers.

Template Parameters
Realis a type of the floating-point arithmetics.
Indexis an indexing type.

The following example shows how to use the iterative solver monitor for monitoring convergence of linear iterative solver:

1#include <iostream>
2#include <memory>
3#include <chrono>
4#include <thread>
5#include <TNL/Matrices/SparseMatrix.h>
6#include <TNL/Devices/Sequential.h>
7#include <TNL/Devices/Cuda.h>
8#include <TNL/Solvers/Linear/Jacobi.h>
9
10template< typename Device >
11void
12iterativeLinearSolverExample()
13{
14 /***
15 * Set the following matrix (dots represent zero matrix elements):
16 *
17 * / 2.5 -1 . . . \
18 * | -1 2.5 -1 . . |
19 * | . -1 2.5 -1. . |
20 * | . . -1 2.5 -1 |
21 * \ . . . -1 2.5 /
22 */
25 const int size( 5 );
26 auto matrix_ptr = std::make_shared< MatrixType >();
27 matrix_ptr->setDimensions( size, size );
28 matrix_ptr->setRowCapacities( Vector( { 2, 3, 3, 3, 2 } ) );
29
30 auto f = [ = ] __cuda_callable__( typename MatrixType::RowView & row ) mutable
31 {
32 const int rowIdx = row.getRowIndex();
33 if( rowIdx == 0 ) {
34 row.setElement( 0, rowIdx, 2.5 ); // diagonal element
35 row.setElement( 1, rowIdx + 1, -1 ); // element above the diagonal
36 }
37 else if( rowIdx == size - 1 ) {
38 row.setElement( 0, rowIdx - 1, -1.0 ); // element below the diagonal
39 row.setElement( 1, rowIdx, 2.5 ); // diagonal element
40 }
41 else {
42 row.setElement( 0, rowIdx - 1, -1.0 ); // element below the diagonal
43 row.setElement( 1, rowIdx, 2.5 ); // diagonal element
44 row.setElement( 2, rowIdx + 1, -1.0 ); // element above the diagonal
45 }
46 };
47
48 /***
49 * Set the matrix elements.
50 */
51 matrix_ptr->forAllRows( f );
52 std::cout << *matrix_ptr << std::endl;
53
54 /***
55 * Set the right-hand side vector.
56 */
57 Vector x( size, 1.0 );
58 Vector b( size );
59 matrix_ptr->vectorProduct( x, b );
60 x = 0.0;
61 std::cout << "Vector b = " << b << std::endl;
62
63 /***
64 * Setup solver of the linear system.
65 */
67 LinearSolver solver;
68 solver.setMatrix( matrix_ptr );
69 solver.setOmega( 0.0005 );
70
71 /***
72 * Setup monitor of the iterative solver.
73 */
74 using IterativeSolverMonitorType = TNL::Solvers::IterativeSolverMonitor< double, int >;
75 IterativeSolverMonitorType monitor;
76 TNL::Solvers::SolverMonitorThread monitorThread( monitor );
77 monitor.setRefreshRate( 10 ); // refresh rate in milliseconds
78 monitor.setVerbose( 1 );
79 monitor.setStage( "Jacobi stage:" );
80 solver.setSolverMonitor( monitor );
81 solver.setConvergenceResidue( 1.0e-6 );
82 solver.solve( b, x );
83 monitor.stopMainLoop();
84 std::cout << "Vector x = " << x << std::endl;
85}
86
87int
88main( int argc, char* argv[] )
89{
90 std::cout << "Solving linear system on host: " << std::endl;
91 iterativeLinearSolverExample< TNL::Devices::Sequential >();
92
93#ifdef __CUDACC__
94 std::cout << "Solving linear system on CUDA device: " << std::endl;
95 iterativeLinearSolverExample< TNL::Devices::Cuda >();
96#endif
97}
#define __cuda_callable__
Definition Macros.h:49
Vector extends Array with algebraic operations.
Definition Vector.h:36
Implementation of sparse matrix, i.e. matrix storing only non-zero elements.
Definition SparseMatrix.h:57
Iterative solver of linear systems based on the Jacobi method.
Definition Jacobi.h:21
void setMatrix(const MatrixPointer &matrix)
Set the matrix of the linear system.
Definition LinearSolver.h:120
A RAII wrapper for launching the SolverMonitor's main loop in a separate thread.
Definition SolverMonitor.h:133
T endl(T... args)
T make_shared(T... args)

The result looks as follows:

Solving linear system on host:
Row: 0 -> 0:2.5 1:-1
Row: 1 -> 0:-1 1:2.5 2:-1
Row: 2 -> 1:-1 2:2.5 3:-1
Row: 3 -> 2:-1 3:2.5 4:-1
Row: 4 -> 3:-1 4:2.5
Vector b = [ 1.5, 0.5, 0.5, 0.5, 1.5 ]
Jacobi stage: ITER: 15447 RES: 0.06736
Jacobi stage: ITER: 34515 RES: 0.0035986
Jacobi stage: ITER: 61527 RES: 5.6817e-05
Jacobi stage: ITER: 77779 RES: 4.6809e-06
Vector x = [ 0.999999, 0.999999, 0.999998, 0.999999, 0.999999 ]
Solving linear system on CUDA device:
Row: 0 -> 0:2.5 1:-1
Row: 1 -> 0:-1 1:2.5 2:-1
Row: 2 -> 1:-1 2:2.5 3:-1
Row: 3 -> 2:-1 3:2.5 4:-1
Row: 4 -> 3:-1 4:2.5
Vector b = [ 1.5, 0.5, 0.5, 0.5, 1.5 ]
Jacobi stage: ITER: 4213 RES: 0.38592
Jacobi stage: ITER: 7531 RES: 0.2277
Jacobi stage: ITER: 8087 RES: 0.20892
Jacobi stage: ITER: 8523 RES: 0.19531
Jacobi stage: ITER: 8849 RES: 0.18568
Jacobi stage: ITER: 9175 RES: 0.17664
Jacobi stage: ITER: 9507 RES: 0.16783
Jacobi stage: ITER: 9823 RES: 0.15986
Jacobi stage: ITER: 10159 RES: 0.15181
Jacobi stage: ITER: 10511 RES: 0.14381
Jacobi stage: ITER: 10815 RES: 0.13724
Jacobi stage: ITER: 11147 RES: 0.13041
Jacobi stage: ITER: 11359 RES: 0.12623
Jacobi stage: ITER: 11603 RES: 0.12158
Jacobi stage: ITER: 11939 RES: 0.11547
Jacobi stage: ITER: 12219 RES: 0.1106
Jacobi stage: ITER: 12535 RES: 0.10536
Jacobi stage: ITER: 12863 RES: 0.10018
Jacobi stage: ITER: 13199 RES: 0.095142
Jacobi stage: ITER: 13527 RES: 0.090467
Jacobi stage: ITER: 13861 RES: 0.085916
Jacobi stage: ITER: 14159 RES: 0.082097
Jacobi stage: ITER: 14501 RES: 0.077871
Jacobi stage: ITER: 14829 RES: 0.074045
Jacobi stage: ITER: 15137 RES: 0.070623
Jacobi stage: ITER: 15459 RES: 0.067236
Jacobi stage: ITER: 15783 RES: 0.063971
Jacobi stage: ITER: 16111 RES: 0.060828
Jacobi stage: ITER: 16443 RES: 0.057804
Jacobi stage: ITER: 16783 RES: 0.054862
Jacobi stage: ITER: 17113 RES: 0.052135
Jacobi stage: ITER: 17449 RES: 0.049512
Jacobi stage: ITER: 17759 RES: 0.047224
Jacobi stage: ITER: 18079 RES: 0.044959
Jacobi stage: ITER: 18409 RES: 0.042724
Jacobi stage: ITER: 18723 RES: 0.040725
Jacobi stage: ITER: 19057 RES: 0.038676
Jacobi stage: ITER: 19369 RES: 0.036867
Jacobi stage: ITER: 19693 RES: 0.035077
Jacobi stage: ITER: 20023 RES: 0.033353
Jacobi stage: ITER: 20355 RES: 0.031695
Jacobi stage: ITER: 20685 RES: 0.030119
Jacobi stage: ITER: 21019 RES: 0.028622
Jacobi stage: ITER: 21351 RES: 0.027199
Jacobi stage: ITER: 21683 RES: 0.025847
Jacobi stage: ITER: 22003 RES: 0.024607
Jacobi stage: ITER: 22321 RES: 0.023427
Jacobi stage: ITER: 22625 RES: 0.022358
Jacobi stage: ITER: 22925 RES: 0.021351
Jacobi stage: ITER: 23247 RES: 0.020327
Jacobi stage: ITER: 23577 RES: 0.019316
Jacobi stage: ITER: 23911 RES: 0.018356
Jacobi stage: ITER: 24243 RES: 0.017443
Jacobi stage: ITER: 24575 RES: 0.016576
Jacobi stage: ITER: 24883 RES: 0.01581
Jacobi stage: ITER: 25199 RES: 0.015061
Jacobi stage: ITER: 25529 RES: 0.014312
Jacobi stage: ITER: 25863 RES: 0.013601
Jacobi stage: ITER: 26195 RES: 0.012925
Jacobi stage: ITER: 26533 RES: 0.012267
Jacobi stage: ITER: 26861 RES: 0.011664
Jacobi stage: ITER: 27187 RES: 0.011098
Jacobi stage: ITER: 27515 RES: 0.010553
Jacobi stage: ITER: 27797 RES: 0.010102
Jacobi stage: ITER: 28111 RES: 0.0096295
Jacobi stage: ITER: 28435 RES: 0.009162
Jacobi stage: ITER: 28769 RES: 0.0087011
Jacobi stage: ITER: 29103 RES: 0.0082685
Jacobi stage: ITER: 29435 RES: 0.0078574
Jacobi stage: ITER: 29767 RES: 0.0074668
Jacobi stage: ITER: 30083 RES: 0.007113
Jacobi stage: ITER: 30407 RES: 0.0067677
Jacobi stage: ITER: 30735 RES: 0.0064352
Jacobi stage: ITER: 31071 RES: 0.0061115
Jacobi stage: ITER: 31403 RES: 0.0058076
Jacobi stage: ITER: 31727 RES: 0.0055257
Jacobi stage: ITER: 32043 RES: 0.0052639
Jacobi stage: ITER: 32361 RES: 0.0050114
Jacobi stage: ITER: 32665 RES: 0.0047828
Jacobi stage: ITER: 32971 RES: 0.0045646
Jacobi stage: ITER: 33279 RES: 0.0043536
Jacobi stage: ITER: 33573 RES: 0.0041601
Jacobi stage: ITER: 33899 RES: 0.0039582
Jacobi stage: ITER: 34377 RES: 0.0036768
Jacobi stage: ITER: 34735 RES: 0.0034812
Jacobi stage: ITER: 35075 RES: 0.003304
Jacobi stage: ITER: 35415 RES: 0.0031359
Jacobi stage: ITER: 35759 RES: 0.0029745
Jacobi stage: ITER: 36083 RES: 0.0028301
Jacobi stage: ITER: 36411 RES: 0.0026911
Jacobi stage: ITER: 36715 RES: 0.0025683
Jacobi stage: ITER: 37043 RES: 0.0024421
Jacobi stage: ITER: 37383 RES: 0.0023178
Jacobi stage: ITER: 37711 RES: 0.0022039
Jacobi stage: ITER: 38039 RES: 0.0020957
Jacobi stage: ITER: 38367 RES: 0.0019927
Jacobi stage: ITER: 38697 RES: 0.0018936
Jacobi stage: ITER: 39025 RES: 0.0018006
Jacobi stage: ITER: 39355 RES: 0.0017121
Jacobi stage: ITER: 39683 RES: 0.001628
Jacobi stage: ITER: 40011 RES: 0.001548
Jacobi stage: ITER: 40347 RES: 0.0014701
Jacobi stage: ITER: 40677 RES: 0.001397
Jacobi stage: ITER: 41005 RES: 0.0013284
Jacobi stage: ITER: 41333 RES: 0.0012631
Jacobi stage: ITER: 41663 RES: 0.0012011
Jacobi stage: ITER: 41991 RES: 0.0011421
Jacobi stage: ITER: 42319 RES: 0.0010859
Jacobi stage: ITER: 42647 RES: 0.0010326
Jacobi stage: ITER: 42975 RES: 0.00098186
Jacobi stage: ITER: 43313 RES: 0.0009319
Jacobi stage: ITER: 43641 RES: 0.00088611
Jacobi stage: ITER: 43971 RES: 0.00084257
Jacobi stage: ITER: 44309 RES: 0.0007997
Jacobi stage: ITER: 44637 RES: 0.00076041
Jacobi stage: ITER: 44967 RES: 0.00072305
Jacobi stage: ITER: 45305 RES: 0.00068625
Jacobi stage: ITER: 45633 RES: 0.00065254
Jacobi stage: ITER: 45971 RES: 0.00061971
Jacobi stage: ITER: 46301 RES: 0.0005889
Jacobi stage: ITER: 46629 RES: 0.00055997
Jacobi stage: ITER: 46959 RES: 0.00053245
Jacobi stage: ITER: 47287 RES: 0.00050629
Jacobi stage: ITER: 47615 RES: 0.00048142
Jacobi stage: ITER: 47943 RES: 0.00045776
Jacobi stage: ITER: 48279 RES: 0.00043474
Jacobi stage: ITER: 48607 RES: 0.00041338
Jacobi stage: ITER: 48947 RES: 0.00039234
Jacobi stage: ITER: 49277 RES: 0.00037284
Jacobi stage: ITER: 49605 RES: 0.00035452
Jacobi stage: ITER: 49935 RES: 0.0003371
Jacobi stage: ITER: 50263 RES: 0.00032054
Jacobi stage: ITER: 50591 RES: 0.00030479
Jacobi stage: ITER: 50919 RES: 0.00028981
Jacobi stage: ITER: 51249 RES: 0.0002754
Jacobi stage: ITER: 51579 RES: 0.00026187
Jacobi stage: ITER: 51907 RES: 0.00024901
Jacobi stage: ITER: 52235 RES: 0.00023677
Jacobi stage: ITER: 52563 RES: 0.00022514
Jacobi stage: ITER: 52893 RES: 0.00021394
Jacobi stage: ITER: 53221 RES: 0.00020343
Jacobi stage: ITER: 53551 RES: 0.00019344
Jacobi stage: ITER: 53879 RES: 0.00018393
Jacobi stage: ITER: 54207 RES: 0.0001749
Jacobi stage: ITER: 54535 RES: 0.0001663
Jacobi stage: ITER: 54865 RES: 0.00015803
Jacobi stage: ITER: 55193 RES: 0.00015027
Jacobi stage: ITER: 55523 RES: 0.00014289
Jacobi stage: ITER: 55851 RES: 0.00013587
Jacobi stage: ITER: 56179 RES: 0.00012919
Jacobi stage: ITER: 56507 RES: 0.00012284
Jacobi stage: ITER: 56835 RES: 0.00011681
Jacobi stage: ITER: 57165 RES: 0.000111
Jacobi stage: ITER: 57493 RES: 0.00010555
Jacobi stage: ITER: 57823 RES: 0.00010036
Jacobi stage: ITER: 58151 RES: 9.543e-05
Jacobi stage: ITER: 58479 RES: 9.0741e-05
Jacobi stage: ITER: 58807 RES: 8.6282e-05
Jacobi stage: ITER: 59137 RES: 8.1993e-05
Jacobi stage: ITER: 59465 RES: 7.7964e-05
Jacobi stage: ITER: 59795 RES: 7.4134e-05
Jacobi stage: ITER: 60123 RES: 7.0491e-05
Jacobi stage: ITER: 60451 RES: 6.7028e-05
Jacobi stage: ITER: 60779 RES: 6.3734e-05
Jacobi stage: ITER: 61109 RES: 6.0566e-05
Jacobi stage: ITER: 61439 RES: 5.759e-05
Jacobi stage: ITER: 61767 RES: 5.476e-05
Jacobi stage: ITER: 62095 RES: 5.207e-05
Jacobi stage: ITER: 62425 RES: 4.9481e-05
Jacobi stage: ITER: 62753 RES: 4.705e-05
Jacobi stage: ITER: 63083 RES: 4.4738e-05
Jacobi stage: ITER: 63411 RES: 4.254e-05
Jacobi stage: ITER: 63739 RES: 4.045e-05
Jacobi stage: ITER: 64067 RES: 3.8462e-05
Jacobi stage: ITER: 64397 RES: 3.655e-05
Jacobi stage: ITER: 64725 RES: 3.4754e-05
Jacobi stage: ITER: 65055 RES: 3.3047e-05
Jacobi stage: ITER: 65383 RES: 3.1423e-05
Jacobi stage: ITER: 65711 RES: 2.9879e-05
Jacobi stage: ITER: 66039 RES: 2.8411e-05
Jacobi stage: ITER: 66369 RES: 2.6999e-05
Jacobi stage: ITER: 66697 RES: 2.5672e-05
Jacobi stage: ITER: 67027 RES: 2.4411e-05
Jacobi stage: ITER: 67355 RES: 2.3211e-05
Jacobi stage: ITER: 67683 RES: 2.2071e-05
Jacobi stage: ITER: 68011 RES: 2.0986e-05
Jacobi stage: ITER: 68339 RES: 1.9955e-05
Jacobi stage: ITER: 68669 RES: 1.8963e-05
Jacobi stage: ITER: 68997 RES: 1.8031e-05
Jacobi stage: ITER: 69327 RES: 1.7146e-05
Jacobi stage: ITER: 69655 RES: 1.6303e-05
Jacobi stage: ITER: 69983 RES: 1.5502e-05
Jacobi stage: ITER: 70311 RES: 1.474e-05
Jacobi stage: ITER: 70641 RES: 1.4008e-05
Jacobi stage: ITER: 70969 RES: 1.3319e-05
Jacobi stage: ITER: 71299 RES: 1.2665e-05
Jacobi stage: ITER: 71627 RES: 1.2043e-05
Jacobi stage: ITER: 71955 RES: 1.1451e-05
Jacobi stage: ITER: 72283 RES: 1.0888e-05
Jacobi stage: ITER: 72613 RES: 1.0347e-05
Jacobi stage: ITER: 72943 RES: 9.8386e-06
Jacobi stage: ITER: 73271 RES: 9.3552e-06
Jacobi stage: ITER: 73599 RES: 8.8955e-06
Jacobi stage: ITER: 73927 RES: 8.4585e-06
Jacobi stage: ITER: 74255 RES: 8.0429e-06
Jacobi stage: ITER: 74585 RES: 7.643e-06
Jacobi stage: ITER: 74913 RES: 7.2675e-06
Jacobi stage: ITER: 75243 RES: 6.9104e-06
Jacobi stage: ITER: 75571 RES: 6.5709e-06
Jacobi stage: ITER: 75899 RES: 6.248e-06
Jacobi stage: ITER: 76227 RES: 5.941e-06
Jacobi stage: ITER: 76557 RES: 5.6457e-06
Jacobi stage: ITER: 76885 RES: 5.3683e-06
Jacobi stage: ITER: 77215 RES: 5.1045e-06
Jacobi stage: ITER: 77543 RES: 4.8537e-06
Jacobi stage: ITER: 77871 RES: 4.6152e-06
Jacobi stage: ITER: 78199 RES: 4.3885e-06
Jacobi stage: ITER: 78527 RES: 4.1729e-06
Jacobi stage: ITER: 78857 RES: 3.9654e-06
Jacobi stage: ITER: 79185 RES: 3.7706e-06
Jacobi stage: ITER: 79515 RES: 3.5853e-06
Jacobi stage: ITER: 79843 RES: 3.4091e-06
Jacobi stage: ITER: 80171 RES: 3.2416e-06
Jacobi stage: ITER: 80499 RES: 3.0824e-06
Jacobi stage: ITER: 80829 RES: 2.9291e-06
Jacobi stage: ITER: 81157 RES: 2.7852e-06
Jacobi stage: ITER: 81487 RES: 2.6484e-06
Jacobi stage: ITER: 81815 RES: 2.5182e-06
Jacobi stage: ITER: 82143 RES: 2.3945e-06
Jacobi stage: ITER: 82471 RES: 2.2769e-06
Jacobi stage: ITER: 82799 RES: 2.165e-06
Jacobi stage: ITER: 83129 RES: 2.0574e-06
Jacobi stage: ITER: 83459 RES: 1.9563e-06
Jacobi stage: ITER: 83787 RES: 1.8602e-06
Jacobi stage: ITER: 84115 RES: 1.7688e-06
Jacobi stage: ITER: 84443 RES: 1.6819e-06
Jacobi stage: ITER: 84771 RES: 1.5992e-06
Jacobi stage: ITER: 85101 RES: 1.5197e-06
Jacobi stage: ITER: 85429 RES: 1.445e-06
Jacobi stage: ITER: 85759 RES: 1.374e-06
Jacobi stage: ITER: 86087 RES: 1.3065e-06
Jacobi stage: ITER: 86415 RES: 1.2423e-06
Jacobi stage: ITER: 86743 RES: 1.1813e-06
Jacobi stage: ITER: 87073 RES: 1.1226e-06
Jacobi stage: ITER: 87401 RES: 1.0674e-06
Jacobi stage: ITER: 87731 RES: 1.015e-06
Vector x = [ 0.999999, 0.999999, 0.999998, 0.999999, 0.999999 ]

The following example shows how to employ timer (TNL::Timer) to the monitor of iterative solvers:

1#include <iostream>
2#include <memory>
3#include <chrono>
4#include <thread>
5#include <TNL/Timer.h>
6#include <TNL/Matrices/SparseMatrix.h>
7#include <TNL/Devices/Sequential.h>
8#include <TNL/Devices/Cuda.h>
9#include <TNL/Solvers/Linear/Jacobi.h>
10
11template< typename Device >
12void
13iterativeLinearSolverExample()
14{
15 /***
16 * Set the following matrix (dots represent zero matrix elements):
17 *
18 * / 2.5 -1 . . . \
19 * | -1 2.5 -1 . . |
20 * | . -1 2.5 -1. . |
21 * | . . -1 2.5 -1 |
22 * \ . . . -1 2.5 /
23 */
26 const int size( 5 );
27 auto matrix_ptr = std::make_shared< MatrixType >();
28 matrix_ptr->setDimensions( size, size );
29 matrix_ptr->setRowCapacities( Vector( { 2, 3, 3, 3, 2 } ) );
30
31 auto f = [ = ] __cuda_callable__( typename MatrixType::RowView & row ) mutable
32 {
33 const int rowIdx = row.getRowIndex();
34 if( rowIdx == 0 ) {
35 row.setElement( 0, rowIdx, 2.5 ); // diagonal element
36 row.setElement( 1, rowIdx + 1, -1 ); // element above the diagonal
37 }
38 else if( rowIdx == size - 1 ) {
39 row.setElement( 0, rowIdx - 1, -1.0 ); // element below the diagonal
40 row.setElement( 1, rowIdx, 2.5 ); // diagonal element
41 }
42 else {
43 row.setElement( 0, rowIdx - 1, -1.0 ); // element below the diagonal
44 row.setElement( 1, rowIdx, 2.5 ); // diagonal element
45 row.setElement( 2, rowIdx + 1, -1.0 ); // element above the diagonal
46 }
47 };
48
49 /***
50 * Set the matrix elements.
51 */
52 matrix_ptr->forAllRows( f );
53 std::cout << *matrix_ptr << std::endl;
54
55 /***
56 * Set the right-hand side vector.
57 */
58 Vector x( size, 1.0 );
59 Vector b( size );
60 matrix_ptr->vectorProduct( x, b );
61 x = 0.0;
62 std::cout << "Vector b = " << b << std::endl;
63
64 /***
65 * Setup solver of the linear system.
66 */
68 LinearSolver solver;
69 solver.setMatrix( matrix_ptr );
70 solver.setOmega( 0.0005 );
71
72 /***
73 * Setup monitor of the iterative solver.
74 */
75 using IterativeSolverMonitorType = TNL::Solvers::IterativeSolverMonitor< double, int >;
76 IterativeSolverMonitorType monitor;
77 TNL::Solvers::SolverMonitorThread mmonitorThread( monitor );
78 monitor.setRefreshRate( 10 ); // refresh rate in milliseconds
79 monitor.setVerbose( 1 );
80 monitor.setStage( "Jacobi stage:" );
81 TNL::Timer timer;
82 monitor.setTimer( timer );
83 timer.start();
84 solver.setSolverMonitor( monitor );
85 solver.setConvergenceResidue( 1.0e-6 );
86 solver.solve( b, x );
87 monitor.stopMainLoop();
88 std::cout << "Vector x = " << x << std::endl;
89}
90
91int
92main( int argc, char* argv[] )
93{
94 std::cout << "Solving linear system on host: " << std::endl;
95 iterativeLinearSolverExample< TNL::Devices::Sequential >();
96
97#ifdef __CUDACC__
98 std::cout << "Solving linear system on CUDA device: " << std::endl;
99 iterativeLinearSolverExample< TNL::Devices::Cuda >();
100#endif
101}
Class for real time, CPU time and CPU cycles measuring.
Definition Timer.h:25
void start()
Starts timer.
Definition Timer.hpp:42

The result looks as follows:

Solving linear system on host:
Row: 0 -> 0:2.5 1:-1
Row: 1 -> 0:-1 1:2.5 2:-1
Row: 2 -> 1:-1 2:2.5 3:-1
Row: 3 -> 2:-1 3:2.5 4:-1
Row: 4 -> 3:-1 4:2.5
Vector b = [ 1.5, 0.5, 0.5, 0.5, 1.5 ]
ELA:8.43e-06
ELA: 0.10012 Jacobi stage: ITER: 22383 RES: 0.023212
ELA: 0.20025 Jacobi stage: ITER: 49097 RES: 0.00038329
ELA: 0.30037 Jacobi stage: ITER: 75421 RES: 6.722e-06
Vector x = [ 0.999999, 0.999999, 0.999998, 0.999999, 0.999999 ]
Solving linear system on CUDA device:
Row: 0 -> 0:2.5 1:-1
Row: 1 -> 0:-1 1:2.5 2:-1
Row: 2 -> 1:-1 2:2.5 3:-1
Row: 3 -> 2:-1 3:2.5 4:-1
Row: 4 -> 3:-1 4:2.5
Vector b = [ 1.5, 0.5, 0.5, 0.5, 1.5 ]
ELA:0.000878
ELA: 0.10098 Jacobi stage: ITER: 227 RES: 0.9273
ELA: 0.20111 Jacobi stage: ITER: 707 RES: 0.8007
ELA: 0.30123 Jacobi stage: ITER: 1101 RES: 0.71883
ELA: 0.40415 Jacobi stage: ITER: 1419 RES: 0.66427
ELA: 0.50426 Jacobi stage: ITER: 1747 RES: 0.61548
ELA: 0.60748 Jacobi stage: ITER: 2089 RES: 0.57108
ELA: 0.7076 Jacobi stage: ITER: 2431 RES: 0.53262
ELA: 0.80771 Jacobi stage: ITER: 2763 RES: 0.49924
ELA: 0.90783 Jacobi stage: ITER: 3107 RES: 0.46819
ELA: 1.0079 Jacobi stage: ITER: 3405 RES: 0.44353
ELA: 1.1208 Jacobi stage: ITER: 3789 RES: 0.41473
ELA: 1.221 Jacobi stage: ITER: 4245 RES: 0.38386
ELA: 1.3211 Jacobi stage: ITER: 4595 RES: 0.36234
ELA: 1.4212 Jacobi stage: ITER: 4907 RES: 0.34434
ELA: 1.5213 Jacobi stage: ITER: 5235 RES: 0.32659
ELA: 1.6214 Jacobi stage: ITER: 5561 RES: 0.30991
ELA: 1.7215 Jacobi stage: ITER: 5887 RES: 0.29439
ELA: 1.8242 Jacobi stage: ITER: 6227 RES: 0.27903
ELA: 1.9243 Jacobi stage: ITER: 6557 RES: 0.26488
ELA: 2.0244 Jacobi stage: ITER: 6879 RES: 0.25198
ELA: 2.1245 Jacobi stage: ITER: 7151 RES: 0.24153
ELA: 2.2246 Jacobi stage: ITER: 7457 RES: 0.23025
ELA: 2.3247 Jacobi stage: ITER: 7751 RES: 0.22007
ELA: 2.4248 Jacobi stage: ITER: 8059 RES: 0.20983
ELA: 2.5261 Jacobi stage: ITER: 8371 RES: 0.19983
ELA: 2.6263 Jacobi stage: ITER: 8695 RES: 0.1902
ELA: 2.7264 Jacobi stage: ITER: 9021 RES: 0.18082
ELA: 2.8265 Jacobi stage: ITER: 9351 RES: 0.17191
ELA: 2.9268 Jacobi stage: ITER: 9683 RES: 0.16334
ELA: 3.027 Jacobi stage: ITER: 10015 RES: 0.15521
ELA: 3.1275 Jacobi stage: ITER: 10351 RES: 0.14739
ELA: 3.2308 Jacobi stage: ITER: 10669 RES: 0.14031
ELA: 3.331 Jacobi stage: ITER: 10985 RES: 0.13366
ELA: 3.4311 Jacobi stage: ITER: 11315 RES: 0.12709
ELA: 3.5321 Jacobi stage: ITER: 11631 RES: 0.12106
ELA: 3.6323 Jacobi stage: ITER: 11963 RES: 0.11504
ELA: 3.7324 Jacobi stage: ITER: 12273 RES: 0.10965
ELA: 3.8327 Jacobi stage: ITER: 12597 RES: 0.10433
ELA: 3.9332 Jacobi stage: ITER: 12929 RES: 0.099142
ELA: 4.0334 Jacobi stage: ITER: 13255 RES: 0.094327
ELA: 4.1335 Jacobi stage: ITER: 13587 RES: 0.089637
ELA: 4.2336 Jacobi stage: ITER: 13919 RES: 0.08518
ELA: 4.3338 Jacobi stage: ITER: 14249 RES: 0.080945
ELA: 4.4339 Jacobi stage: ITER: 14581 RES: 0.07692
ELA: 4.534 Jacobi stage: ITER: 14901 RES: 0.07323
ELA: 4.6341 Jacobi stage: ITER: 15219 RES: 0.069761
ELA: 4.7342 Jacobi stage: ITER: 15495 RES: 0.066865
ELA: 4.8363 Jacobi stage: ITER: 15821 RES: 0.063579
ELA: 4.9365 Jacobi stage: ITER: 16143 RES: 0.06053
ELA: 5.0366 Jacobi stage: ITER: 16471 RES: 0.057556
ELA: 5.1367 Jacobi stage: ITER: 16799 RES: 0.054728
ELA: 5.2369 Jacobi stage: ITER: 17131 RES: 0.052007
ELA: 5.337 Jacobi stage: ITER: 17465 RES: 0.049391
ELA: 5.4371 Jacobi stage: ITER: 17767 RES: 0.047166
ELA: 5.5375 Jacobi stage: ITER: 18087 RES: 0.044904
ELA: 5.6408 Jacobi stage: ITER: 18425 RES: 0.042619
ELA: 5.741 Jacobi stage: ITER: 18755 RES: 0.040525
ELA: 5.8436 Jacobi stage: ITER: 19093 RES: 0.038463
ELA: 5.9442 Jacobi stage: ITER: 19425 RES: 0.036551
ELA: 6.0443 Jacobi stage: ITER: 19757 RES: 0.034734
ELA: 6.1444 Jacobi stage: ITER: 20075 RES: 0.033088
ELA: 6.2446 Jacobi stage: ITER: 20407 RES: 0.031443
ELA: 6.346 Jacobi stage: ITER: 20685 RES: 0.030119
ELA: 6.4461 Jacobi stage: ITER: 21001 RES: 0.028692
ELA: 6.5464 Jacobi stage: ITER: 21323 RES: 0.027316
ELA: 6.6465 Jacobi stage: ITER: 21655 RES: 0.025958
ELA: 6.7475 Jacobi stage: ITER: 21993 RES: 0.024637
ELA: 6.848 Jacobi stage: ITER: 22327 RES: 0.023412
ELA: 6.9498 Jacobi stage: ITER: 22661 RES: 0.022235
ELA: 7.0508 Jacobi stage: ITER: 22979 RES: 0.021181
ELA: 7.1509 Jacobi stage: ITER: 23303 RES: 0.020153
ELA: 7.2511 Jacobi stage: ITER: 23633 RES: 0.019151
ELA: 7.3521 Jacobi stage: ITER: 23963 RES: 0.01821
ELA: 7.4522 Jacobi stage: ITER: 24295 RES: 0.017305
ELA: 7.5523 Jacobi stage: ITER: 24619 RES: 0.016464
ELA: 7.6525 Jacobi stage: ITER: 24925 RES: 0.015704
ELA: 7.7526 Jacobi stage: ITER: 25245 RES: 0.01495
ELA: 7.8527 Jacobi stage: ITER: 25547 RES: 0.014277
ELA: 7.9542 Jacobi stage: ITER: 25855 RES: 0.013617
ELA: 8.0543 Jacobi stage: ITER: 26159 RES: 0.012996
ELA: 8.1544 Jacobi stage: ITER: 26493 RES: 0.012342
ELA: 8.2575 Jacobi stage: ITER: 26825 RES: 0.011729
ELA: 8.3642 Jacobi stage: ITER: 27183 RES: 0.011105
ELA: 8.4643 Jacobi stage: ITER: 27715 RES: 0.010233
ELA: 8.5675 Jacobi stage: ITER: 28055 RES: 0.0097126
ELA: 8.6676 Jacobi stage: ITER: 28377 RES: 0.0092411
ELA: 8.7708 Jacobi stage: ITER: 28707 RES: 0.0087871
ELA: 8.8709 Jacobi stage: ITER: 29027 RES: 0.0083656
ELA: 8.9711 Jacobi stage: ITER: 29331 RES: 0.0079839
ELA: 9.0734 Jacobi stage: ITER: 29661 RES: 0.007587
ELA: 9.1735 Jacobi stage: ITER: 29991 RES: 0.0072142
ELA: 9.2737 Jacobi stage: ITER: 30319 RES: 0.0068598
ELA: 9.3738 Jacobi stage: ITER: 30647 RES: 0.0065227
ELA: 9.4739 Jacobi stage: ITER: 30975 RES: 0.0062022
ELA: 9.5775 Jacobi stage: ITER: 31315 RES: 0.0058866
ELA: 9.6776 Jacobi stage: ITER: 31645 RES: 0.005594
ELA: 9.7777 Jacobi stage: ITER: 31973 RES: 0.0053191
ELA: 9.8808 Jacobi stage: ITER: 32311 RES: 0.0050516
ELA: 9.9809 Jacobi stage: ITER: 32641 RES: 0.0048004
ELA: 10.081 Jacobi stage: ITER: 32969 RES: 0.0045646
ELA: 10.181 Jacobi stage: ITER: 33299 RES: 0.0043403
ELA: 10.284 Jacobi stage: ITER: 33637 RES: 0.0041194
ELA: 10.384 Jacobi stage: ITER: 33965 RES: 0.003917
ELA: 10.484 Jacobi stage: ITER: 34295 RES: 0.0037246
ELA: 10.587 Jacobi stage: ITER: 34631 RES: 0.0035372
ELA: 10.688 Jacobi stage: ITER: 34961 RES: 0.0033614
ELA: 10.788 Jacobi stage: ITER: 35289 RES: 0.0031962
ELA: 10.888 Jacobi stage: ITER: 35619 RES: 0.0030392
ELA: 10.989 Jacobi stage: ITER: 35951 RES: 0.0028881
ELA: 11.089 Jacobi stage: ITER: 36279 RES: 0.0027462
ELA: 11.19 Jacobi stage: ITER: 36609 RES: 0.0026096
ELA: 11.29 Jacobi stage: ITER: 36937 RES: 0.0024814
ELA: 11.39 Jacobi stage: ITER: 37267 RES: 0.0023595
ELA: 11.49 Jacobi stage: ITER: 37595 RES: 0.0022436
ELA: 11.591 Jacobi stage: ITER: 37927 RES: 0.002132
ELA: 11.691 Jacobi stage: ITER: 38255 RES: 0.0020273
ELA: 11.791 Jacobi stage: ITER: 38583 RES: 0.0019277
ELA: 11.894 Jacobi stage: ITER: 38921 RES: 0.0018296
ELA: 11.994 Jacobi stage: ITER: 39251 RES: 0.0017397
ELA: 12.094 Jacobi stage: ITER: 39579 RES: 0.0016542
ELA: 12.194 Jacobi stage: ITER: 39907 RES: 0.0015729
ELA: 12.297 Jacobi stage: ITER: 40245 RES: 0.0014929
ELA: 12.398 Jacobi stage: ITER: 40575 RES: 0.0014195
ELA: 12.498 Jacobi stage: ITER: 40903 RES: 0.0013498
ELA: 12.598 Jacobi stage: ITER: 41231 RES: 0.0012835
ELA: 12.701 Jacobi stage: ITER: 41569 RES: 0.0012182
ELA: 12.801 Jacobi stage: ITER: 41899 RES: 0.0011583
ELA: 12.901 Jacobi stage: ITER: 42227 RES: 0.0011014
ELA: 13.001 Jacobi stage: ITER: 42555 RES: 0.0010473
ELA: 13.101 Jacobi stage: ITER: 42883 RES: 0.00099583
ELA: 13.201 Jacobi stage: ITER: 43213 RES: 0.00094632
ELA: 13.302 Jacobi stage: ITER: 43541 RES: 0.00089983
ELA: 13.402 Jacobi stage: ITER: 43871 RES: 0.00085561
ELA: 13.502 Jacobi stage: ITER: 44199 RES: 0.00081358
ELA: 13.602 Jacobi stage: ITER: 44527 RES: 0.0007736
ELA: 13.702 Jacobi stage: ITER: 44857 RES: 0.00073514
ELA: 13.802 Jacobi stage: ITER: 45185 RES: 0.00069902
ELA: 13.902 Jacobi stage: ITER: 45513 RES: 0.00066468
ELA: 14.002 Jacobi stage: ITER: 45843 RES: 0.00063202
ELA: 14.102 Jacobi stage: ITER: 46171 RES: 0.00060096
ELA: 14.203 Jacobi stage: ITER: 46499 RES: 0.00057144
ELA: 14.303 Jacobi stage: ITER: 46829 RES: 0.00054303
ELA: 14.403 Jacobi stage: ITER: 47157 RES: 0.00051635
ELA: 14.503 Jacobi stage: ITER: 47487 RES: 0.00049098
ELA: 14.603 Jacobi stage: ITER: 47815 RES: 0.00046685
ELA: 14.703 Jacobi stage: ITER: 48143 RES: 0.00044392
ELA: 14.803 Jacobi stage: ITER: 48471 RES: 0.0004221
ELA: 14.904 Jacobi stage: ITER: 48801 RES: 0.00040112
ELA: 15.004 Jacobi stage: ITER: 49129 RES: 0.00038141
ELA: 15.104 Jacobi stage: ITER: 49459 RES: 0.00036267
ELA: 15.204 Jacobi stage: ITER: 49787 RES: 0.00034485
ELA: 15.304 Jacobi stage: ITER: 50115 RES: 0.00032791
ELA: 15.404 Jacobi stage: ITER: 50443 RES: 0.0003118
ELA: 15.504 Jacobi stage: ITER: 50773 RES: 0.00029629
ELA: 15.605 Jacobi stage: ITER: 51101 RES: 0.00028174
ELA: 15.705 Jacobi stage: ITER: 51431 RES: 0.00026789
ELA: 15.805 Jacobi stage: ITER: 51759 RES: 0.00025473
ELA: 15.905 Jacobi stage: ITER: 52087 RES: 0.00024222
ELA: 16.005 Jacobi stage: ITER: 52417 RES: 0.00023017
ELA: 16.105 Jacobi stage: ITER: 52745 RES: 0.00021886
ELA: 16.205 Jacobi stage: ITER: 53075 RES: 0.00020811
ELA: 16.305 Jacobi stage: ITER: 53403 RES: 0.00019789
ELA: 16.406 Jacobi stage: ITER: 53731 RES: 0.00018816
ELA: 16.506 Jacobi stage: ITER: 54059 RES: 0.00017892
ELA: 16.606 Jacobi stage: ITER: 54389 RES: 0.00017002
ELA: 16.706 Jacobi stage: ITER: 54719 RES: 0.00016167
ELA: 16.806 Jacobi stage: ITER: 55047 RES: 0.00015373
ELA: 16.906 Jacobi stage: ITER: 55375 RES: 0.00014617
ELA: 17.006 Jacobi stage: ITER: 55703 RES: 0.00013899
ELA: 17.106 Jacobi stage: ITER: 56033 RES: 0.00013208
ELA: 17.207 Jacobi stage: ITER: 56361 RES: 0.00012559
ELA: 17.307 Jacobi stage: ITER: 56691 RES: 0.00011942
ELA: 17.407 Jacobi stage: ITER: 57019 RES: 0.00011355
ELA: 17.507 Jacobi stage: ITER: 57347 RES: 0.00010797
ELA: 17.607 Jacobi stage: ITER: 57675 RES: 0.00010267
ELA: 17.707 Jacobi stage: ITER: 58005 RES: 9.7564e-05
ELA: 17.807 Jacobi stage: ITER: 58333 RES: 9.277e-05
ELA: 17.907 Jacobi stage: ITER: 58663 RES: 8.8212e-05
ELA: 18.008 Jacobi stage: ITER: 58991 RES: 8.3878e-05
ELA: 18.108 Jacobi stage: ITER: 59319 RES: 7.9757e-05
ELA: 18.208 Jacobi stage: ITER: 59647 RES: 7.5838e-05
ELA: 18.308 Jacobi stage: ITER: 59977 RES: 7.2068e-05
ELA: 18.408 Jacobi stage: ITER: 60305 RES: 6.8527e-05
ELA: 18.508 Jacobi stage: ITER: 60635 RES: 6.516e-05
ELA: 18.608 Jacobi stage: ITER: 60963 RES: 6.1958e-05
ELA: 18.709 Jacobi stage: ITER: 61291 RES: 5.8914e-05
ELA: 18.809 Jacobi stage: ITER: 61619 RES: 5.6019e-05
ELA: 18.909 Jacobi stage: ITER: 61949 RES: 5.3234e-05
ELA: 19.009 Jacobi stage: ITER: 62277 RES: 5.0619e-05
ELA: 19.109 Jacobi stage: ITER: 62607 RES: 4.8132e-05
ELA: 19.209 Jacobi stage: ITER: 62935 RES: 4.5767e-05
ELA: 19.309 Jacobi stage: ITER: 63263 RES: 4.3518e-05
ELA: 19.41 Jacobi stage: ITER: 63593 RES: 4.1355e-05
ELA: 19.51 Jacobi stage: ITER: 63921 RES: 3.9323e-05
ELA: 19.61 Jacobi stage: ITER: 64251 RES: 3.7391e-05
ELA: 19.71 Jacobi stage: ITER: 64579 RES: 3.5553e-05
ELA: 19.81 Jacobi stage: ITER: 64907 RES: 3.3807e-05
ELA: 19.91 Jacobi stage: ITER: 65235 RES: 3.2146e-05
ELA: 20.01 Jacobi stage: ITER: 65565 RES: 3.0547e-05
ELA: 20.11 Jacobi stage: ITER: 65895 RES: 2.9046e-05
ELA: 20.211 Jacobi stage: ITER: 66223 RES: 2.7619e-05
ELA: 20.311 Jacobi stage: ITER: 66551 RES: 2.6262e-05
ELA: 20.411 Jacobi stage: ITER: 66879 RES: 2.4972e-05
ELA: 20.511 Jacobi stage: ITER: 67209 RES: 2.373e-05
ELA: 20.611 Jacobi stage: ITER: 67537 RES: 2.2564e-05
ELA: 20.711 Jacobi stage: ITER: 67867 RES: 2.1456e-05
ELA: 20.811 Jacobi stage: ITER: 68195 RES: 2.0402e-05
ELA: 20.911 Jacobi stage: ITER: 68523 RES: 1.9399e-05
ELA: 21.012 Jacobi stage: ITER: 68851 RES: 1.8446e-05
ELA: 21.112 Jacobi stage: ITER: 69181 RES: 1.7529e-05
ELA: 21.212 Jacobi stage: ITER: 69509 RES: 1.6668e-05
ELA: 21.312 Jacobi stage: ITER: 69839 RES: 1.5849e-05
ELA: 21.412 Jacobi stage: ITER: 70167 RES: 1.507e-05
ELA: 21.512 Jacobi stage: ITER: 70495 RES: 1.433e-05
ELA: 21.612 Jacobi stage: ITER: 70823 RES: 1.3626e-05
ELA: 21.713 Jacobi stage: ITER: 71153 RES: 1.2948e-05
ELA: 21.813 Jacobi stage: ITER: 71481 RES: 1.2312e-05
ELA: 21.913 Jacobi stage: ITER: 71811 RES: 1.1707e-05
ELA: 22.013 Jacobi stage: ITER: 72139 RES: 1.1132e-05
ELA: 22.113 Jacobi stage: ITER: 72467 RES: 1.0585e-05
ELA: 22.213 Jacobi stage: ITER: 72795 RES: 1.0065e-05
ELA: 22.313 Jacobi stage: ITER: 73123 RES: 9.5703e-06
ELA: 22.413 Jacobi stage: ITER: 73453 RES: 9.0945e-06
ELA: 22.513 Jacobi stage: ITER: 73781 RES: 8.6477e-06
ELA: 22.613 Jacobi stage: ITER: 74111 RES: 8.2228e-06
ELA: 22.714 Jacobi stage: ITER: 74439 RES: 7.8188e-06
ELA: 22.814 Jacobi stage: ITER: 74767 RES: 7.4346e-06
ELA: 22.914 Jacobi stage: ITER: 75095 RES: 7.0693e-06
ELA: 23.014 Jacobi stage: ITER: 75423 RES: 6.722e-06
ELA: 23.114 Jacobi stage: ITER: 75753 RES: 6.3878e-06
ELA: 23.214 Jacobi stage: ITER: 76083 RES: 6.0739e-06
ELA: 23.314 Jacobi stage: ITER: 76411 RES: 5.7755e-06
ELA: 23.414 Jacobi stage: ITER: 76739 RES: 5.4917e-06
ELA: 23.514 Jacobi stage: ITER: 77067 RES: 5.2219e-06
ELA: 23.614 Jacobi stage: ITER: 77395 RES: 4.9653e-06
ELA: 23.715 Jacobi stage: ITER: 77725 RES: 4.7185e-06
ELA: 23.815 Jacobi stage: ITER: 78053 RES: 4.4866e-06
ELA: 23.915 Jacobi stage: ITER: 78381 RES: 4.2662e-06
ELA: 24.015 Jacobi stage: ITER: 78711 RES: 4.0566e-06
ELA: 24.115 Jacobi stage: ITER: 79039 RES: 3.8573e-06
ELA: 24.215 Jacobi stage: ITER: 79367 RES: 3.6677e-06
ELA: 24.315 Jacobi stage: ITER: 79695 RES: 3.4875e-06
ELA: 24.415 Jacobi stage: ITER: 80025 RES: 3.3141e-06
ELA: 24.515 Jacobi stage: ITER: 80353 RES: 3.1513e-06
ELA: 24.615 Jacobi stage: ITER: 80693 RES: 2.991e-06
ELA: 24.716 Jacobi stage: ITER: 81189 RES: 2.7716e-06
ELA: 24.816 Jacobi stage: ITER: 81685 RES: 2.5682e-06
ELA: 24.916 Jacobi stage: ITER: 82179 RES: 2.3813e-06
ELA: 25.016 Jacobi stage: ITER: 82671 RES: 2.208e-06
ELA: 25.116 Jacobi stage: ITER: 83167 RES: 2.046e-06
ELA: 25.216 Jacobi stage: ITER: 83659 RES: 1.8971e-06
ELA: 25.316 Jacobi stage: ITER: 84155 RES: 1.7579e-06
ELA: 25.416 Jacobi stage: ITER: 84649 RES: 1.629e-06
ELA: 25.516 Jacobi stage: ITER: 85255 RES: 1.4846e-06
ELA: 25.617 Jacobi stage: ITER: 85749 RES: 1.3757e-06
ELA: 25.717 Jacobi stage: ITER: 86243 RES: 1.2756e-06
ELA: 25.817 Jacobi stage: ITER: 86753 RES: 1.1791e-06
ELA: 25.917 Jacobi stage: ITER: 87247 RES: 1.0933e-06
ELA: 26.017 Jacobi stage: ITER: 87741 RES: 1.0131e-06
Vector x = [ 0.999999, 0.999999, 0.999998, 0.999999, 0.999999 ]

Member Function Documentation

◆ refresh()

template<typename Real, typename Index>
void TNL::Solvers::IterativeSolverMonitor< Real, Index >::refresh ( )
overridevirtual

Causes that the monitor prints out the status of the solver.

Implements TNL::Solvers::SolverMonitor.

◆ setIterations()

template<typename Real, typename Index>
void TNL::Solvers::IterativeSolverMonitor< Real, Index >::setIterations ( const IndexType & iterations)

Set number of the current iteration.

Parameters
iterationsis number of the current iteration.

◆ setNodesPerIteration()

template<typename Real, typename Index>
void TNL::Solvers::IterativeSolverMonitor< Real, Index >::setNodesPerIteration ( const IndexType & nodes)

Set the number of nodes of the numerical mesh or lattice.

This can be used to compute the number of nodes processed per one second.

Parameters
nodesis number of nodes of the numerical mesh or lattice.

◆ setResidue()

template<typename Real = double, typename Index = int>
void TNL::Solvers::IterativeSolverMonitor< Real, Index >::setResidue ( const RealType & residue)

Set residue of the current approximation of the solution.

Parameters
residueis a residue of the current approximation of the solution.

◆ setStage()

template<typename Real, typename Index>
void TNL::Solvers::IterativeSolverMonitor< Real, Index >::setStage ( const std::string & stage)

This method can be used for naming a stage of the monitored solver.

The stage name can be used to differ between various stages of iterative solvers.

Parameters
stageis name of the solver stage.

◆ setTime()

template<typename Real, typename Index>
void TNL::Solvers::IterativeSolverMonitor< Real, Index >::setTime ( const RealType & time)

Set the time of the simulated evolution if it is time dependent.

This can be used for example when solving parabolic or hyperbolic PDEs.

Parameters
timetime of the simulated evolution.

◆ setTimeStep()

template<typename Real, typename Index>
void TNL::Solvers::IterativeSolverMonitor< Real, Index >::setTimeStep ( const RealType & timeStep)

Set the time step for time dependent iterative solvers.

Parameters
timeSteptime step of the time dependent iterative solver.

◆ setVerbose()

template<typename Real, typename Index>
void TNL::Solvers::IterativeSolverMonitor< Real, Index >::setVerbose ( const IndexType & verbose)

Set up the verbosity of the monitor.

Parameters
verboseis the new value of the verbosity of the monitor.

The documentation for this class was generated from the following files: