|
◆ 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] | n | Dimension of the matrix. (n >= 0) (if n = 0, returns without computation) |
[in] | matvec | User 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] | psolve | User 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] | chkconv | User 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] | mode | The 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] | maxiter | Maximum number of iterations. (maxiter > 0) |
[out] | iter | Final number of iterations. |
[out] | res | Final residual norm. |
[in] | lwork | Size 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. |
|