XLPack 7.0
XLPack Numerical Library (C API) Reference Manual
Loading...
Searching...
No Matches

◆ z_cg()

void z_cg ( int  n,
void(*)(int, const doublecomplex[], doublecomplex[])  matvec,
void(*)(int, const doublecomplex[], doublecomplex[])  psolve,
void(*)(int, const doublecomplex[], double, int, int *)  chkconv,
const doublecomplex  b[],
doublecomplex  x[],
int  maxiter,
int *  iter,
double *  res,
int  lwork,
doublecomplex  work[],
int *  info 
)

Solution of linear system Ax = b using conjugate gradient (CG) method (Hermitian positive definite matrices)

Purpose
This routine solves the linear system Ax = b with Hermitian positive definite coefficient matrix using the conjugate gradient (CG) method with preconditioning.
Parameters
[in]nDimension of the matrix. (n >= 0) (if n = 0, returns without computation)
[in]matvecUser supplied subroutine which calculates the matrix-vector product as follows.
void matvec(int n, const doublecomplex x[], doublecomplex y[])
{
Compute A*x, and return result in y[].
}
[in]psolveUser supplied subroutine which perform the preconditioner solve routine for the linear system M*x = b as follows, where M is a preconditioner metrix.
void psolve(int n, const doublecomplex b[], doublecomplex x[])
{
Solve M*x = b, and return solution in x[].
}
[in]chkconvUser supplied subroutine which is called on every iteration for the convergence test as follows, where x[] is the current approximate solution, res is the current residual norm norm(b - A*x), and iter is the current number of iterations. This routine can also be used to output the intermediate results.
void chkconv(int n, const doublecomplex x[], double res, int iter, int *ichk)
{
Set *ichk = 1 if converged. Otherwise, set *ichk = 0.
}
[in]b[]Array b[lb] (lb >= n)
Right hand side vector b.
[in,out]x[]Array x[lx] (lx >= n)
[in] Initial guess of solution.
[out] Obtained approximate solution.
[in]maxiterMaximum number of iterations. (maxiter > 0)
[out]iterFinal number of iterations.
[out]resFinal residual norm norm(b - A*x).
[in]lworkSize of array work[]. (lwork >= 5*n)
[out]work[]Array work[lwork]
Work array.
[out]info= 0: Successful exit.
< 0: The (-info)-th argument is invalid.
= 1: (Warning) Matrix A is not positive definite (computation continued).
= 2: (Warning) Preconditioner matrix M is not positive definite (computation continued).
= 11: Maximum number of iterations exceeded.
= 12: Matrix A is singular.