Skip to content

Commit 175b99d

Browse files
authored
solve_bicgstab: cut use of s (#3629)
## Summary The MF named `s` seems to be an unnecessary usage of memory as the residue `r` can fulfill its roles in the algorithm. This PR replaces `s` with `r` and `LinComb` with `Saxpy` as appropriate. ## Additional background This PR is part of a larger request to improve `solve_bicgstab` and `solve_cg`.
1 parent d93f344 commit 175b99d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Src/LinearSolvers/MLMG/AMReX_MLCGSolver.H

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ MLCGSolverT<MF>::solve_bicgstab (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
9898
MF sorig = Lp.make(amrlev, mglev, nghost);
9999
MF p = Lp.make(amrlev, mglev, nghost);
100100
MF r = Lp.make(amrlev, mglev, nghost);
101-
MF s = Lp.make(amrlev, mglev, nghost);
102101
MF rh = Lp.make(amrlev, mglev, nghost);
103102
MF v = Lp.make(amrlev, mglev, nghost);
104103
MF t = Lp.make(amrlev, mglev, nghost);
@@ -166,9 +165,9 @@ MLCGSolverT<MF>::solve_bicgstab (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
166165
ret = 2; break;
167166
}
168167
MF::Saxpy(sol, alpha, ph, 0, 0, ncomp, nghost); // sol += alpha * ph
169-
MF::LinComb(s, RT(1.0), r, 0, -alpha, v, 0, 0, ncomp, nghost); // s = r - alpha * v
168+
MF::Saxpy(r, -alpha, v, 0, 0, ncomp, nghost); // r += -alpha * v
170169

171-
rnorm = norm_inf(s);
170+
rnorm = norm_inf(r);
172171

173172
if ( verbose > 2 && ParallelDescriptor::IOProcessor() )
174173
{
@@ -180,15 +179,15 @@ MLCGSolverT<MF>::solve_bicgstab (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
180179

181180
if ( rnorm < eps_rel*rnorm0 || rnorm < eps_abs ) { break; }
182181

183-
sh.LocalCopy(s,0,0,ncomp,nghost);
182+
sh.LocalCopy(r,0,0,ncomp,nghost);
184183
Lp.apply(amrlev, mglev, t, sh, MLLinOpT<MF>::BCMode::Homogeneous, MLLinOpT<MF>::StateMode::Correction);
185184
Lp.normalize(amrlev, mglev, t);
186185
//
187186
// This is a little funky. I want to elide one of the reductions
188187
// in the following two dotxy()s. We do that by calculating the "local"
189188
// values and then reducing the two local values at the same time.
190189
//
191-
RT tvals[2] = { dotxy(t,t,true), dotxy(t,s,true) };
190+
RT tvals[2] = { dotxy(t,t,true), dotxy(t,r,true) };
192191

193192
BL_PROFILE_VAR("MLCGSolver::ParallelAllReduce", blp_par);
194193
ParallelAllReduce::Sum(tvals,2,Lp.BottomCommunicator());
@@ -203,7 +202,7 @@ MLCGSolverT<MF>::solve_bicgstab (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
203202
ret = 3; break;
204203
}
205204
MF::Saxpy(sol, omega, sh, 0, 0, ncomp, nghost); // sol += omega * sh
206-
MF::LinComb(r, RT(1.0), s, 0, -omega, t, 0, 0, ncomp, nghost); // r = s - omega * t
205+
MF::Saxpy(r, -omega, t, 0, 0, ncomp, nghost); // r += -omega * t
207206

208207
rnorm = norm_inf(r);
209208

0 commit comments

Comments
 (0)