31 int rows,
int maxit,
double err,
int prec,
int has_band,
34 int rows,
int maxit,
double err,
int has_band,
37 double *
b,
int rows,
int maxit,
double err);
69 return solver_pcg(A,
NULL,
x,
b, rows, maxit,
err, prec, 0, 0);
102 int bandwidth,
int maxit,
double err,
int prec)
104 G_fatal_error(
"Preconditioning of band matrics is not implemented yet");
105 return solver_pcg(A,
NULL,
x,
b, rows, maxit,
err, prec, 1, bandwidth);
134 int rows,
int maxit,
double err,
int prec)
137 return solver_pcg(
NULL, Asp,
x,
b, rows, maxit,
err, prec, 0, 0);
141 int rows,
int maxit,
double err,
int prec,
int has_band,
152 double a0 = 0, a1 = 0, mygamma, tmp = 0;
170 M = create_diag_precond_matrix(A, Asp, rows, prec);
189 #pragma omp for schedule(static) private(i) reduction(+ : s)
190 for (i = 0; i < rows; i++) {
201 for (m = 0; m < maxit; m++) {
202 #pragma omp parallel default(shared)
212 #pragma omp for schedule(static) private(i) reduction(+ : s)
213 for (i = 0; i < rows; i++) {
245 #pragma omp for schedule(static) private(i) reduction(+ : s)
246 for (i = 0; i < rows; i++) {
258 if (a1 < 0 || a1 == 0 || a1 > 0) {
262 G_warning(
_(
"Unable to solve the linear equation system"));
270 G_message(
_(
"Sparse PCG -- iteration %i error %g\n"), m, a0);
272 G_message(
_(
"PCG -- iteration %i error %g\n"), m, a0);
274 if (error_break == 1) {
322 return solver_cg(A,
NULL,
x,
b, rows, maxit,
err, 0, 0);
351 int bandwidth,
int maxit,
double err)
353 return solver_cg(A,
NULL,
x,
b, rows, maxit,
err, 1, bandwidth);
381 int rows,
int maxit,
double err)
383 return solver_cg(
NULL, Asp,
x,
b, rows, maxit,
err, 0, 0);
387 int maxit,
double err,
int has_band,
int bandwidth)
397 double a0 = 0, a1 = 0, mygamma, tmp = 0;
426 #pragma omp for schedule(static) private(i) reduction(+ : s)
427 for (i = 0; i < rows; i++) {
438 for (m = 0; m < maxit; m++) {
439 #pragma omp parallel default(shared)
449 #pragma omp for schedule(static) private(i) reduction(+ : s)
450 for (i = 0; i < rows; i++) {
479 #pragma omp for schedule(static) private(i) reduction(+ : s)
480 for (i = 0; i < rows; i++) {
492 if (a1 < 0 || a1 == 0 || a1 > 0) {
496 G_warning(
_(
"Unable to solve the linear equation system"));
504 G_message(
_(
"Sparse CG -- iteration %i error %g\n"), m, a0);
506 G_message(
_(
"CG -- iteration %i error %g\n"), m, a0);
508 if (error_break == 1) {
551 int maxit,
double err)
553 return solver_bicgstab(A,
NULL,
x,
b, rows, maxit,
err);
581 int rows,
int maxit,
double err)
583 return solver_bicgstab(
NULL, Asp,
x,
b, rows, maxit,
err);
587 int rows,
int maxit,
double err)
601 double s1 = 0.0, s2 = 0.0, s3 = 0.0;
603 double alpha = 0, beta = 0, omega, rr0 = 0, error;
637 for (m = 0; m < maxit; m++) {
639 #pragma omp parallel default(shared)
647 #pragma omp for schedule(static) private(i) reduction(+ : s1, s2, s3)
648 for (i = 0; i < rows; i++) {
658 if (error < 0 || error == 0 || error > 0) {
662 G_warning(
_(
"Unable to solve the linear equation system"));
678 #pragma omp for schedule(static) private(i) reduction(+ : s1, s2)
679 for (i = 0; i < rows; i++) {
694 #pragma omp for schedule(static) private(i) reduction(+ : s1)
695 for (i = 0; i < rows; i++) {
701 beta = alpha / omega * s1 / rr0;
710 G_message(
_(
"Sparse BiCGStab -- iteration %i error %g\n"), m,
713 G_message(
_(
"BiCGStab -- iteration %i error %g\n"), m, error);
715 if (error_break == 1) {
751 unsigned int i, j, cols = (
unsigned int)rows;
760 #pragma omp parallel for schedule(static) private(i, j, sum) \
761 shared(A, Msp, rows, cols, prec)
762 for (i = 0; i < (
unsigned int)rows; i++) {
768 for (j = 0; j < cols; j++)
769 sum += A[i][j] * A[i][j];
770 spvect->
values[0] = 1.0 / sqrt(sum);
774 for (j = 0; j < cols; j++)
775 sum += fabs(A[i][j]);
776 spvect->
values[0] = 1.0 / (sum);
780 spvect->
values[0] = 1.0 / A[i][i];
784 spvect->
index[0] = i;
791 #pragma omp parallel for schedule(static) private(i, j, sum) \
792 shared(Asp, Msp, rows, cols, prec)
793 for (i = 0; i < (
unsigned int)rows; i++) {
799 for (j = 0; j < Asp[i]->
cols; j++)
800 sum += Asp[i]->values[j] * Asp[i]->values[j];
801 spvect->
values[0] = 1.0 / sqrt(sum);
805 for (j = 0; j < Asp[i]->
cols; j++)
806 sum += fabs(Asp[i]->values[j]);
807 spvect->
values[0] = 1.0 / (sum);
811 for (j = 0; j < Asp[i]->
cols; j++)
812 if (i == Asp[i]->index[j])
817 spvect->
index[0] = i;
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
void G_message(const char *,...) __attribute__((format(printf
void G_math_d_ax_by(double *, double *, double *, double, double, int)
Scales vectors x and y with the scalars a and b and adds them.
void G_math_Ax_sband(double **A, double *x, double *y, int rows, int bandwidth)
Compute the matrix - vector product of symmetric band matrix A and vector x.
G_math_spvector * G_math_alloc_spvector(int)
Allocate memory for a sparse vector.
void G_math_free_spmatrix(G_math_spvector **, int)
Release the memory of the sparse matrix.
double * G_alloc_vector(size_t)
Vector matrix memory allocation.
void G_math_Ax_sparse(G_math_spvector **, double *, double *, int)
Compute the matrix - vector product of sparse matrix **Asp and vector x.
int G_math_add_spvector(G_math_spvector **, G_math_spvector *, int)
Adds a sparse vector to a sparse matrix at position row.
G_math_spvector ** G_math_alloc_spmatrix(int)
Allocate memory for a sparse matrix.
void G_math_d_Ax(double **, double *, double *, int, int)
Compute the matrix - vector product of matrix A and vector x.
void G_math_d_copy(double *, double *, int)
Copy the vector x to y.
#define G_MATH_ROWSCALE_ABSSUMNORM_PRECONDITION
#define G_MATH_ROWSCALE_EUKLIDNORM_PRECONDITION
#define G_MATH_DIAGONAL_PRECONDITION
#define assert(condition)
int G_math_solver_pcg(double **A, double *x, double *b, int rows, int maxit, double err, int prec)
The iterative preconditioned conjugate gradients solver for symmetric positive definite matrices.
int G_math_solver_cg(double **A, double *x, double *b, int rows, int maxit, double err)
The iterative conjugate gradients solver for symmetric positive definite matrices.
int G_math_solver_bicgstab(double **A, double *x, double *b, int rows, int maxit, double err)
The iterative biconjugate gradients solver with stabilization for unsymmetric non-definite matrices.
int G_math_solver_sparse_cg(G_math_spvector **Asp, double *x, double *b, int rows, int maxit, double err)
The iterative conjugate gradients solver for sparse symmetric positive definite matrices.
int G_math_solver_cg_sband(double **A, double *x, double *b, int rows, int bandwidth, int maxit, double err)
The iterative conjugate gradients solver for symmetric positive definite band matrices.
int G_math_solver_pcg_sband(double **A, double *x, double *b, int rows, int bandwidth, int maxit, double err, int prec)
The iterative preconditioned conjugate gradients solver for symmetric positive definite band matrices...
int G_math_solver_sparse_bicgstab(G_math_spvector **Asp, double *x, double *b, int rows, int maxit, double err)
The iterative biconjugate gradients solver with stabilization for unsymmetric non-definite matrices.
int G_math_solver_sparse_pcg(G_math_spvector **Asp, double *x, double *b, int rows, int maxit, double err, int prec)
The iterative preconditioned conjugate gradients solver for sparse symmetric positive definite matric...
The row vector of the sparse matrix.
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)