Skip to content

Commit d47d633

Browse files
Reduce PPCG subspace scaling overhead
1 parent 553d25e commit d47d633

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

source/source_hsolver/ppcg/diago_ppcg_subspace.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,19 @@ void DiagoPPCG<T, Device>::build_small_subspace(
9595
static_cast<Real>(1e-30)));
9696
// Only scale if the norm is non-negligible; a near-zero
9797
// column is a converged band whose contribution is harmless.
98-
if (sn > static_cast<Real>(1e-15)) {
99-
Real inv = static_cast<Real>(1) / sn;
98+
sn2_all[j] = (sn > static_cast<Real>(1e-15))
99+
? static_cast<double>(static_cast<Real>(1) / sn)
100+
: 1.0;
101+
}
100102
#ifdef _OPENMP
101-
#pragma omp parallel for schedule(static) if (n_dim_ > 4096)
103+
#pragma omp parallel for collapse(2) schedule(static) if (n_dim_ * lcols > 4096)
102104
#endif
103-
for (int ig = 0; ig < n_dim_; ++ig) {
104-
x[ idx(ig, j, ld_psi_)] *= inv;
105-
sx[idx(ig, j, ld_psi_)] *= inv;
106-
hx[idx(ig, j, ld_psi_)] *= inv;
107-
}
105+
for (int j = 0; j < lcols; ++j) {
106+
for (int ig = 0; ig < n_dim_; ++ig) {
107+
const Real scale = static_cast<Real>(sn2_all[j]);
108+
x[ idx(ig, j, ld_psi_)] *= scale;
109+
sx[idx(ig, j, ld_psi_)] *= scale;
110+
hx[idx(ig, j, ld_psi_)] *= scale;
108111
}
109112
}
110113
};

0 commit comments

Comments
 (0)