Skip to content

Commit 53f0577

Browse files
committed
Make the PPCG search-direction restart deterministic
1 parent f38b5d2 commit 53f0577

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

source/source_hsolver/diago_ppcg.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,8 @@ double DiagoPPCG<T, Device>::diag(const HPsiFunc& hpsi_func,
10861086
SmallSubspace subspace;
10871087
bool use_p = false; // previous search direction becomes available after
10881088
// the first block update.
1089-
Real prev_res = std::numeric_limits<Real>::max(); // restart watchdog
1090-
int stall_streak = 0; // consecutive residual rises
1089+
Real best_res = std::numeric_limits<Real>::max(); // best residual seen
1090+
int no_improve = 0; // iterations since the residual last decreased
10911091

10921092
while (!active_cols.empty() && iter <= maxiter_)
10931093
{
@@ -1176,26 +1176,24 @@ double DiagoPPCG<T, Device>::diag(const HPsiFunc& hpsi_func,
11761176
ld_psi_,
11771177
n_dim_,
11781178
ncol);
1179-
const Real rel_tol = std::max(Real(1e-12),
1180-
Real(1e2) * std::numeric_limits<Real>::epsilon());
1181-
const bool rising = cur_res > prev_res * (Real(1) + rel_tol);
1182-
if (rising)
1179+
if (cur_res < best_res)
11831180
{
1184-
++stall_streak;
1181+
best_res = cur_res;
1182+
no_improve = 0;
11851183
}
11861184
else
11871185
{
1188-
stall_streak = 0;
1186+
++no_improve;
11891187
}
1190-
if (stall_streak >= 3)
1188+
if (no_improve >= 15)
11911189
{
11921190
std::fill(p_.begin(), p_.end(), T(0));
11931191
std::fill(sp_.begin(), sp_.end(), T(0));
11941192
std::fill(hp_.begin(), hp_.end(), T(0));
11951193
use_p = false;
1196-
stall_streak = 0;
1194+
no_improve = 0;
1195+
best_res = cur_res;
11971196
}
1198-
prev_res = cur_res;
11991197
}
12001198
// The Rayleigh-Ritz rotation already keeps hpsi_/spsi_ consistent
12011199
// with the rotated psi up to rounding; re-applying H/S exactly is

0 commit comments

Comments
 (0)