31 double alpha, beta, r_r, r_r_new, p_Ap;
34 double *Ap =
gv_calloc(n,
sizeof(
double));
35 double *Ax =
gv_calloc(n,
sizeof(
double));
36 double *alphap =
gv_calloc(n,
sizeof(
double));
38 double *orth_b =
gv_calloc(n,
sizeof(
double));
47 for (i = 0; i < max_iterations &&
max_abs(n, r) >
tol; i++) {
59 if (i < max_iterations - 1) {
65 agerrorf(
"conjugate_gradient: unexpected length 0 vector\n");
93 (
float **
A,
double *x,
double *b,
int n,
double tol,
94 int max_iterations,
bool ortho1) {
100 double alpha, beta, r_r, r_r_new, p_Ap;
101 double *r =
gv_calloc(n,
sizeof(
double));
102 double *p =
gv_calloc(n,
sizeof(
double));
103 double *Ap =
gv_calloc(n,
sizeof(
double));
104 double *Ax =
gv_calloc(n,
sizeof(
double));
105 double *alphap =
gv_calloc(n,
sizeof(
double));
107 double *orth_b =
gv_calloc(n,
sizeof(
double));
118 for (i = 0; i < max_iterations &&
max_abs(n, r) >
tol; i++) {
130 if (i < max_iterations - 1) {
141 agerrorf(
"conjugate_gradient: unexpected length 0 vector\n");
144 beta = r_r_new / r_r;
163 double tol,
int max_iterations)
171 double alpha, beta, r_r, r_r_new, p_Ap;
191 for (i = 0; i < max_iterations &&
max_absf(n, r) >
tol; i++) {
209 if (i < max_iterations - 1) {
217 agerrorf(
"conjugate_gradient: unexpected length 0 vector\n");
220 beta = r_r_new / r_r;
223 for (
size_t j = 0; j < (size_t)n; ++j) {
224 p[j] = (float)beta * p[j] + r[j];
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
int conjugate_gradient(vtx_data *A, double *x, double *b, int n, double tol, int max_iterations)
int conjugate_gradient_mkernel(float *A, float *x, float *b, int n, double tol, int max_iterations)
int conjugate_gradient_f(float **A, double *x, double *b, int n, double tol, int max_iterations, bool ortho1)
void agerrorf(const char *fmt,...)
double vectors_inner_product(int n, const double *vector1, const double *vector2)
void orthog1f(int n, float *vec)
void right_mult_with_vector(vtx_data *matrix, int n, double *vector, double *result)
void copy_vector(int n, const double *restrict source, double *restrict dest)
void right_mult_with_vector_f(float **matrix, int n, double *vector, double *result)
double max_absf(int n, float *vector)
void orthog1(int n, double *vec)
void copy_vectorf(int n, float *source, float *dest)
void right_mult_with_vector_ff(float *packed_matrix, int n, float *vector, float *result)
void vectors_mult_additionf(int n, float *vector1, float alpha, float *vector2)
double max_abs(int n, double *vector)
void vectors_subtraction(int n, double *vector1, double *vector2, double *result)
void vectors_addition(int n, double *vector1, double *vector2, double *result)
void vectors_scalar_mult(int n, const double *vector, double alpha, double *result)
void vectors_subtractionf(int n, float *vector1, float *vector2, float *result)
double vectors_inner_productf(int n, float *vector1, float *vector2)
static void cleanup2(graph_t *g, int64_t nc)
static void cleanup1(graph_t *g)