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

◆ z_cr()

void z_cr ( 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  mode,
int  maxiter,
int *  iter,
double *  res,
int  lwork,
doublecomplex  work[],
int *  info 
)

Solution of linear system Ax = b using conjugate residual (CR) method (Hermitian matrix)

Purpose
This routine solves the linear system Ax = b with Hermitian coefficient matrix using the conjugate residual (CR) 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[].
}
Note - Matrix M must be positive definite.
[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, 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]modeThe residual norm returned via parameters chkcnv and res can be specified.
= 0: norm(b - A*x) is returned. However, one additional matvec operation per one iteration is required.
= 1: M^(-1)*norm(b - A*x) is returned.
(For other values, mode = 0 is assumed.)
[in]maxiterMaximum number of iterations. (maxiter > 0)
[out]iterFinal number of iterations.
[out]resFinal residual norm.
[in]lworkSize of array work[]. (lwork >= 6*n)
[out]work[]Array work[lwork]
Work array.
[out]info= 0: Successful exit.
< 0: The (-info)-th argument is invalid.
= 2: (Warning) Preconditioner matrix M is not positive definite (computation continued).
= 11: Maximum number of iterations exceeded.
= 12: Matrix A is singular.