Skip to content

Commit 553d25e

Browse files
Tighten PPCG OpenMP updates
1 parent b2ae9f7 commit 553d25e

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

source/source_hsolver/ppcg/diago_ppcg_cg.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ void DiagoPPCG<T, Device>::update_polak_ribiere(
119119

120120
for (int j = 0; j < n_band_; ++j)
121121
{
122-
T* pj = p.data() + j * ld_psi_;
123-
T* zn = z_new.data() + j * ld_psi_;
124122
const Real beta_num_zr = static_cast<Real>(beta_nums[j]);
125123
const Real beta_num_zo = static_cast<Real>(beta_nums[n_band_ + j]);
126124
Real beta = 0;
@@ -131,16 +129,23 @@ void DiagoPPCG<T, Device>::update_polak_ribiere(
131129
if (beta < 0)
132130
beta = 0;
133131
}
132+
beta_nums[j] = static_cast<double>(beta);
134133

135-
// d_new = z_new + beta * d_old
134+
// Save <z_new, r_new> as denominator for next iteration.
135+
beta_denom[j] = beta_num_zr + static_cast<Real>(1.0e-30);
136+
}
137+
138+
// d_new = z_new + beta * d_old
136139
#ifdef _OPENMP
137-
#pragma omp parallel for schedule(static) if (n_dim_ > 4096)
140+
#pragma omp parallel for collapse(2) schedule(static) if (n_dim_ * n_band_ > 4096)
138141
#endif
142+
for (int j = 0; j < n_band_; ++j)
143+
{
139144
for (int ig = 0; ig < n_dim_; ++ig)
140-
pj[ig] = zn[ig] + beta * pj[ig];
141-
142-
// Save <z_new, r_new> as denominator for next iteration.
143-
beta_denom[j] = beta_num_zr + static_cast<Real>(1.0e-30);
145+
{
146+
const int off = idx(ig, j, ld_psi_);
147+
p[off] = z_new[off] + static_cast<Real>(beta_nums[j]) * p[off];
148+
}
144149
}
145150

146151
// Persist state for next iteration.

source/source_hsolver/ppcg/diago_ppcg_reduce.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ Real max_generalized_residual(
6868
template <typename T>
6969
inline void set_zero(std::vector<T>& x)
7070
{
71-
std::fill(x.begin(), x.end(), T(0));
71+
const int n = static_cast<int>(x.size());
72+
#ifdef _OPENMP
73+
#pragma omp parallel for schedule(static) if (n > 4096)
74+
#endif
75+
for (int i = 0; i < n; ++i)
76+
x[i] = T(0);
7277
}
7378

7479
} // anonymous namespace

0 commit comments

Comments
 (0)