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

◆ cg1()

void cg1 ( char  uplo,
int  n,
const double  val[],
const int  rowptr[],
const int  colind[],
const double  b[],
double  x[],
double  tol,
int  maxiter,
int *  iter,
double *  res,
int  lwork,
double  work[],
int *  info 
)

Solution of linear system Ax = b using conjugate gradient (CG) method (Symmetric positive definite) (Simple driver)

Purpose
This routine solves the linear system Ax = b with symmetric positive definite coefficient matrix using the conjugate gradient (CG) method. Matrix A is represented in CSR format.
Parameters
[in]uploSpecifies whether the upper or lower triangular part of matrix A is stored.
= 'U': Upper triangular part is stored.
= 'L': Lower triangular part is stored.
= 'F': Full matrix (both upper and lower triangular parts) are stored.
[in]nDimension of the matrix. (n >= 0) (If n = 0, returns without computation)
[in]val[]Array val[lval] (lval >= nnz)
Values of nonzero elements of matrix A (where nnz is the number of nonzero elements).
[in]rowptr[]Array rowptr[lrowptr] (lrowptr >= n + 1)
Row pointers of matrix A.
[in]colind[]Array colind[lcolind] (lcolind >= nnz)
Column indices of matrix A (where nnz is the number of nonzero elements).
[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]tolTolerance for convergence test.
Assumed to be converged if norm(b - A*x) <= tol*norm(b).
If tol < eps (machine epsilon), tol = eps is assumed.
[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.