25static double *
diag_precon(
const double *diag,
double *x,
double *y) {
29 for (i = 0; i < m; i++) y[i] = x[i]*diag[i];
34 int i, j, m =
A->m, *ia =
A->ia, *ja =
A->ja;
41 double *data =
gv_calloc(
A->m + 1,
sizeof(
double));
46 for (i = 0; i < m; i++){
48 for (j = ia[i]; j < ia[i+1]; j++){
49 if (i == ja[j] && fabs(a[j]) > 0) diag[i] = 1./a[j];
57 double *x,
double *rhs,
double tol,
60 double rho, rho_old = 1, res0, beta;
75 "on entry, cg iter = %d of %.0f, residual = %g, tol = %g\n",
80 while ((iter++) <
maxit && res >
tol*res0){
88 memcpy(p,
z,
sizeof(
double)*n);
104 _statistics[0] += iter - 1;
109 fprintf(stderr,
" cg iter = %d, residual = %g, relative res = %g\n", iter, res, res/res0);
116 double *x0,
double *rhs,
double tol,
double maxit) {
119 double *x =
gv_calloc(n,
sizeof(
double));
120 double *b =
gv_calloc(n,
sizeof(
double));
121 for (k = 0; k <
dim; k++){
122 for (i = 0; i < n; i++) {
128 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