XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ Gcr()

Sub Gcr ( N As  Long,
Val() As  Double,
Ptr() As  Long,
Ind() As  Long,
B() As  Double,
X() As  Double,
Optional Info As  Long,
Optional Iter As  Long,
Optional Res As  Double,
Optional Format As  Long = 0,
Optional M As  Long = 0,
Optional MaxIter As  Long = 500,
Optional Tol As  Double = 1.0E-10,
Optional Base As  Long = -1,
Optional Precon As  Long = 0,
Optional Omega As  Double = 1.5,
Optional P As  Long = 3,
Optional Nnz2 As  Long = -1,
Optional Md As  Long = 0 
)

Solution of linear system Ax = b using generalized conjugate residual (GCR) method (driver)

Purpose
This routine solves the linear system Ax = b using the generalized conjugate residual (GCR) method with preconditioning. Matrix A is represented in CSR or CSC format.
Parameters
[in]NDimension of the matrix A. (N >= 0) (if N = 0, returns without computation)
[in]Val()Array Val(LVal - 1) (LVal >= Nnz) (Nnz is the number of nonzero elements of the matrix A)
Values of nonzero elements of the matrix A.
[in]Ptr()Array Ptr(LPtr - 1) (LPtr >= N + 1)
Column pointers (if CSC) or row pointers (if CSR) of the matrix A.
[in]Ind()Array Ind(LInd - 1) (LInd >= Nnz)
Row indices (if CSC) or column indices (if CSR) of the matrix A.
[in]B()Array B(LB - 1) (LB >= N)
Right hand side vector b.
[in,out]X()Array X(LX - 1) (LX >= N)
[in] Initial guess of solution.
[out] Obtained approximate solution.
[out]Info(Optional)
= 0: Successful exit
= i < 0: The (-i)-th argument is invalid.
= 11: Maximum number of iterations exceeded.
= 12: Breakdown occurred.
= 13: Error during initializing preconditioner.
= 14: Error during preconditioning.
[out]Iter(Optional)
Actual number of iterations performed for convergence.
[out]Res(Optional)
Final residual norm value norm(b - A*x).
[in]Format(Optional)
Sparse matrix format. (default = 0)
= 0: CSR format.
= 1: CSC format.
[in]M(Optional)
Restart parameter. (0 < M <= N) (default = min(64, N))
[in]MaxIter(Optional)
Maximum number of iterations. (MaxIter > 0) (default = 500)
[in]Tol(Optional)
Tolerance for convergence test. (default = 1.0e-10)
Assumed to be converged if norm(b - A*x) <= Tol*norm(b).
If Tol < eps (machine epsilon), Tol = eps is assumed.
[in]Base(Optional)
Indexing of Ptr() and Ind().
= 0: Zero-based (C style) indexing: Starting index is 0.
= 1: One-based (Fortran style) indexing: Starting index is 1.
(default: Assumes 1 if Ptr(0) = 1, 0 otherwise)
[in]Precon(Optional)
Specify preconditioner. (default = 0)
= 0: No preconditioner.
= 1: Diagonal scaling preconditioner.
= 2: SSOR preconditioner.
= 3: ILU(0) preconditioner.
= 4: ILU(p) preconditioner.
[in]Omega(Optional)
The relaxation parameter ω of SSOR preconditioner. (0 < ω < 2) (default = 1.5)
Not used if Precon <> 2.
[in]P(Optional)
The value of level p of ILU(p) algorithm. (P >= 0) (default = 3)
Not used if Precon <> 4.
[in]Nnz2(Optional)
Maximum number of non-zero elements of matrix L*U. If the number of non-zero elements exceeds this, the routine will be terminated with error (info = 13). (Nnz2 > 0) (default = P*Nnz)
Not used if Precon <> 4.
[in]Md(Optional)
Specify whether the diagonal compensation of the dropped elements are required. ILU with this compensation is called as MILU (modified ILU).
= 0: ILU (no compensation).
= 1: MILU (with diagonal compensation).
Not used if Precon <> 4 or Format <> 0.
Example Program
Solve the system of linear equations Ax = B, where
( 0.2 -0.11 -0.93 ) ( -0.3727 )
A = ( -0.32 0.81 0.37 ), B = ( 0.4319 )
( -0.8 -0.92 -0.29 ) ( -1.4247 )
Sub Ex_Gcr()
Const N = 3, Nnz = N * N
Dim A(Nnz - 1) As Double, Ia(N) As Long, Ja(Nnz - 1) As Long
Dim B(N - 1) As Double, X(N - 1) As Double
Dim Iter As Long, Res As Double, Info As Long
A(0) = 0.2: A(1) = -0.11: A(2) = -0.93: A(3) = -0.32: A(4) = 0.81: A(5) = 0.37: A(6) = -0.8: A(7) = -0.92: A(8) = -0.29
Ia(0) = 0: Ia(1) = 3: Ia(2) = 6: Ia(3) = 9
Ja(0) = 0: Ja(1) = 1: Ja(2) = 2: Ja(3) = 0: Ja(4) = 1: Ja(5) = 2: Ja(6) = 0: Ja(7) = 1: Ja(8) = 2
B(0) = -0.3727: B(1) = 0.4319: B(2) = -1.4247
Call Gcr(N, A(), Ia(), Ja(), B(), X(), Info, Iter, Res)
Debug.Print "X =", X(0), X(1), X(2)
Debug.Print "Iter = " + CStr(Iter) + ", Res = " + CStr(Res) + ", Info = " + CStr(Info)
End Sub
Sub Gcr(N As Long, Val() As Double, Ptr() As Long, Ind() As Long, B() As Double, X() As Double, Optional Info As Long, Optional Iter As Long, Optional Res As Double, Optional Format As Long=0, Optional M As Long=0, Optional MaxIter As Long=500, Optional Tol As Double=1.0E-10, Optional Base As Long=-1, Optional Precon As Long=0, Optional Omega As Double=1.5, Optional P As Long=3, Optional Nnz2 As Long=-1, Optional Md As Long=0)
Solution of linear system Ax = b using generalized conjugate residual (GCR) method (driver)
Example Results
X = 0.86 0.64 0.51
Iter = 3, Res = 1.94005292274303E-16, Info = 0