Sub Ex_Cg_Ssor_Ssc()
Const N = 3, Nnz = 6, Omega = 0.9, Tol = 0.0000000001 '1.0e-10
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 XX(N - 1) As Double, YY(N - 1) As Double
Dim Iter As Long, Res As Double, IRev As Long, Info As Long
A(0) = 2.2: A(1) = -0.11: A(2) = -0.32: A(3) = 2.93: A(4) = 0.81: A(5) = 2.37
Ia(0) = 0: Ia(1) = 3: Ia(2) = 5: Ia(3) = 6
Ja(0) = 0: Ja(1) = 1: Ja(2) = 2: Ja(3) = 1: Ja(4) = 2: Ja(5) = 2
B(0) = -1.566: B(1) = -2.8425: B(2) = -1.1765
Dim D(Nnz - 1) As Double
Call
CsxSsor(N, Omega, A(), Ia(), Ja(), D(), Info)
If Info <> 0 Then Debug.Print "Ssor Info =" + Str(Info)
IRev = 0
Do
Call
Cg_r(N, B(), X(), Info, XX(), YY(), IRev, Iter, Res)
If IRev = 1 Then '- Matvec
Call
SscDusmv("L", N, 1, A(), Ia(), Ja(), XX(), 0, YY())
ElseIf IRev = 3 Then '- Psolve
Call
SscSsorSolve("L", N, Omega, A(), Ia(), Ja(), D(), YY(), XX(), Info)
If Info <> 0 Then Debug.Print "SsorSolve Info =" + Str(Info)
ElseIf IRev = 10 Then '- Check convergence
If Res < Tol Then IRev = 11
End If
Loop While IRev <> 0
Debug.Print "X =", X(0), X(1), X(2)
Debug.Print "Iter = " + CStr(Iter) + ", Res = " + CStr(Res) + ", Info = " + CStr(Info)
End Sub
Sub SscDusmv(Uplo As String, N As Long, Alpha As Double, Val() As Double, Colptr() As Long, Rowind() As Long, X() As Double, Beta As Double, Y() As Double, Optional Info As Long, Optional Base As Long=-1, Optional IncX As Long=1, Optional IncY As Long=1)
y <- αAx + βy (CSC) (Symmetric matrix)
Sub CsxSsor(N As Long, Omega As Double, Val() As Double, Ptr() As Long, Ind() As Long, D() As Double, Optional Info As Long, Optional Base As Long=-1)
Initialize symmetric successive over-relaxation (SSOR) preconditioner (CSC/CSR)
Sub Cg_r(N As Long, B() As Double, X() As Double, Info As Long, XX() As Double, YY() As Double, IRev As Long, Optional Iter As Long, Optional Res As Double, Optional MaxIter As Long=500)
Solution of linear system Ax = b using conjugate gradient (CG) method (symmetric positive definite ma...
Sub SscSsorSolve(Uplo As String, N As Long, Omega As Double, Val() As Double, Colptr() As Long, Rowind() As Long, D() As Double, B() As Double, X() As Double, Optional Info As Long, Optional Base As Long=-1)
Symmetric successive over-relaxation (SSOR) preconditioner (Symmetric matrix) (CSC)