@@ -80,6 +80,11 @@ double DiagoPPCG<T, Device>::diag(const HPsiFunc& hpsi_func,
8080 apply_s_current (psi_in, spsi_.data (), ncol);
8181 record_residual (0 , " initial_rr" );
8282
83+ std::vector<T> w_active;
84+ std::vector<T> hw_active;
85+ std::vector<int > cols;
86+ SmallSubspace subspace;
87+
8388 while (!active_cols.empty () && iter <= maxiter_)
8489 {
8590 const int nact = static_cast <int >(active_cols.size ());
@@ -91,10 +96,9 @@ double DiagoPPCG<T, Device>::diag(const HPsiFunc& hpsi_func,
9196 project_against (psi_in, spsi_.data (), all_cols, w_, sw_, active_cols);
9297
9398 // Apply H to the search direction.
94- std::vector<T> w_active;
9599 copy_cols (w_.data (), active_cols, w_active);
96100 force_g0_real (w_active.data (), nact);
97- std::vector<T> hw_active (ld_psi_ * nact, T (0 ));
101+ hw_active. assign (ld_psi_ * nact, T (0 ));
98102 scatter_cols (w_.data (), active_cols, w_active);
99103 apply_h (hpsi_func, w_active.data (), hw_active.data (), nact);
100104 scatter_cols (hw_.data (), active_cols, hw_active);
@@ -117,10 +121,9 @@ double DiagoPPCG<T, Device>::diag(const HPsiFunc& hpsi_func,
117121 {
118122 const int i0 = isb * sbsize_;
119123 const int l = std::min (sbsize_, nact - i0);
120- std::vector< int > cols (active_cols.begin () + i0,
121- active_cols.begin () + i0 + l);
124+ cols. assign (active_cols.begin () + i0,
125+ active_cols.begin () + i0 + l);
122126
123- SmallSubspace subspace;
124127 build_small_subspace (psi_in, cols, use_p_now, subspace);
125128 solve_small_generalized ((use_p_now ? 3 : 2 ) * l, subspace);
126129 update_one_block (psi_in, cols, l, use_p_now, subspace);
@@ -166,11 +169,13 @@ double DiagoPPCG<T, Device>::diag(const HPsiFunc& hpsi_func,
166169 update_polak_ribiere (grad, p, grad_old_, z_old_, beta_denom_, prec);
167170
168171 // CG iteration loop.
172+ std::vector<T> hp;
173+ std::vector<T> sp;
169174 while (iter <= maxiter_)
170175 {
171176 // Apply H and S to search direction.
172- std::vector<T> hp (ld_psi_ * ncol, T (0 ));
173- std::vector<T> sp (ld_psi_ * ncol, T (0 ));
177+ hp. assign (ld_psi_ * ncol, T (0 ));
178+ sp. assign (ld_psi_ * ncol, T (0 ));
174179 apply_h (hpsi_func, p.data (), hp.data (), ncol);
175180 apply_s_current (p.data (), sp.data (), ncol);
176181
0 commit comments