Skip to content

Commit

Permalink
Parallel CG.
Browse files Browse the repository at this point in the history
  • Loading branch information
anaegel committed Jun 26, 2024
1 parent 917e66b commit f5f52a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ugbase/lib_algebra/common/operations_vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ inline void VecLog(vector_t &dest, const vector_t &v)



//! We also provide this as a struct. This uses parallel execution.
//! We also provide this as a struct. This uses thread-parallel execution.
template<typename TVector>
struct vector_operations
{
Expand Down
10 changes: 9 additions & 1 deletion ugbase/lib_algebra/operator/linear_solver/cg.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,16 @@ class CG
// alpha = rho / (q,p)
const number alpha = rhoOld/lambda;

#ifndef UG_OPENMP
// Update x := x + alpha*p
VecScaleAdd(x, 1.0, x, alpha, p);

// Update r := r - alpha*t
VecScaleAdd(r, 1.0, r, -alpha, q);
#else
vector_operations<vector_type>::axpy(alpha, p, x);
vector_operations<vector_type>::axpy(-alpha, q,r);
#endif

write_debugXR(x, r, convergence_check()->step());

Expand Down Expand Up @@ -229,9 +234,12 @@ class CG

// new beta = rho / rhoOld
const number beta = rho/rhoOld;

#ifndef UG_OPENMP
// new direction p := beta * p + z
VecScaleAdd(p, beta, p, 1.0, z);
#else
vector_operations<vector_type>::vec_scale_add(p, beta, p, 1.0, z);
#endif

// remember old rho
rhoOld = rho;
Expand Down

0 comments on commit f5f52a9

Please sign in to comment.