23static double *
diag_precon(
const double *diag,
double *x,
double *y) {
27 for (i = 0; i < m; i++) y[i] = x[i]*diag[i];
32 int i, j, m =
A->m, *ia =
A->ia, *ja =
A->ja;
44 for (i = 0; i < m; i++){
46 for (j = ia[i]; j < ia[i+1]; j++){
47 if (i == ja[j] && fabs(a[j]) > 0) diag[i] = 1./a[j];
55 double *x,
double *rhs,
double tol,
58 double rho, rho_old = 1, res0, beta;
73 "on entry, cg iter = %d of %.0f, residual = %g, tol = %g\n",
78 while ((iter++) <
maxit && res >
tol*res0){
86 memcpy(p,
z,
sizeof(
double)*n);
102 _statistics[0] += iter - 1;
107 fprintf(stderr,
" cg iter = %d, residual = %g, relative res = %g\n", iter, res, res/res0);
114 double *x0,
double *rhs,
double tol,
double maxit) {
117 double *x =
gv_calloc(n,
sizeof(
double));
118 double *b =
gv_calloc(n,
sizeof(
double));
119 for (k = 0; k <
dim; k++){
120 for (i = 0; i < n; i++) {
126 for (i = 0; i < n; i++) {
void SparseMatrix_multiply_vector(SparseMatrix A, double *v, double **res)
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
double * vector_saxpy(int n, double *x, double *y, double beta)
double * vector_saxpy2(int n, double *x, double *y, double beta)
double vector_product(int n, double *x, double *y)
double * vector_subtract_to(int n, double *x, double *y)
static double conjugate_gradient(SparseMatrix A, const double *precon, int n, double *x, double *rhs, double tol, double maxit)
static double * diag_precon_new(SparseMatrix A)
static double cg(SparseMatrix A, const double *precond, int n, int dim, double *x0, double *rhs, double tol, double maxit)
double SparseMatrix_solve(SparseMatrix A, int dim, double *x0, double *rhs, double tol, double maxit)
static double * diag_precon(const double *diag, double *x, double *y)
graphs, nodes and edges info: Agraphinfo_t, Agnodeinfo_t and Agedgeinfo_t