Skip to content

Commit

Permalink
solve_cg: avoid use of MF z (AMReX-Codes#3637)
Browse files Browse the repository at this point in the history
## Summary

The method `solve_cg` is modified so that the MF `z` is no longer used,
thus saving on memory usage.

## Additional background

This is similar to the PR that changed `solve_bicgstab` that avoided use
of `s`.
  • Loading branch information
eebasso authored Nov 29, 2023
1 parent 0cd1385 commit 9b733ec
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Src/LinearSolvers/MLMG/AMReX_MLCGSolver.H
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ MLCGSolverT<MF>::solve_cg (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)

MF sorig = Lp.make(amrlev, mglev, nghost);
MF r = Lp.make(amrlev, mglev, nghost);
MF z = Lp.make(amrlev, mglev, nghost);
MF q = Lp.make(amrlev, mglev, nghost);

sorig.LocalCopy(sol,0,0,ncomp,nghost);
Expand Down Expand Up @@ -295,22 +294,20 @@ MLCGSolverT<MF>::solve_cg (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)

for (; iter <= maxiter; ++iter)
{
z.LocalCopy(r,0,0,ncomp,nghost);

RT rho = dotxy(z,r);
RT rho = dotxy(r,r);

if ( rho == 0 )
{
ret = 1; break;
}
if (iter == 1)
{
p.LocalCopy(z,0,0,ncomp,nghost);
p.LocalCopy(r,0,0,ncomp,nghost);
}
else
{
RT beta = rho/rho_1;
MF::Xpay(p, beta, z, 0, 0, ncomp, nghost); // p = z + beta * p
MF::Xpay(p, beta, r, 0, 0, ncomp, nghost); // p = r + beta * p
}
Lp.apply(amrlev, mglev, q, p, MLLinOpT<MF>::BCMode::Homogeneous, MLLinOpT<MF>::StateMode::Correction);

Expand Down

0 comments on commit 9b733ec

Please sign in to comment.