@@ -120,35 +120,54 @@ void DiagoPPCG<T, Device>::build_small_subspace(
120120 if (use_p)
121121 scale_to_unit_snorm (p_l, sp_l, hp_l, l, subspace.p_scale );
122122
123- auto fill_sym = [&](const std::vector<T>& a, const std::vector<T>& b,
124- int r0, int c0, std::vector<T>& mat)
123+ auto copy_block = [&](const std::vector<T>& src,
124+ const int col0,
125+ std::vector<T>& dst)
125126 {
126- std::vector<T> g;
127- gram (a.data (), b.data (), l, l, g, l);
127+ #ifdef _OPENMP
128+ #pragma omp parallel for schedule(static) if (ld_psi_ * l > 4096)
129+ #endif
128130 for (int j = 0 ; j < l; ++j)
129- for (int i = 0 ; i < l; ++i)
131+ std::copy (src.begin () + j * ld_psi_,
132+ src.begin () + (j + 1 ) * ld_psi_,
133+ dst.begin () + (col0 + j) * ld_psi_);
134+ };
135+
136+ auto hermitize = [&](std::vector<T>& mat)
137+ {
138+ for (int j = 0 ; j < dim; ++j)
139+ {
140+ mat[j + j * dim] = T (std::real (mat[j + j * dim]), 0 );
141+ for (int i = j + 1 ; i < dim; ++i)
130142 {
131- mat[(r0 + i) + (c0 + j) * dim] = g[i + j * l];
132- mat[(c0 + j) + (r0 + i) * dim] = std::conj (g[i + j * l]);
143+ const T avg = (mat[i + j * dim] + std::conj (mat[j + i * dim]))
144+ * static_cast <Real>(0.5 );
145+ mat[i + j * dim] = avg;
146+ mat[j + i * dim] = std::conj (avg);
133147 }
148+ }
134149 };
135150
136- fill_sym (psi_l, hpsi_l, 0 , 0 , subspace.k );
137- fill_sym (psi_l, spsi_l, 0 , 0 , subspace.m );
138- fill_sym (w_l, hw_l, l, l, subspace.k );
139- fill_sym (w_l, sw_l, l, l, subspace.m );
140- fill_sym (psi_l, hw_l, 0 , l, subspace.k );
141- fill_sym (psi_l, sw_l, 0 , l, subspace.m );
142-
151+ std::vector<T> basis (ld_psi_ * dim, T (0 ));
152+ std::vector<T> hbasis (ld_psi_ * dim, T (0 ));
153+ std::vector<T> sbasis (ld_psi_ * dim, T (0 ));
154+ copy_block (psi_l, 0 , basis);
155+ copy_block (hpsi_l, 0 , hbasis);
156+ copy_block (spsi_l, 0 , sbasis);
157+ copy_block (w_l, l, basis);
158+ copy_block (hw_l, l, hbasis);
159+ copy_block (sw_l, l, sbasis);
143160 if (use_p)
144161 {
145- fill_sym (p_l, hp_l, 2 *l, 2 *l, subspace.k );
146- fill_sym (p_l, sp_l, 2 *l, 2 *l, subspace.m );
147- fill_sym (psi_l, hp_l, 0 , 2 *l, subspace.k );
148- fill_sym (psi_l, sp_l, 0 , 2 *l, subspace.m );
149- fill_sym (w_l, hp_l, l, 2 *l, subspace.k );
150- fill_sym (w_l, sp_l, l, 2 *l, subspace.m );
162+ copy_block (p_l, 2 * l, basis);
163+ copy_block (hp_l, 2 * l, hbasis);
164+ copy_block (sp_l, 2 * l, sbasis);
151165 }
166+
167+ gram (basis.data (), hbasis.data (), dim, dim, subspace.k , dim);
168+ gram (basis.data (), sbasis.data (), dim, dim, subspace.m , dim);
169+ hermitize (subspace.k );
170+ hermitize (subspace.m );
152171}
153172
154173// ---------------------------------------------------------------------------
0 commit comments