Introduction
Solvers of linear systems are one of the most important algorithms in scientific computations. TNL offers the following iterative methods:
- Stationary methods
- Jacobi method (TNL::Solvers::Linear::Jacobi)
- Successive-overrelaxation method, SOR (TNL::Solvers::Linear::SOR)
- Krylov subspace methods
- Conjugate gradient method, CG (TNL::Solvers::Linear::CG)
- Biconjugate gradient stabilized method, BICGStab (TNL::Solvers::Linear::BICGStab)
- Biconjugate gradient stabilized method, BICGStab(l) (TNL::Solvers::Linear::BICGStabL)
- Transpose-free quasi-minimal residual method, TFQMR (TNL::Solvers::Linear::TFQMR)
- Generalized minimal residual method, GMRES (TNL::Solvers::Linear::GMRES) with various methods of orthogonalization:
- Classical Gramm-Schmidt, CGS
- Classical Gramm-Schmidt with reorthogonalization, CGSR
- Modified Gramm-Schmidt, MGS
- Modified Gramm-Schmidt with reorthogonalization, MGSR
- Compact WY form of the Householder reflections, CWY
The iterative solvers (not the stationary solvers like TNL::Solvers::Linear::Jacobi and TNL::Solvers::Linear::SOR) can be combined with the following preconditioners:
- Diagonal or Jacobi (TNL::Solvers::Linear::Preconditioners::Diagonal)
- ILU (Incomplete LU) - CPU only currently
- ILU(0) (TNL::Solvers::Linear::Preconditioners::ILU0)
- ILUT (ILU with thresholding) (TNL::Solvers::Linear::Preconditioners::ILUT)
Iterative solvers of linear systems
Basic setup
All iterative solvers for linear systems can be found in the namespace TNL::Solvers::Linear. The following example shows the use the iterative solvers:
1#include <iostream>
2#include <memory>
3#include <TNL/Matrices/SparseMatrix.h>
4#include <TNL/Devices/Host.h>
5#include <TNL/Devices/Cuda.h>
6#include <TNL/Solvers/Linear/TFQMR.h>
7
8template< typename Device >
9void
10iterativeLinearSolverExample()
11{
12
13
14
15
16
17
18
19
20
23 const int size( 5 );
25 matrix_ptr->setDimensions( size, size );
26 matrix_ptr->setRowCapacities( Vector( { 2, 3, 3, 3, 2 } ) );
27
29 {
30 const int rowIdx = row.getRowIndex();
31 if( rowIdx == 0 ) {
32 row.setElement( 0, rowIdx, 2.5 );
33 row.setElement( 1, rowIdx + 1, -1 );
34 }
35 else if( rowIdx == size - 1 ) {
36 row.setElement( 0, rowIdx - 1, -1.0 );
37 row.setElement( 1, rowIdx, 2.5 );
38 }
39 else {
40 row.setElement( 0, rowIdx - 1, -1.0 );
41 row.setElement( 1, rowIdx, 2.5 );
42 row.setElement( 2, rowIdx + 1, -1.0 );
43 }
44 };
45
46
47
48
49 matrix_ptr->forAllRows( f );
51
52
53
54
55 Vector x( size, 1.0 );
56 Vector b( size );
57 matrix_ptr->vectorProduct( x, b );
58 x = 0.0;
60
61
62
63
65 LinearSolver solver;
67 solver.setConvergenceResidue( 1.0e-6 );
68 solver.solve( b, x );
70}
71
72int
73main( int argc, char* argv[] )
74{
75 std::cout <<
"Solving linear system on host:\n";
76 iterativeLinearSolverExample< TNL::Devices::Sequential >();
77
78#ifdef __CUDACC__
79 std::cout <<
"Solving linear system on CUDA device:\n";
80 iterativeLinearSolverExample< TNL::Devices::Cuda >();
81#endif
82}
#define __cuda_callable__
Definition Macros.h:49
Vector extends Array with algebraic operations.
Definition Vector.h:37
Implementation of sparse matrix, i.e. matrix storing only non-zero elements.
Definition SparseMatrix.h:57
virtual void setMatrix(const MatrixPointer &matrix)
Set the matrix of the linear system.
Definition LinearSolver.h:120
Iterative solver of linear systems based on the Transpose-free quasi-minimal residual (TFQMR) method.
Definition TFQMR.h:21
In this example we solve a linear system \( A \vec x = \vec b \) where
\[A = \left(
\begin{array}{cccc}
2.5 & -1 & & & \\
-1 & 2.5 & -1 & & \\
& -1 & 2.5 & -1 & \\
& & -1 & 2.5 & -1 \\
& & & -1 & 2.5 \\
\end{array}
\right)
\]
The right-hand side vector \(\vec b \) is set to \(( 1.5, 0.5, 0.5, 0.5, 1.5 )^T \) so that the exact solution is \( \vec x = ( 1, 1, 1, 1, 1 )^T \). The elements of the matrix \( A \) are set using the method TNL::Matrices::SparseMatrix::forAllRows. In this example, we use the sparse matrix but any other matrix type can be used as well (see the namespace TNL::Matrices). Next we set the solution vector \( \vec x = ( 1, 1, 1, 1, 1 )^T \) and multiply it with matrix \( A \) to get the right-hand side vector \( \vec b \). Finally, we reset the vector \( \vec x \) to zero.
To solve the linear system in the example, we use the TFQMR solver. Other solvers can be used as well (see the namespace TNL::Solvers::Linear). The solver needs only one template parameter which is the matrix type. Next we create an instance of the solver and set the matrix of the linear system. Note that the matrix is passed to the solver as a std::shared_ptr. Then we set the stopping criterion for the iterative method in terms of the relative residue, i.e. \( \lVert \vec b - A \vec x \rVert / \lVert b \rVert \). The solver is executed by calling the TNL::Solvers::Linear::LinearSolver::solve method which accepts the right-hand side vector \( \vec b \) and the solution vector \( \vec x \).
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 ]
Vector x = [ 1, 1, 1, 1, 1 ]
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 ]
Vector x = [ 1, 1, 1, 1, 1 ]
Setup with a solver monitor
Solution of large linear systems may take a lot of time. In such situations, it is useful to be able to monitor the convergence of the solver or the solver status in general. For this purpose, TNL provides a solver monitor which can show various metrics in real time, such as current number of iterations, current residue of the approximate solution, etc. The solver monitor in TNL runs in a separate thread and it refreshes the status of the solver with a configurable refresh rate (once per 500 ms by default). The use of the solver monitor is demonstrated in the following example.
1#include <iostream>
2#include <memory>
3#include <TNL/Matrices/SparseMatrix.h>
4#include <TNL/Devices/Sequential.h>
5#include <TNL/Devices/Cuda.h>
6#include <TNL/Solvers/Linear/Jacobi.h>
7
8template< typename Device >
9void
10iterativeLinearSolverExample()
11{
12
13
14
15
16
17
18
19
20
23 const int size( 5 );
25 matrix_ptr->setDimensions( size, size );
26 matrix_ptr->setRowCapacities( Vector( { 2, 3, 3, 3, 2 } ) );
27
29 {
30 const int rowIdx = row.getRowIndex();
31 if( rowIdx == 0 ) {
32 row.setElement( 0, rowIdx, 2.5 );
33 row.setElement( 1, rowIdx + 1, -1 );
34 }
35 else if( rowIdx == size - 1 ) {
36 row.setElement( 0, rowIdx - 1, -1.0 );
37 row.setElement( 1, rowIdx, 2.5 );
38 }
39 else {
40 row.setElement( 0, rowIdx - 1, -1.0 );
41 row.setElement( 1, rowIdx, 2.5 );
42 row.setElement( 2, rowIdx + 1, -1.0 );
43 }
44 };
45
46
47
48
49 matrix_ptr->forAllRows( f );
51
52
53
54
55 Vector x( size, 1.0 );
56 Vector b( size );
57 matrix_ptr->vectorProduct( x, b );
58 x = 0.0;
60
61
62
63
65 LinearSolver solver;
67 solver.setOmega( 0.0005 );
68
69
70
71
73 IterativeSolverMonitorType monitor;
75 monitor.setRefreshRate( 10 );
76 monitor.setVerbose( 1 );
77 monitor.setStage( "Jacobi stage:" );
78 solver.setSolverMonitor( monitor );
79 solver.setConvergenceResidue( 1.0e-6 );
80 solver.solve( b, x );
81 monitor.stopMainLoop();
83}
84
85int
86main( int argc, char* argv[] )
87{
88 std::cout <<
"Solving linear system on host:\n";
89 iterativeLinearSolverExample< TNL::Devices::Sequential >();
90
91#ifdef __CUDACC__
92 std::cout <<
"Solving linear system on CUDA device:\n";
93 iterativeLinearSolverExample< TNL::Devices::Cuda >();
94#endif
95}
Iterative solver of linear systems based on the Jacobi method.
Definition Jacobi.h:21
A RAII wrapper for launching the SolverMonitor's main loop in a separate thread.
Definition SolverMonitor.h:142
First, we set up the same linear system as in the previous example, we create an instance of the Jacobi solver and we pass the matrix of the linear system to the solver. Then, we set the relaxation parameter \( \omega \) of the Jacobi solver to 0.0005. The reason is to artificially slow down the convergence, because we want to see some iterations in this example. Next, we create an instance of the solver monitor and a special thread for the monitor (an instance of the TNL::Solvers::SolverMonitorThread class). We use the following methods to configure the solver monitor:
Next, we call TNL::Solvers::IterativeSolver::setSolverMonitor to connect the solver with the monitor and we set the convergence criterion based on the relative residue. Finally, we start the solver using the TNL::Solvers::Linear::Jacobi::solve method and when the solver finishes, we stop the monitor using TNL::Solvers::SolverMonitor::stopMainLoop.
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: 22373 RES: 0.02324
Jacobi stage: ITER: 45463 RES: 0.00067001
Jacobi stage: ITER: 67405 RES: 2.3027e-05
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: 4175 RES: 0.38852
Jacobi stage: ITER: 4553 RES: 0.36474
Jacobi stage: ITER: 4931 RES: 0.343
Jacobi stage: ITER: 5307 RES: 0.32284
Jacobi stage: ITER: 5679 RES: 0.30425
Jacobi stage: ITER: 6063 RES: 0.28632
Jacobi stage: ITER: 6443 RES: 0.26974
Jacobi stage: ITER: 6821 RES: 0.25419
Jacobi stage: ITER: 7191 RES: 0.24003
Jacobi stage: ITER: 7547 RES: 0.22713
Jacobi stage: ITER: 7787 RES: 0.21884
Jacobi stage: ITER: 8065 RES: 0.20957
Jacobi stage: ITER: 8195 RES: 0.20546
Jacobi stage: ITER: 8291 RES: 0.20244
Jacobi stage: ITER: 8359 RES: 0.20032
Jacobi stage: ITER: 8467 RES: 0.19701
Jacobi stage: ITER: 8623 RES: 0.19232
Jacobi stage: ITER: 8847 RES: 0.18579
Jacobi stage: ITER: 9103 RES: 0.17861
Jacobi stage: ITER: 9317 RES: 0.17276
Jacobi stage: ITER: 9561 RES: 0.16639
Jacobi stage: ITER: 9829 RES: 0.15967
Jacobi stage: ITER: 10077 RES: 0.15369
Jacobi stage: ITER: 10329 RES: 0.14784
Jacobi stage: ITER: 10563 RES: 0.14266
Jacobi stage: ITER: 10859 RES: 0.13631
Jacobi stage: ITER: 11115 RES: 0.13105
Jacobi stage: ITER: 11361 RES: 0.12615
Jacobi stage: ITER: 11565 RES: 0.12226
Jacobi stage: ITER: 11823 RES: 0.11754
Jacobi stage: ITER: 12061 RES: 0.11329
Jacobi stage: ITER: 12299 RES: 0.10925
Jacobi stage: ITER: 12551 RES: 0.1051
Jacobi stage: ITER: 12803 RES: 0.10111
Jacobi stage: ITER: 13007 RES: 0.097991
Jacobi stage: ITER: 13251 RES: 0.094385
Jacobi stage: ITER: 13763 RES: 0.087246
Jacobi stage: ITER: 14133 RES: 0.0824
Jacobi stage: ITER: 14299 RES: 0.08035
Jacobi stage: ITER: 14497 RES: 0.077919
Jacobi stage: ITER: 14719 RES: 0.07533
Jacobi stage: ITER: 15049 RES: 0.071584
Jacobi stage: ITER: 15227 RES: 0.069675
Jacobi stage: ITER: 15403 RES: 0.067816
Jacobi stage: ITER: 15655 RES: 0.065242
Jacobi stage: ITER: 15909 RES: 0.062726
Jacobi stage: ITER: 16163 RES: 0.060344
Jacobi stage: ITER: 16419 RES: 0.058017
Jacobi stage: ITER: 16653 RES: 0.055952
Jacobi stage: ITER: 16909 RES: 0.053794
Jacobi stage: ITER: 17143 RES: 0.051911
Jacobi stage: ITER: 17379 RES: 0.050063
Jacobi stage: ITER: 17627 RES: 0.048192
Jacobi stage: ITER: 17879 RES: 0.046362
Jacobi stage: ITER: 18119 RES: 0.044684
Jacobi stage: ITER: 18341 RES: 0.043173
Jacobi stage: ITER: 18569 RES: 0.041687
Jacobi stage: ITER: 18823 RES: 0.040104
Jacobi stage: ITER: 19069 RES: 0.038605
Jacobi stage: ITER: 19309 RES: 0.037208
Jacobi stage: ITER: 19561 RES: 0.035795
Jacobi stage: ITER: 19795 RES: 0.034542
Jacobi stage: ITER: 20037 RES: 0.033271
Jacobi stage: ITER: 20271 RES: 0.032107
Jacobi stage: ITER: 20489 RES: 0.03104
Jacobi stage: ITER: 20743 RES: 0.029861
Jacobi stage: ITER: 20997 RES: 0.02871
Jacobi stage: ITER: 21251 RES: 0.02762
Jacobi stage: ITER: 21489 RES: 0.02662
Jacobi stage: ITER: 21715 RES: 0.02572
Jacobi stage: ITER: 21941 RES: 0.024835
Jacobi stage: ITER: 22175 RES: 0.023965
Jacobi stage: ITER: 22413 RES: 0.023098
Jacobi stage: ITER: 22667 RES: 0.022221
Jacobi stage: ITER: 22921 RES: 0.021364
Jacobi stage: ITER: 23175 RES: 0.020553
Jacobi stage: ITER: 23405 RES: 0.019833
Jacobi stage: ITER: 23639 RES: 0.019139
Jacobi stage: ITER: 23863 RES: 0.018492
Jacobi stage: ITER: 24115 RES: 0.01779
Jacobi stage: ITER: 24333 RES: 0.017199
Jacobi stage: ITER: 24581 RES: 0.016556
Jacobi stage: ITER: 24839 RES: 0.015917
Jacobi stage: ITER: 25091 RES: 0.015313
Jacobi stage: ITER: 25311 RES: 0.014804
Jacobi stage: ITER: 25551 RES: 0.014268
Jacobi stage: ITER: 25803 RES: 0.013727
Jacobi stage: ITER: 25951 RES: 0.013418
Jacobi stage: ITER: 26187 RES: 0.01294
Jacobi stage: ITER: 26461 RES: 0.012403
Jacobi stage: ITER: 26713 RES: 0.011932
Jacobi stage: ITER: 26965 RES: 0.011479
Jacobi stage: ITER: 27217 RES: 0.011043
Jacobi stage: ITER: 27471 RES: 0.010624
Jacobi stage: ITER: 27725 RES: 0.010215
Jacobi stage: ITER: 27967 RES: 0.0098448
Jacobi stage: ITER: 28125 RES: 0.0096058
Jacobi stage: ITER: 28307 RES: 0.0093439
Jacobi stage: ITER: 28553 RES: 0.0089946
Jacobi stage: ITER: 28805 RES: 0.0086531
Jacobi stage: ITER: 29051 RES: 0.0083348
Jacobi stage: ITER: 29325 RES: 0.0079889
Jacobi stage: ITER: 29687 RES: 0.0075591
Jacobi stage: ITER: 29929 RES: 0.007281
Jacobi stage: ITER: 30177 RES: 0.0070089
Jacobi stage: ITER: 30429 RES: 0.0067428
Jacobi stage: ITER: 30639 RES: 0.0065307
Jacobi stage: ITER: 30871 RES: 0.0063021
Jacobi stage: ITER: 31111 RES: 0.006074
Jacobi stage: ITER: 31363 RES: 0.0058434
Jacobi stage: ITER: 31603 RES: 0.0056319
Jacobi stage: ITER: 31857 RES: 0.0054148
Jacobi stage: ITER: 32111 RES: 0.0052092
Jacobi stage: ITER: 32347 RES: 0.0050237
Jacobi stage: ITER: 32569 RES: 0.0048538
Jacobi stage: ITER: 32817 RES: 0.0046724
Jacobi stage: ITER: 33067 RES: 0.0044977
Jacobi stage: ITER: 33295 RES: 0.004343
Jacobi stage: ITER: 33547 RES: 0.0041781
Jacobi stage: ITER: 33795 RES: 0.0040219
Jacobi stage: ITER: 34031 RES: 0.0038787
Jacobi stage: ITER: 34281 RES: 0.0037315
Jacobi stage: ITER: 34523 RES: 0.0035964
Jacobi stage: ITER: 34749 RES: 0.0034726
Jacobi stage: ITER: 34997 RES: 0.0033428
Jacobi stage: ITER: 35225 RES: 0.0032278
Jacobi stage: ITER: 35475 RES: 0.0031071
Jacobi stage: ITER: 35719 RES: 0.0029928
Jacobi stage: ITER: 35947 RES: 0.0028898
Jacobi stage: ITER: 36195 RES: 0.0027818
Jacobi stage: ITER: 36441 RES: 0.0026779
Jacobi stage: ITER: 36671 RES: 0.0025857
Jacobi stage: ITER: 36913 RES: 0.0024906
Jacobi stage: ITER: 37143 RES: 0.0024049
Jacobi stage: ITER: 37397 RES: 0.0023121
Jacobi stage: ITER: 37627 RES: 0.0022326
Jacobi stage: ITER: 37819 RES: 0.0021677
Jacobi stage: ITER: 38063 RES: 0.002088
Jacobi stage: ITER: 38277 RES: 0.0020198
Jacobi stage: ITER: 38523 RES: 0.0019455
Jacobi stage: ITER: 38775 RES: 0.0018716
Jacobi stage: ITER: 39027 RES: 0.0018006
Jacobi stage: ITER: 39263 RES: 0.0017365
Jacobi stage: ITER: 39513 RES: 0.0016706
Jacobi stage: ITER: 39745 RES: 0.0016121
Jacobi stage: ITER: 39981 RES: 0.0015547
Jacobi stage: ITER: 40235 RES: 0.0014956
Jacobi stage: ITER: 40467 RES: 0.0014433
Jacobi stage: ITER: 40721 RES: 0.0013876
Jacobi stage: ITER: 40963 RES: 0.0013374
Jacobi stage: ITER: 41223 RES: 0.0012851
Jacobi stage: ITER: 41435 RES: 0.0012439
Jacobi stage: ITER: 41639 RES: 0.0012055
Jacobi stage: ITER: 41903 RES: 0.0011576
Jacobi stage: ITER: 42163 RES: 0.0011123
Jacobi stage: ITER: 42435 RES: 0.0010668
Jacobi stage: ITER: 42687 RES: 0.0010263
Jacobi stage: ITER: 42939 RES: 0.0009873
Jacobi stage: ITER: 43189 RES: 0.00094982
Jacobi stage: ITER: 43439 RES: 0.00091432
Jacobi stage: ITER: 43691 RES: 0.0008796
Jacobi stage: ITER: 43941 RES: 0.0008462
Jacobi stage: ITER: 44191 RES: 0.00081458
Jacobi stage: ITER: 44443 RES: 0.00078365
Jacobi stage: ITER: 44693 RES: 0.00075389
Jacobi stage: ITER: 44943 RES: 0.00072572
Jacobi stage: ITER: 45195 RES: 0.00069816
Jacobi stage: ITER: 45445 RES: 0.00067165
Jacobi stage: ITER: 45695 RES: 0.00064655
Jacobi stage: ITER: 45945 RES: 0.000622
Jacobi stage: ITER: 46195 RES: 0.00059875
Jacobi stage: ITER: 46447 RES: 0.00057602
Jacobi stage: ITER: 46697 RES: 0.00055415
Jacobi stage: ITER: 46947 RES: 0.00053344
Jacobi stage: ITER: 47199 RES: 0.00051318
Jacobi stage: ITER: 47449 RES: 0.0004937
Jacobi stage: ITER: 47699 RES: 0.00047525
Jacobi stage: ITER: 47951 RES: 0.0004572
Jacobi stage: ITER: 48201 RES: 0.00043984
Jacobi stage: ITER: 48451 RES: 0.0004234
Jacobi stage: ITER: 48703 RES: 0.00040733
Jacobi stage: ITER: 48953 RES: 0.00039186
Jacobi stage: ITER: 49203 RES: 0.00037722
Jacobi stage: ITER: 49453 RES: 0.00036289
Jacobi stage: ITER: 49703 RES: 0.00034933
Jacobi stage: ITER: 49955 RES: 0.00033607
Jacobi stage: ITER: 50205 RES: 0.00032331
Jacobi stage: ITER: 50455 RES: 0.00031122
Jacobi stage: ITER: 50707 RES: 0.00029941
Jacobi stage: ITER: 50957 RES: 0.00028804
Jacobi stage: ITER: 51207 RES: 0.00027727
Jacobi stage: ITER: 51459 RES: 0.00026674
Jacobi stage: ITER: 51709 RES: 0.00025662
Jacobi stage: ITER: 51959 RES: 0.00024703
Jacobi stage: ITER: 52211 RES: 0.00023765
Jacobi stage: ITER: 52461 RES: 0.00022862
Jacobi stage: ITER: 52711 RES: 0.00022008
Jacobi stage: ITER: 52963 RES: 0.00021172
Jacobi stage: ITER: 53213 RES: 0.00020368
Jacobi stage: ITER: 53463 RES: 0.00019607
Jacobi stage: ITER: 53715 RES: 0.00018863
Jacobi stage: ITER: 53965 RES: 0.00018146
Jacobi stage: ITER: 54215 RES: 0.00017468
Jacobi stage: ITER: 54465 RES: 0.00016805
Jacobi stage: ITER: 54715 RES: 0.00016177
Jacobi stage: ITER: 54967 RES: 0.00015563
Jacobi stage: ITER: 55217 RES: 0.00014972
Jacobi stage: ITER: 55467 RES: 0.00014412
Jacobi stage: ITER: 55719 RES: 0.00013865
Jacobi stage: ITER: 55969 RES: 0.00013339
Jacobi stage: ITER: 56219 RES: 0.0001284
Jacobi stage: ITER: 56471 RES: 0.00012352
Jacobi stage: ITER: 56721 RES: 0.00011883
Jacobi stage: ITER: 56971 RES: 0.00011439
Jacobi stage: ITER: 57223 RES: 0.00011005
Jacobi stage: ITER: 57473 RES: 0.00010587
Jacobi stage: ITER: 57723 RES: 0.00010191
Jacobi stage: ITER: 57973 RES: 9.8045e-05
Jacobi stage: ITER: 58223 RES: 9.438e-05
Jacobi stage: ITER: 58475 RES: 9.0797e-05
Jacobi stage: ITER: 58725 RES: 8.7349e-05
Jacobi stage: ITER: 58975 RES: 8.4084e-05
Jacobi stage: ITER: 59227 RES: 8.0892e-05
Jacobi stage: ITER: 59477 RES: 7.7821e-05
Jacobi stage: ITER: 59727 RES: 7.4912e-05
Jacobi stage: ITER: 59977 RES: 7.2068e-05
Jacobi stage: ITER: 60227 RES: 6.9374e-05
Jacobi stage: ITER: 60479 RES: 6.674e-05
Jacobi stage: ITER: 60729 RES: 6.4206e-05
Jacobi stage: ITER: 60979 RES: 6.1806e-05
Jacobi stage: ITER: 61231 RES: 5.946e-05
Jacobi stage: ITER: 61481 RES: 5.7202e-05
Jacobi stage: ITER: 61731 RES: 5.5064e-05
Jacobi stage: ITER: 61981 RES: 5.2973e-05
Jacobi stage: ITER: 62231 RES: 5.0993e-05
Jacobi stage: ITER: 62483 RES: 4.9057e-05
Jacobi stage: ITER: 62733 RES: 4.7195e-05
Jacobi stage: ITER: 62983 RES: 4.5431e-05
Jacobi stage: ITER: 63235 RES: 4.3706e-05
Jacobi stage: ITER: 63485 RES: 4.2046e-05
Jacobi stage: ITER: 63739 RES: 4.045e-05
Jacobi stage: ITER: 63991 RES: 3.8914e-05
Jacobi stage: ITER: 64589 RES: 3.5488e-05
Jacobi stage: ITER: 64839 RES: 3.4162e-05
Jacobi stage: ITER: 65091 RES: 3.2865e-05
Jacobi stage: ITER: 65341 RES: 3.1617e-05
Jacobi stage: ITER: 65591 RES: 3.0435e-05
Jacobi stage: ITER: 65843 RES: 2.9279e-05
Jacobi stage: ITER: 66093 RES: 2.8168e-05
Jacobi stage: ITER: 66343 RES: 2.7115e-05
Jacobi stage: ITER: 66595 RES: 2.6085e-05
Jacobi stage: ITER: 66843 RES: 2.511e-05
Jacobi stage: ITER: 67095 RES: 2.4157e-05
Jacobi stage: ITER: 67345 RES: 2.324e-05
Jacobi stage: ITER: 67595 RES: 2.2371e-05
Jacobi stage: ITER: 67847 RES: 2.1522e-05
Jacobi stage: ITER: 68097 RES: 2.0705e-05
Jacobi stage: ITER: 68347 RES: 1.9931e-05
Jacobi stage: ITER: 68597 RES: 1.9174e-05
Jacobi stage: ITER: 68847 RES: 1.8457e-05
Jacobi stage: ITER: 69099 RES: 1.7757e-05
Jacobi stage: ITER: 69349 RES: 1.7082e-05
Jacobi stage: ITER: 69599 RES: 1.6444e-05
Jacobi stage: ITER: 69851 RES: 1.582e-05
Jacobi stage: ITER: 70101 RES: 1.5219e-05
Jacobi stage: ITER: 70351 RES: 1.465e-05
Jacobi stage: ITER: 70601 RES: 1.4094e-05
Jacobi stage: ITER: 70851 RES: 1.3567e-05
Jacobi stage: ITER: 71103 RES: 1.3052e-05
Jacobi stage: ITER: 71349 RES: 1.2564e-05
Jacobi stage: ITER: 71599 RES: 1.2095e-05
Jacobi stage: ITER: 71851 RES: 1.1635e-05
Jacobi stage: ITER: 72101 RES: 1.1194e-05
Jacobi stage: ITER: 72351 RES: 1.0775e-05
Jacobi stage: ITER: 72603 RES: 1.0366e-05
Jacobi stage: ITER: 72853 RES: 9.9725e-06
Jacobi stage: ITER: 73103 RES: 9.5998e-06
Jacobi stage: ITER: 73355 RES: 9.2353e-06
Jacobi stage: ITER: 73603 RES: 8.8901e-06
Jacobi stage: ITER: 73855 RES: 8.5525e-06
Jacobi stage: ITER: 74105 RES: 8.2278e-06
Jacobi stage: ITER: 74355 RES: 7.9203e-06
Jacobi stage: ITER: 74607 RES: 7.6196e-06
Jacobi stage: ITER: 74857 RES: 7.3303e-06
Jacobi stage: ITER: 75107 RES: 7.0563e-06
Jacobi stage: ITER: 75359 RES: 6.7884e-06
Jacobi stage: ITER: 75607 RES: 6.5346e-06
Jacobi stage: ITER: 75859 RES: 6.2865e-06
Jacobi stage: ITER: 76109 RES: 6.0479e-06
Jacobi stage: ITER: 76359 RES: 5.8218e-06
Jacobi stage: ITER: 76611 RES: 5.6008e-06
Jacobi stage: ITER: 76861 RES: 5.3881e-06
Jacobi stage: ITER: 77111 RES: 5.1867e-06
Jacobi stage: ITER: 77361 RES: 4.9898e-06
Jacobi stage: ITER: 77611 RES: 4.8033e-06
Jacobi stage: ITER: 77863 RES: 4.6209e-06
Jacobi stage: ITER: 78113 RES: 4.4455e-06
Jacobi stage: ITER: 78363 RES: 4.2793e-06
Jacobi stage: ITER: 78615 RES: 4.1168e-06
Jacobi stage: ITER: 78863 RES: 3.963e-06
Jacobi stage: ITER: 79115 RES: 3.8125e-06
Jacobi stage: ITER: 79365 RES: 3.6677e-06
Jacobi stage: ITER: 79615 RES: 3.5307e-06
Jacobi stage: ITER: 79867 RES: 3.3966e-06
Jacobi stage: ITER: 80117 RES: 3.2676e-06
Jacobi stage: ITER: 80367 RES: 3.1455e-06
Jacobi stage: ITER: 80617 RES: 3.0261e-06
Jacobi stage: ITER: 80867 RES: 2.913e-06
Jacobi stage: ITER: 81119 RES: 2.8024e-06
Jacobi stage: ITER: 81369 RES: 2.696e-06
Jacobi stage: ITER: 81619 RES: 2.5952e-06
Jacobi stage: ITER: 81871 RES: 2.4967e-06
Jacobi stage: ITER: 82119 RES: 2.4034e-06
Jacobi stage: ITER: 82371 RES: 2.3121e-06
Jacobi stage: ITER: 82621 RES: 2.2243e-06
Jacobi stage: ITER: 82871 RES: 2.1412e-06
Jacobi stage: ITER: 83123 RES: 2.0599e-06
Jacobi stage: ITER: 83373 RES: 1.9817e-06
Jacobi stage: ITER: 83623 RES: 1.9076e-06
Jacobi stage: ITER: 83875 RES: 1.8352e-06
Jacobi stage: ITER: 84123 RES: 1.7666e-06
Jacobi stage: ITER: 84375 RES: 1.6995e-06
Jacobi stage: ITER: 84625 RES: 1.635e-06
Jacobi stage: ITER: 84875 RES: 1.5739e-06
Jacobi stage: ITER: 85127 RES: 1.5141e-06
Jacobi stage: ITER: 85377 RES: 1.4566e-06
Jacobi stage: ITER: 85627 RES: 1.4022e-06
Jacobi stage: ITER: 85879 RES: 1.3489e-06
Jacobi stage: ITER: 86129 RES: 1.2977e-06
Jacobi stage: ITER: 86379 RES: 1.2492e-06
Jacobi stage: ITER: 86629 RES: 1.2018e-06
Jacobi stage: ITER: 86879 RES: 1.1569e-06
Jacobi stage: ITER: 87131 RES: 1.1129e-06
Jacobi stage: ITER: 87381 RES: 1.0707e-06
Jacobi stage: ITER: 87631 RES: 1.0307e-06
Vector x = [ 0.999999, 0.999999, 0.999998, 0.999999, 0.999999 ]
The monitoring of the solver can be improved by time elapsed since the beginning of the computation as demonstrated in the following example:
1#include <iostream>
2#include <memory>
3#include <TNL/Timer.h>
4#include <TNL/Matrices/SparseMatrix.h>
5#include <TNL/Devices/Sequential.h>
6#include <TNL/Devices/Cuda.h>
7#include <TNL/Solvers/Linear/Jacobi.h>
8
9template< typename Device >
10void
11iterativeLinearSolverExample()
12{
13
14
15
16
17
18
19
20
21
24 const int size( 5 );
26 matrix_ptr->setDimensions( size, size );
27 matrix_ptr->setRowCapacities( Vector( { 2, 3, 3, 3, 2 } ) );
28
30 {
31 const int rowIdx = row.getRowIndex();
32 if( rowIdx == 0 ) {
33 row.setElement( 0, rowIdx, 2.5 );
34 row.setElement( 1, rowIdx + 1, -1 );
35 }
36 else if( rowIdx == size - 1 ) {
37 row.setElement( 0, rowIdx - 1, -1.0 );
38 row.setElement( 1, rowIdx, 2.5 );
39 }
40 else {
41 row.setElement( 0, rowIdx - 1, -1.0 );
42 row.setElement( 1, rowIdx, 2.5 );
43 row.setElement( 2, rowIdx + 1, -1.0 );
44 }
45 };
46
47
48
49
50 matrix_ptr->forAllRows( f );
52
53
54
55
56 Vector x( size, 1.0 );
57 Vector b( size );
58 matrix_ptr->vectorProduct( x, b );
59 x = 0.0;
61
62
63
64
66 LinearSolver solver;
68 solver.setOmega( 0.0005 );
69
70
71
72
74 IterativeSolverMonitorType monitor;
76 monitor.setRefreshRate( 10 );
77 monitor.setVerbose( 1 );
78 monitor.setStage( "Jacobi stage:" );
80 monitor.setTimer( timer );
82 solver.setSolverMonitor( monitor );
83 solver.setConvergenceResidue( 1.0e-6 );
84 solver.solve( b, x );
85 monitor.stopMainLoop();
87}
88
89int
90main( int argc, char* argv[] )
91{
92 std::cout <<
"Solving linear system on host:\n";
93 iterativeLinearSolverExample< TNL::Devices::Sequential >();
94
95#ifdef __CUDACC__
96 std::cout <<
"Solving linear system on CUDA device:\n";
97 iterativeLinearSolverExample< TNL::Devices::Cuda >();
98#endif
99}
Class for real time, CPU time and CPU cycles measuring.
Definition Timer.h:25
void start()
Starts timer.
The only changes are around the lines where we create an instance of TNL::Timer, connect it with the monitor using TNL::Solvers::SolverMonitor::setTimer and start the timer with TNL::Timer::start.
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:1.4492e-
ELA: 0.10013 Jacobi stage: ITER: 24099 RES: 0.017823
ELA: 0.20026 Jacobi stage: ITER: 48573 RES: 0.00041541
ELA: 0.3004 Jacobi stage: ITER: 70417 RES: 1.4498e-05
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:2.9514e-
ELA: 0.10016 Jacobi stage: ITER: 377 RES: 0.88333
ELA: 0.20029 Jacobi stage: ITER: 755 RES: 0.78983
ELA: 0.30042 Jacobi stage: ITER: 1141 RES: 0.71145
ELA: 0.40054 Jacobi stage: ITER: 1521 RES: 0.64802
ELA: 0.50367 Jacobi stage: ITER: 2123 RES: 0.56725
ELA: 0.60378 Jacobi stage: ITER: 2505 RES: 0.52465
ELA: 0.7039 Jacobi stage: ITER: 2907 RES: 0.48584
ELA: 0.80402 Jacobi stage: ITER: 3277 RES: 0.4538
ELA: 0.90415 Jacobi stage: ITER: 3649 RES: 0.4249
ELA: 1.0043 Jacobi stage: ITER: 3901 RES: 0.40684
ELA: 1.1044 Jacobi stage: ITER: 4191 RES: 0.38748
ELA: 1.2045 Jacobi stage: ITER: 4503 RES: 0.36788
ELA: 1.3046 Jacobi stage: ITER: 4755 RES: 0.35297
ELA: 1.4047 Jacobi stage: ITER: 5037 RES: 0.33706
ELA: 1.5049 Jacobi stage: ITER: 5257 RES: 0.32533
ELA: 1.605 Jacobi stage: ITER: 5487 RES: 0.31368
ELA: 1.7051 Jacobi stage: ITER: 5711 RES: 0.30271
ELA: 1.8052 Jacobi stage: ITER: 5963 RES: 0.29087
ELA: 1.9053 Jacobi stage: ITER: 6189 RES: 0.28061
ELA: 2.0055 Jacobi stage: ITER: 6399 RES: 0.2716
ELA: 2.1056 Jacobi stage: ITER: 6503 RES: 0.26721
ELA: 2.2057 Jacobi stage: ITER: 6657 RES: 0.26077
ELA: 2.3058 Jacobi stage: ITER: 6823 RES: 0.25419
ELA: 2.4059 Jacobi stage: ITER: 7045 RES: 0.24547
ELA: 2.5087 Jacobi stage: ITER: 7217 RES: 0.23899
ELA: 2.6088 Jacobi stage: ITER: 7481 RES: 0.2294
ELA: 2.7089 Jacobi stage: ITER: 7653 RES: 0.22336
ELA: 2.809 Jacobi stage: ITER: 7843 RES: 0.21695
ELA: 2.9091 Jacobi stage: ITER: 7985 RES: 0.21217
ELA: 3.0092 Jacobi stage: ITER: 8111 RES: 0.20815
ELA: 3.1094 Jacobi stage: ITER: 8307 RES: 0.20194
ELA: 3.2095 Jacobi stage: ITER: 8571 RES: 0.19387
ELA: 3.3096 Jacobi stage: ITER: 8819 RES: 0.1866
ELA: 3.4097 Jacobi stage: ITER: 8927 RES: 0.18352
ELA: 3.5099 Jacobi stage: ITER: 9169 RES: 0.17674
ELA: 3.61 Jacobi stage: ITER: 9413 RES: 0.17023
ELA: 3.7107 Jacobi stage: ITER: 9611 RES: 0.16516
ELA: 3.8117 Jacobi stage: ITER: 9775 RES: 0.16105
ELA: 3.9118 Jacobi stage: ITER: 9967 RES: 0.15636
ELA: 4.0127 Jacobi stage: ITER: 10199 RES: 0.15088
ELA: 4.1128 Jacobi stage: ITER: 10371 RES: 0.14694
ELA: 4.2137 Jacobi stage: ITER: 10645 RES: 0.14083
ELA: 4.3138 Jacobi stage: ITER: 10847 RES: 0.13657
ELA: 4.4139 Jacobi stage: ITER: 11083 RES: 0.1317
ELA: 4.514 Jacobi stage: ITER: 11337 RES: 0.12662
ELA: 4.6141 Jacobi stage: ITER: 11591 RES: 0.12181
ELA: 4.7142 Jacobi stage: ITER: 11843 RES: 0.11718
ELA: 4.8143 Jacobi stage: ITER: 12079 RES: 0.11301
ELA: 4.9145 Jacobi stage: ITER: 12331 RES: 0.10872
ELA: 5.0146 Jacobi stage: ITER: 12567 RES: 0.10484
ELA: 5.1147 Jacobi stage: ITER: 12801 RES: 0.10111
ELA: 5.2148 Jacobi stage: ITER: 13047 RES: 0.09739
ELA: 5.3157 Jacobi stage: ITER: 13299 RES: 0.093692
ELA: 5.4158 Jacobi stage: ITER: 13535 RES: 0.090356
ELA: 5.5159 Jacobi stage: ITER: 13759 RES: 0.0873
ELA: 5.6163 Jacobi stage: ITER: 14005 RES: 0.084036
ELA: 5.7164 Jacobi stage: ITER: 14229 RES: 0.081194
ELA: 5.8165 Jacobi stage: ITER: 14475 RES: 0.078207
ELA: 5.9167 Jacobi stage: ITER: 14715 RES: 0.075376
ELA: 6.0168 Jacobi stage: ITER: 14963 RES: 0.072558
ELA: 6.1169 Jacobi stage: ITER: 15191 RES: 0.070061
ELA: 6.217 Jacobi stage: ITER: 15443 RES: 0.067401
ELA: 6.3177 Jacobi stage: ITER: 15667 RES: 0.065121
ELA: 6.4178 Jacobi stage: ITER: 15883 RES: 0.062996
ELA: 6.5179 Jacobi stage: ITER: 16127 RES: 0.060679
ELA: 6.618 Jacobi stage: ITER: 16381 RES: 0.058339
ELA: 6.7182 Jacobi stage: ITER: 16635 RES: 0.056124
ELA: 6.8183 Jacobi stage: ITER: 16875 RES: 0.054093
ELA: 6.9184 Jacobi stage: ITER: 17101 RES: 0.052231
ELA: 7.0185 Jacobi stage: ITER: 17321 RES: 0.050495
ELA: 7.1197 Jacobi stage: ITER: 17567 RES: 0.048638
ELA: 7.2198 Jacobi stage: ITER: 17791 RES: 0.046993
ELA: 7.3199 Jacobi stage: ITER: 18035 RES: 0.045264
ELA: 7.42 Jacobi stage: ITER: 18287 RES: 0.043546
ELA: 7.5201 Jacobi stage: ITER: 18541 RES: 0.041867
ELA: 7.6203 Jacobi stage: ITER: 18775 RES: 0.040401
ELA: 7.7204 Jacobi stage: ITER: 18999 RES: 0.039034
ELA: 7.8205 Jacobi stage: ITER: 19247 RES: 0.037575
ELA: 7.9206 Jacobi stage: ITER: 19473 RES: 0.036282
ELA: 8.0208 Jacobi stage: ITER: 19691 RES: 0.035098
ELA: 8.1227 Jacobi stage: ITER: 19939 RES: 0.033786
ELA: 8.2228 Jacobi stage: ITER: 20191 RES: 0.032504
ELA: 8.3229 Jacobi stage: ITER: 20443 RES: 0.03127
ELA: 8.423 Jacobi stage: ITER: 20663 RES: 0.030231
ELA: 8.5257 Jacobi stage: ITER: 20907 RES: 0.029118
ELA: 8.6258 Jacobi stage: ITER: 21151 RES: 0.028047
ELA: 8.7259 Jacobi stage: ITER: 21545 RES: 0.026392
ELA: 8.826 Jacobi stage: ITER: 21807 RES: 0.025359
ELA: 8.9261 Jacobi stage: ITER: 22051 RES: 0.024426
ELA: 9.0263 Jacobi stage: ITER: 22299 RES: 0.023513
ELA: 9.1264 Jacobi stage: ITER: 22551 RES: 0.02262
ELA: 9.2265 Jacobi stage: ITER: 22803 RES: 0.021762
ELA: 9.3266 Jacobi stage: ITER: 23055 RES: 0.020935
ELA: 9.4277 Jacobi stage: ITER: 23311 RES: 0.020128
ELA: 9.5278 Jacobi stage: ITER: 23555 RES: 0.019388
ELA: 9.6279 Jacobi stage: ITER: 23729 RES: 0.018871
ELA: 9.728 Jacobi stage: ITER: 23895 RES: 0.018401
ELA: 9.8287 Jacobi stage: ITER: 24135 RES: 0.017735
ELA: 9.9288 Jacobi stage: ITER: 24383 RES: 0.017072
ELA: 10.033 Jacobi stage: ITER: 24635 RES: 0.016424
ELA: 10.133 Jacobi stage: ITER: 24881 RES: 0.01581
ELA: 10.233 Jacobi stage: ITER: 25167 RES: 0.015135
ELA: 10.333 Jacobi stage: ITER: 25409 RES: 0.014579
ELA: 10.433 Jacobi stage: ITER: 25659 RES: 0.014034
ELA: 10.533 Jacobi stage: ITER: 25907 RES: 0.013509
ELA: 10.633 Jacobi stage: ITER: 26119 RES: 0.013076
ELA: 10.737 Jacobi stage: ITER: 26361 RES: 0.012595
ELA: 10.837 Jacobi stage: ITER: 26595 RES: 0.012154
ELA: 10.938 Jacobi stage: ITER: 26847 RES: 0.011693
ELA: 11.038 Jacobi stage: ITER: 27089 RES: 0.011263
ELA: 11.138 Jacobi stage: ITER: 27331 RES: 0.010855
ELA: 11.239 Jacobi stage: ITER: 27581 RES: 0.010443
ELA: 11.339 Jacobi stage: ITER: 27819 RES: 0.010071
ELA: 11.439 Jacobi stage: ITER: 28055 RES: 0.0097126
ELA: 11.539 Jacobi stage: ITER: 28289 RES: 0.0093669
ELA: 11.64 Jacobi stage: ITER: 28529 RES: 0.0090278
ELA: 11.74 Jacobi stage: ITER: 28777 RES: 0.0086904
ELA: 11.844 Jacobi stage: ITER: 29015 RES: 0.008381
ELA: 11.944 Jacobi stage: ITER: 29259 RES: 0.0080727
ELA: 12.044 Jacobi stage: ITER: 29495 RES: 0.0077853
ELA: 12.144 Jacobi stage: ITER: 29743 RES: 0.0074943
ELA: 12.244 Jacobi stage: ITER: 29991 RES: 0.0072142
ELA: 12.344 Jacobi stage: ITER: 30207 RES: 0.0069788
ELA: 12.444 Jacobi stage: ITER: 30455 RES: 0.006718
ELA: 12.544 Jacobi stage: ITER: 30695 RES: 0.0064748
ELA: 12.645 Jacobi stage: ITER: 30927 RES: 0.0062481
ELA: 12.745 Jacobi stage: ITER: 31171 RES: 0.0060183
ELA: 12.845 Jacobi stage: ITER: 31405 RES: 0.005804
ELA: 12.945 Jacobi stage: ITER: 31653 RES: 0.0055871
ELA: 13.045 Jacobi stage: ITER: 31897 RES: 0.0053816
ELA: 13.145 Jacobi stage: ITER: 32127 RES: 0.0051964
ELA: 13.245 Jacobi stage: ITER: 32373 RES: 0.0050022
ELA: 13.345 Jacobi stage: ITER: 32599 RES: 0.004833
ELA: 13.445 Jacobi stage: ITER: 32837 RES: 0.0046581
ELA: 13.546 Jacobi stage: ITER: 33081 RES: 0.0044867
ELA: 13.646 Jacobi stage: ITER: 33419 RES: 0.004261
ELA: 13.746 Jacobi stage: ITER: 33663 RES: 0.0041043
ELA: 13.846 Jacobi stage: ITER: 33877 RES: 0.0039703
ELA: 13.946 Jacobi stage: ITER: 34125 RES: 0.0038219
ELA: 14.046 Jacobi stage: ITER: 34371 RES: 0.0036814
ELA: 14.146 Jacobi stage: ITER: 34623 RES: 0.0035416
ELA: 14.246 Jacobi stage: ITER: 34859 RES: 0.0034155
ELA: 14.346 Jacobi stage: ITER: 35101 RES: 0.0032899
ELA: 14.447 Jacobi stage: ITER: 35339 RES: 0.0031727
ELA: 14.547 Jacobi stage: ITER: 35555 RES: 0.0030692
ELA: 14.647 Jacobi stage: ITER: 35803 RES: 0.0029545
ELA: 14.747 Jacobi stage: ITER: 36079 RES: 0.0028318
ELA: 14.847 Jacobi stage: ITER: 36331 RES: 0.0027243
ELA: 14.947 Jacobi stage: ITER: 36563 RES: 0.002629
ELA: 15.047 Jacobi stage: ITER: 36795 RES: 0.0025369
ELA: 15.147 Jacobi stage: ITER: 37005 RES: 0.0024556
ELA: 15.247 Jacobi stage: ITER: 37253 RES: 0.0023639
ELA: 15.348 Jacobi stage: ITER: 37479 RES: 0.0022839
ELA: 15.448 Jacobi stage: ITER: 37727 RES: 0.0021985
ELA: 15.548 Jacobi stage: ITER: 37995 RES: 0.0021099
ELA: 15.648 Jacobi stage: ITER: 38247 RES: 0.0020298
ELA: 15.748 Jacobi stage: ITER: 38497 RES: 0.0019527
ELA: 15.848 Jacobi stage: ITER: 38747 RES: 0.0018797
ELA: 15.948 Jacobi stage: ITER: 38999 RES: 0.0018083
ELA: 16.048 Jacobi stage: ITER: 39249 RES: 0.0017397
ELA: 16.148 Jacobi stage: ITER: 39499 RES: 0.0016747
ELA: 16.249 Jacobi stage: ITER: 39751 RES: 0.0016111
ELA: 16.349 Jacobi stage: ITER: 40001 RES: 0.0015499
ELA: 16.449 Jacobi stage: ITER: 40251 RES: 0.001492
ELA: 16.549 Jacobi stage: ITER: 40503 RES: 0.0014353
ELA: 16.649 Jacobi stage: ITER: 40753 RES: 0.0013808
ELA: 16.749 Jacobi stage: ITER: 41003 RES: 0.0013292
ELA: 16.849 Jacobi stage: ITER: 41255 RES: 0.0012788
ELA: 16.949 Jacobi stage: ITER: 41503 RES: 0.001231
ELA: 17.05 Jacobi stage: ITER: 41755 RES: 0.0011842
ELA: 17.15 Jacobi stage: ITER: 42005 RES: 0.0011393
ELA: 17.25 Jacobi stage: ITER: 42255 RES: 0.0010967
ELA: 17.35 Jacobi stage: ITER: 42507 RES: 0.001055
ELA: 17.45 Jacobi stage: ITER: 42757 RES: 0.001015
ELA: 17.55 Jacobi stage: ITER: 43007 RES: 0.00097704
ELA: 17.65 Jacobi stage: ITER: 43259 RES: 0.00093995
ELA: 17.75 Jacobi stage: ITER: 43509 RES: 0.00090426
ELA: 17.851 Jacobi stage: ITER: 43759 RES: 0.00087046
ELA: 17.951 Jacobi stage: ITER: 44011 RES: 0.00083741
ELA: 18.051 Jacobi stage: ITER: 44261 RES: 0.00080562
ELA: 18.151 Jacobi stage: ITER: 44511 RES: 0.00077551
ELA: 18.251 Jacobi stage: ITER: 44763 RES: 0.00074606
ELA: 18.351 Jacobi stage: ITER: 45013 RES: 0.00071773
ELA: 18.451 Jacobi stage: ITER: 45263 RES: 0.00069091
ELA: 18.551 Jacobi stage: ITER: 45515 RES: 0.00066468
ELA: 18.652 Jacobi stage: ITER: 45765 RES: 0.00063944
ELA: 18.752 Jacobi stage: ITER: 46015 RES: 0.00061554
ELA: 18.852 Jacobi stage: ITER: 46267 RES: 0.00059217
ELA: 18.952 Jacobi stage: ITER: 46517 RES: 0.00056968
ELA: 19.052 Jacobi stage: ITER: 46767 RES: 0.00054839
ELA: 19.152 Jacobi stage: ITER: 47019 RES: 0.00052757
ELA: 19.252 Jacobi stage: ITER: 47269 RES: 0.00050754
ELA: 19.352 Jacobi stage: ITER: 47519 RES: 0.00048857
ELA: 19.452 Jacobi stage: ITER: 47771 RES: 0.00047002
ELA: 19.553 Jacobi stage: ITER: 48021 RES: 0.00045217
ELA: 19.653 Jacobi stage: ITER: 48271 RES: 0.00043527
ELA: 19.753 Jacobi stage: ITER: 48523 RES: 0.00041875
ELA: 19.853 Jacobi stage: ITER: 48773 RES: 0.00040285
ELA: 19.953 Jacobi stage: ITER: 49023 RES: 0.00038779
ELA: 20.053 Jacobi stage: ITER: 49273 RES: 0.00037307
ELA: 20.153 Jacobi stage: ITER: 49523 RES: 0.00035912
ELA: 20.253 Jacobi stage: ITER: 49775 RES: 0.00034549
ELA: 20.353 Jacobi stage: ITER: 50025 RES: 0.00033237
ELA: 20.454 Jacobi stage: ITER: 50275 RES: 0.00031995
ELA: 20.554 Jacobi stage: ITER: 50527 RES: 0.0003078
ELA: 20.654 Jacobi stage: ITER: 50777 RES: 0.00029611
ELA: 20.754 Jacobi stage: ITER: 51027 RES: 0.00028504
ELA: 20.854 Jacobi stage: ITER: 51279 RES: 0.00027422
ELA: 20.954 Jacobi stage: ITER: 51529 RES: 0.00026381
ELA: 21.054 Jacobi stage: ITER: 51779 RES: 0.00025395
ELA: 21.154 Jacobi stage: ITER: 52031 RES: 0.00024431
ELA: 21.254 Jacobi stage: ITER: 52281 RES: 0.00023503
ELA: 21.354 Jacobi stage: ITER: 52531 RES: 0.00022625
ELA: 21.455 Jacobi stage: ITER: 52781 RES: 0.00021766
ELA: 21.555 Jacobi stage: ITER: 53031 RES: 0.00020952
ELA: 21.655 Jacobi stage: ITER: 53283 RES: 0.00020157
ELA: 21.755 Jacobi stage: ITER: 53533 RES: 0.00019391
ELA: 21.855 Jacobi stage: ITER: 53783 RES: 0.00018667
ELA: 21.955 Jacobi stage: ITER: 54035 RES: 0.00017958
ELA: 22.055 Jacobi stage: ITER: 54285 RES: 0.00017276
ELA: 22.155 Jacobi stage: ITER: 54535 RES: 0.0001663
ELA: 22.255 Jacobi stage: ITER: 54785 RES: 0.00015999
ELA: 22.356 Jacobi stage: ITER: 55035 RES: 0.00015401
ELA: 22.456 Jacobi stage: ITER: 55287 RES: 0.00014816
ELA: 22.556 Jacobi stage: ITER: 55537 RES: 0.00014254
ELA: 22.656 Jacobi stage: ITER: 55787 RES: 0.00013721
ELA: 22.756 Jacobi stage: ITER: 56039 RES: 0.000132
ELA: 22.856 Jacobi stage: ITER: 56289 RES: 0.00012699
ELA: 22.956 Jacobi stage: ITER: 56539 RES: 0.00012224
ELA: 23.056 Jacobi stage: ITER: 56789 RES: 0.0001176
ELA: 23.156 Jacobi stage: ITER: 57039 RES: 0.0001132
ELA: 23.257 Jacobi stage: ITER: 57291 RES: 0.00010891
ELA: 23.357 Jacobi stage: ITER: 57541 RES: 0.00010477
ELA: 23.457 Jacobi stage: ITER: 57791 RES: 0.00010086
ELA: 23.557 Jacobi stage: ITER: 58043 RES: 9.7026e-05
ELA: 23.657 Jacobi stage: ITER: 58291 RES: 9.3399e-05
ELA: 23.757 Jacobi stage: ITER: 58543 RES: 8.9853e-05
ELA: 23.857 Jacobi stage: ITER: 58793 RES: 8.6442e-05
ELA: 23.957 Jacobi stage: ITER: 59043 RES: 8.3211e-05
ELA: 24.058 Jacobi stage: ITER: 59295 RES: 8.0051e-05
ELA: 24.158 Jacobi stage: ITER: 59545 RES: 7.7012e-05
ELA: 24.419 Jacobi stage: ITER: 60199 RES: 6.9673e-05
ELA: 24.519 Jacobi stage: ITER: 60449 RES: 6.7028e-05
ELA: 24.619 Jacobi stage: ITER: 60699 RES: 6.4522e-05
ELA: 24.719 Jacobi stage: ITER: 60949 RES: 6.2073e-05
ELA: 24.819 Jacobi stage: ITER: 61199 RES: 5.9752e-05
ELA: 24.919 Jacobi stage: ITER: 61451 RES: 5.7484e-05
ELA: 25.019 Jacobi stage: ITER: 61701 RES: 5.5301e-05
ELA: 25.119 Jacobi stage: ITER: 61951 RES: 5.3234e-05
ELA: 25.22 Jacobi stage: ITER: 62203 RES: 5.1213e-05
ELA: 25.32 Jacobi stage: ITER: 62453 RES: 4.9269e-05
ELA: 25.42 Jacobi stage: ITER: 62703 RES: 4.7427e-05
ELA: 25.52 Jacobi stage: ITER: 62953 RES: 4.5626e-05
ELA: 25.62 Jacobi stage: ITER: 63203 RES: 4.3921e-05
ELA: 25.72 Jacobi stage: ITER: 63455 RES: 4.2253e-05
ELA: 25.82 Jacobi stage: ITER: 63705 RES: 4.0649e-05
ELA: 25.92 Jacobi stage: ITER: 63955 RES: 3.913e-05
ELA: 26.02 Jacobi stage: ITER: 64207 RES: 3.7644e-05
ELA: 26.121 Jacobi stage: ITER: 64457 RES: 3.6215e-05
ELA: 26.221 Jacobi stage: ITER: 64707 RES: 3.4861e-05
ELA: 26.321 Jacobi stage: ITER: 64957 RES: 3.3538e-05
ELA: 26.421 Jacobi stage: ITER: 65207 RES: 3.2284e-05
ELA: 26.521 Jacobi stage: ITER: 65459 RES: 3.1058e-05
ELA: 26.621 Jacobi stage: ITER: 65709 RES: 2.9879e-05
ELA: 26.721 Jacobi stage: ITER: 65959 RES: 2.8762e-05
ELA: 26.821 Jacobi stage: ITER: 66211 RES: 2.767e-05
ELA: 26.921 Jacobi stage: ITER: 66461 RES: 2.662e-05
ELA: 27.022 Jacobi stage: ITER: 66711 RES: 2.5625e-05
ELA: 27.122 Jacobi stage: ITER: 66963 RES: 2.4652e-05
ELA: 27.222 Jacobi stage: ITER: 67215 RES: 2.3716e-05
ELA: 27.322 Jacobi stage: ITER: 67465 RES: 2.2815e-05
ELA: 27.422 Jacobi stage: ITER: 67715 RES: 2.1963e-05
ELA: 27.522 Jacobi stage: ITER: 67967 RES: 2.1129e-05
ELA: 27.622 Jacobi stage: ITER: 68217 RES: 2.0327e-05
ELA: 27.722 Jacobi stage: ITER: 68467 RES: 1.9567e-05
ELA: 27.822 Jacobi stage: ITER: 68719 RES: 1.8824e-05
ELA: 27.923 Jacobi stage: ITER: 68969 RES: 1.8109e-05
ELA: 28.023 Jacobi stage: ITER: 69219 RES: 1.7432e-05
ELA: 28.123 Jacobi stage: ITER: 69471 RES: 1.677e-05
ELA: 28.223 Jacobi stage: ITER: 69721 RES: 1.6134e-05
ELA: 28.323 Jacobi stage: ITER: 69971 RES: 1.5531e-05
ELA: 28.423 Jacobi stage: ITER: 70223 RES: 1.4941e-05
ELA: 28.523 Jacobi stage: ITER: 70473 RES: 1.4374e-05
ELA: 28.623 Jacobi stage: ITER: 70723 RES: 1.3836e-05
ELA: 28.724 Jacobi stage: ITER: 70973 RES: 1.3311e-05
ELA: 28.824 Jacobi stage: ITER: 71223 RES: 1.2814e-05
ELA: 28.924 Jacobi stage: ITER: 71475 RES: 1.2327e-05
ELA: 29.024 Jacobi stage: ITER: 71725 RES: 1.1859e-05
ELA: 29.124 Jacobi stage: ITER: 71975 RES: 1.1416e-05
ELA: 29.224 Jacobi stage: ITER: 72227 RES: 1.0982e-05
ELA: 29.324 Jacobi stage: ITER: 72477 RES: 1.0565e-05
ELA: 29.424 Jacobi stage: ITER: 72727 RES: 1.017e-05
ELA: 29.524 Jacobi stage: ITER: 72979 RES: 9.7843e-06
ELA: 29.625 Jacobi stage: ITER: 73229 RES: 9.4129e-06
ELA: 29.725 Jacobi stage: ITER: 73479 RES: 9.061e-06
ELA: 29.825 Jacobi stage: ITER: 73729 RES: 8.717e-06
ELA: 29.925 Jacobi stage: ITER: 73979 RES: 8.3912e-06
ELA: 30.025 Jacobi stage: ITER: 74231 RES: 8.0726e-06
ELA: 30.125 Jacobi stage: ITER: 74481 RES: 7.7661e-06
ELA: 30.225 Jacobi stage: ITER: 74731 RES: 7.4758e-06
ELA: 30.325 Jacobi stage: ITER: 74983 RES: 7.192e-06
ELA: 30.425 Jacobi stage: ITER: 75231 RES: 6.9232e-06
ELA: 30.526 Jacobi stage: ITER: 75483 RES: 6.6603e-06
ELA: 30.626 Jacobi stage: ITER: 75733 RES: 6.4074e-06
ELA: 30.726 Jacobi stage: ITER: 75983 RES: 6.1679e-06
ELA: 30.826 Jacobi stage: ITER: 76235 RES: 5.9338e-06
ELA: 30.926 Jacobi stage: ITER: 76483 RES: 5.7085e-06
ELA: 31.026 Jacobi stage: ITER: 76735 RES: 5.4951e-06
ELA: 31.126 Jacobi stage: ITER: 76985 RES: 5.2865e-06
ELA: 31.226 Jacobi stage: ITER: 77235 RES: 5.0889e-06
ELA: 31.326 Jacobi stage: ITER: 77487 RES: 4.8957e-06
ELA: 31.427 Jacobi stage: ITER: 77737 RES: 4.7098e-06
ELA: 31.527 Jacobi stage: ITER: 77987 RES: 4.5337e-06
ELA: 31.627 Jacobi stage: ITER: 78239 RES: 4.3616e-06
ELA: 31.727 Jacobi stage: ITER: 78489 RES: 4.196e-06
ELA: 31.827 Jacobi stage: ITER: 78739 RES: 4.0392e-06
ELA: 31.927 Jacobi stage: ITER: 78991 RES: 3.8858e-06
ELA: 32.027 Jacobi stage: ITER: 79239 RES: 3.7406e-06
ELA: 32.127 Jacobi stage: ITER: 79491 RES: 3.5985e-06
ELA: 32.227 Jacobi stage: ITER: 79741 RES: 3.4619e-06
ELA: 32.328 Jacobi stage: ITER: 79991 RES: 3.3325e-06
ELA: 32.428 Jacobi stage: ITER: 80243 RES: 3.206e-06
ELA: 32.528 Jacobi stage: ITER: 80493 RES: 3.0843e-06
ELA: 32.628 Jacobi stage: ITER: 80743 RES: 2.969e-06
ELA: 32.728 Jacobi stage: ITER: 80995 RES: 2.8563e-06
ELA: 32.828 Jacobi stage: ITER: 81243 RES: 2.7495e-06
ELA: 32.928 Jacobi stage: ITER: 81495 RES: 2.6451e-06
ELA: 33.028 Jacobi stage: ITER: 81745 RES: 2.5447e-06
ELA: 33.128 Jacobi stage: ITER: 81995 RES: 2.4496e-06
ELA: 33.229 Jacobi stage: ITER: 82247 RES: 2.3566e-06
ELA: 33.329 Jacobi stage: ITER: 82497 RES: 2.2671e-06
ELA: 33.429 Jacobi stage: ITER: 82747 RES: 2.1824e-06
ELA: 33.529 Jacobi stage: ITER: 82999 RES: 2.0995e-06
ELA: 33.629 Jacobi stage: ITER: 83249 RES: 2.0198e-06
ELA: 33.729 Jacobi stage: ITER: 83525 RES: 1.9359e-06
ELA: 33.829 Jacobi stage: ITER: 83903 RES: 1.8273e-06
ELA: 33.929 Jacobi stage: ITER: 84279 RES: 1.7248e-06
ELA: 34.03 Jacobi stage: ITER: 84657 RES: 1.627e-06
ELA: 34.13 Jacobi stage: ITER: 85035 RES: 1.5357e-06
ELA: 34.23 Jacobi stage: ITER: 85411 RES: 1.4495e-06
ELA: 34.33 Jacobi stage: ITER: 85789 RES: 1.3673e-06
ELA: 34.43 Jacobi stage: ITER: 86167 RES: 1.2906e-06
ELA: 34.53 Jacobi stage: ITER: 86545 RES: 1.2174e-06
ELA: 34.63 Jacobi stage: ITER: 86923 RES: 1.1491e-06
ELA: 34.73 Jacobi stage: ITER: 87299 RES: 1.0846e-06
ELA: 34.83 Jacobi stage: ITER: 87677 RES: 1.0231e-06
Vector x = [ 0.999999, 0.999999, 0.999998, 0.999999, 0.999999 ]
Setup with preconditioner
Preconditioners of iterative solvers can significantly improve the performance of the solver. In the case of the linear systems, they are used mainly with the Krylov subspace methods. Preconditioners cannot be used with the starionary methods (TNL::Solvers::Linear::Jacobi and TNL::Solvers::Linear::SOR). The following example shows how to setup an iterative solver of linear systems with preconditioning.
1#include <iostream>
2#include <memory>
3#include <TNL/Matrices/SparseMatrix.h>
4#include <TNL/Devices/Host.h>
5#include <TNL/Devices/Cuda.h>
6#include <TNL/Solvers/Linear/TFQMR.h>
7#include <TNL/Solvers/Linear/Preconditioners/Diagonal.h>
8
9template< typename Device >
10void
11iterativeLinearSolverExample()
12{
13
14
15
16
17
18
19
20
21
24 const int size( 5 );
26 matrix_ptr->setDimensions( size, size );
27 matrix_ptr->setRowCapacities( Vector( { 2, 3, 3, 3, 2 } ) );
28
30 {
31 const int rowIdx = row.getRowIndex();
32 if( rowIdx == 0 ) {
33 row.setElement( 0, rowIdx, 2.5 );
34 row.setElement( 1, rowIdx + 1, -1 );
35 }
36 else if( rowIdx == size - 1 ) {
37 row.setElement( 0, rowIdx - 1, -1.0 );
38 row.setElement( 1, rowIdx, 2.5 );
39 }
40 else {
41 row.setElement( 0, rowIdx - 1, -1.0 );
42 row.setElement( 1, rowIdx, 2.5 );
43 row.setElement( 2, rowIdx + 1, -1.0 );
44 }
45 };
46
47
48
49
50 matrix_ptr->forAllRows( f );
52
53
54
55
56 Vector x( size, 1.0 );
57 Vector b( size );
58 matrix_ptr->vectorProduct( x, b );
59 x = 0.0;
61
62
63
64
68 preconditioner_ptr->update( matrix_ptr );
69 LinearSolver solver;
70 solver.setMatrix( matrix_ptr );
71 solver.setPreconditioner( preconditioner_ptr );
72 solver.setConvergenceResidue( 1.0e-6 );
73 solver.solve( b, x );
75}
76
77int
78main( int argc, char* argv[] )
79{
80 std::cout <<
"Solving linear system on host:\n";
81 iterativeLinearSolverExample< TNL::Devices::Sequential >();
82
83#ifdef __CUDACC__
84 std::cout <<
"Solving linear system on CUDA device:\n";
85 iterativeLinearSolverExample< TNL::Devices::Cuda >();
86#endif
87}
Diagonal (Jacobi) preconditioner for iterative solvers of linear systems.
Definition Diagonal.h:21
In this example, we solve the same problem as in all other examples in this section. The only differences concerning the preconditioner happen in the solver setup. Similarly to the matrix of the linear system, the preconditioner needs to be passed to the solver as a std::shared_ptr. When the preconditioner object is created, we have to initialize it using the update method, which has to be called everytime the matrix of the linear system changes. This is important, for example, when solving time-dependent PDEs, but it does not happen in this example. Finally, we need to connect the solver with the preconditioner using the setPreconditioner method.
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 ]
Vector x = [ 1, 1, 1, 1, 1 ]
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 ]
Vector x = [ 1, 1, 1, 1, 1 ]
Choosing the solver and preconditioner type at runtime
When developing a numerical solver, one often has to search for a combination of various methods and algorithms that fit given requirements the best. To make this easier, TNL provides the functions TNL::Solvers::getLinearSolver and TNL::Solvers::getPreconditioner for selecting the linear solver and preconditioner at runtime. The following example shows how to use these functions:
1#include <iostream>
2#include <memory>
3#include <TNL/Matrices/SparseMatrix.h>
4#include <TNL/Devices/Host.h>
5#include <TNL/Devices/Cuda.h>
6#include <TNL/Solvers/LinearSolverTypeResolver.h>
7
8template< typename Device >
9void
10iterativeLinearSolverExample()
11{
12
13
14
15
16
17
18
19
20
23 const int size( 5 );
25 matrix_ptr->setDimensions( size, size );
26 matrix_ptr->setRowCapacities( Vector( { 2, 3, 3, 3, 2 } ) );
27
29 {
30 const int rowIdx = row.getRowIndex();
31 if( rowIdx == 0 ) {
32 row.setElement( 0, rowIdx, 2.5 );
33 row.setElement( 1, rowIdx + 1, -1 );
34 }
35 else if( rowIdx == size - 1 ) {
36 row.setElement( 0, rowIdx - 1, -1.0 );
37 row.setElement( 1, rowIdx, 2.5 );
38 }
39 else {
40 row.setElement( 0, rowIdx - 1, -1.0 );
41 row.setElement( 1, rowIdx, 2.5 );
42 row.setElement( 2, rowIdx + 1, -1.0 );
43 }
44 };
45
46
47
48
49 matrix_ptr->forAllRows( f );
51
52
53
54
55 Vector x( size, 1.0 );
56 Vector b( size );
57 matrix_ptr->vectorProduct( x, b );
58 x = 0.0;
60
61
62
63
66 preconditioner_ptr->update( matrix_ptr );
67 solver_ptr->setMatrix( matrix_ptr );
68 solver_ptr->setPreconditioner( preconditioner_ptr );
69 solver_ptr->setConvergenceResidue( 1.0e-6 );
70 solver_ptr->solve( b, x );
72}
73
74int
75main( int argc, char* argv[] )
76{
77 std::cout <<
"Solving linear system on host:\n";
78 iterativeLinearSolverExample< TNL::Devices::Sequential >();
79
80#ifdef __CUDACC__
81 std::cout <<
"Solving linear system on CUDA device:\n";
82 iterativeLinearSolverExample< TNL::Devices::Cuda >();
83#endif
84}
std::shared_ptr< Linear::Preconditioners::Preconditioner< MatrixType > > getPreconditioner(const std::string &name)
Function returning shared pointer with linear preconditioner given by its name in a form of a string.
Definition LinearSolverTypeResolver.h:144
std::shared_ptr< Linear::LinearSolver< MatrixType > > getLinearSolver(const std::string &name)
Function returning shared pointer with linear solver given by its name in a form of a string.
Definition LinearSolverTypeResolver.h:87
We still stay with the same problem and the only changes are in the solver setup. We first use TNL::Solvers::getLinearSolver to get a shared pointer holding the solver and then TNL::Solvers::getPreconditioner to get a shared pointer holding the preconditioner. The rest of the code is the same as in the previous examples with the only difference that we work with the pointer solver_ptr instead of the direct instance solver of the solver type.
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 ]
Vector x = [ 1, 1, 1, 1, 1 ]
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 ]
Vector x = [ 1, 1, 1, 1, 1 ]