From 9b733ec45cd93a80234a7c98248b6eb4816589d5 Mon Sep 17 00:00:00 2001 From: Edward Basso Date: Wed, 29 Nov 2023 17:43:44 -0600 Subject: [PATCH] solve_cg: avoid use of MF `z` (#3637) ## 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`. --- Src/LinearSolvers/MLMG/AMReX_MLCGSolver.H | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Src/LinearSolvers/MLMG/AMReX_MLCGSolver.H b/Src/LinearSolvers/MLMG/AMReX_MLCGSolver.H index 4768f06fc41..3afa56ee245 100644 --- a/Src/LinearSolvers/MLMG/AMReX_MLCGSolver.H +++ b/Src/LinearSolvers/MLMG/AMReX_MLCGSolver.H @@ -262,7 +262,6 @@ MLCGSolverT::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); @@ -295,9 +294,7 @@ MLCGSolverT::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 ) { @@ -305,12 +302,12 @@ MLCGSolverT::solve_cg (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs) } 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::BCMode::Homogeneous, MLLinOpT::StateMode::Correction);