47 for (i = 0; i < m; i++) xsum += x[i];
49 for (i = 0; i < m; i++) y[i] += alpha*(m*x[i] - xsum);
95 for (i = 0; i < m; i++) y[i] = x[i]*diag[i];
103 int i, j, m = A->
m, *ia = A->
ia, *ja = A->
ja;
116 for (i = 0; i < m; i++){
118 for (j = ia[i]; j < ia[i+1]; j++){
119 if (i == ja[j] &&
ABS(a[j]) > 0) diag[i] = 1./((m-1)*alpha+a[j]);
132 int i, j, m = A->
m, *ia = A->
ia, *ja = A->
ja;
145 for (i = 0; i < m; i++){
147 for (j = ia[i]; j < ia[i+1]; j++){
148 if (i == ja[j] &&
ABS(a[j]) > 0) diag[i] = 1./a[j];
163 real *z, *r, *p, *q, res = 10*tol,
alpha;
164 real rho = 1.0e20, rho_old = 1, res0, beta;
180 fprintf(stderr,
"on entry, cg iter = %d of %d, residual = %g, tol = %g\n", iter, maxit, res, tol);
184 while ((iter++) < maxit && res > tol*res0){
185 z = Minvx(precon, r, z);
206 fprintf(stderr,
" cg iter = %d, residual = %g, relative res = %g\n", iter, res, res/res0);
216 _statistics[0] += iter - 1;
221 fprintf(stderr,
" cg iter = %d, residual = %g, relative res = %g\n", iter, res, res/res0);
228 real *x, *b, res = 0;
232 for (k = 0; k < dim; k++){
233 for (i = 0; i < n; i++) {
239 for (i = 0; i < n; i++) {
251 real *x, *y, *b, sum, diag, *a;
252 int k, i, j, n = A->
n, *ia, *ja, iter;
257 ia = A->
ia; ja = A->
ja; a = (
real*) A->
a;
259 for (k = 0; k < dim; k++){
260 for (i = 0; i < n; i++) {
265 for (iter = 0; iter < maxit; iter++){
266 for (i = 0; i < n; i++){
268 for (j = ia[i]; j < ia[i+1]; j++){
270 sum += a[j]*x[ja[j]];
275 if (sum == 0) fprintf(stderr,
"neighb=%d\n",ia[i+1]-ia[i]);
277 y[i] = (b[i] - sum)/diag;
283 for (i = 0; i < n; i++) {
306 res =
cg(Ax, precond, n, dim, x0, rhs, tol, maxit, flag);
311 jacobi(A, dim, x0, rhs, maxit, flag);
real * vector_saxpy(int n, real *x, real *y, real beta)
struct SparseMatrix_struct * SparseMatrix
real * vector_saxpy2(int n, real *x, real *y, real beta)
Operator Operator_diag_precon_new(SparseMatrix A)
real * vector_subtract_to(int n, real *x, real *y)
void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int transposed)
int conjugate_gradient(vtx_data *A, double *x, double *b, int n, double tol, int max_iterations)
void Operator_diag_precon_delete(Operator o)
real * Operator_diag_precon_apply(Operator o, real *x, real *y)
real * Operator_uniform_stress_matmul_apply(Operator o, real *x, real *y)
Operator Operator_matmul_new(SparseMatrix A)
real vector_product(int n, real *x, real *y)
Operator Operator_uniform_stress_diag_precon_new(SparseMatrix A, real alpha)
real * jacobi(SparseMatrix A, int dim, real *x0, real *rhs, int maxit, int *flag)
real cg(Operator Ax, Operator precond, int n, int dim, real *x0, real *rhs, real tol, int maxit, int *flag)
real SparseMatrix_solve(SparseMatrix A, int dim, real *x0, real *rhs, real tol, int maxit, int method, int *flag)
EXTERN unsigned char Verbose
Operator Operator_uniform_stress_matmul(SparseMatrix A, real alpha)
real *(* Operator_apply)(Operator o, real *in, real *out)
void Operator_uniform_stress_matmul_delete(Operator o)
real * Operator_matmul_apply(Operator o, real *x, real *y)
void Operator_matmul_delete(Operator o)