Skip to content

Commit 1cf0e11

Browse files
committed
Remove unused PPCG helper functions and constants
1 parent 0f72f2a commit 1cf0e11

2 files changed

Lines changed: 1 addition & 144 deletions

File tree

source/source_hsolver/diago_ppcg.cpp

Lines changed: 1 addition & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <ATen/kernels/lapack.h>
77
#include <stdexcept>
88
#include "source_base/kernels/math_kernel_op.h"
9-
#include <limits>
109
#include <cstdlib>
1110
#include <fstream>
1211
#include <numeric>
@@ -21,22 +20,9 @@ const double ppcg_preconditioner_threshold = 1.0e-12;
2120
const double ppcg_numerical_threshold = 1.0e-30;
2221
const double ppcg_scaling_threshold = 1.0e-15;
2322

24-
// Increasing diagonal shifts used to regularize an ill-conditioned Gram matrix
25-
// when a Cholesky factorization or a small projected generalized eigenproblem
26-
// fails numerically. The ladder is tried from no shift up to a unit shift.
27-
const double ppcg_cholesky_shifts[] = {0.0, 1.0e-12, 1.0e-10, 1.0e-8, 1.0e-6,
28-
1.0e-4, 1.0e-3, 1.0e-2, 1.0e-1, 1.0};
29-
// Subset of the shift ladder used by the small projected eigensolve fallback.
23+
// Diagonal shifts used by the small projected eigensolve fallback.
3024
const double ppcg_subspace_shifts[] = {0.0, 1.0e-10, 1.0e-8, 1.0e-6};
3125

32-
// Orthogonality check tolerance expressed as a multiple of machine epsilon.
33-
const double ppcg_orthogonality_tolerance_factor = 10.0;
34-
// Line-search root-selection tolerance expressed as a multiple of machine epsilon.
35-
const double ppcg_line_search_tolerance_factor = 100.0;
36-
// Quadratic-formula coefficients in the line-search root solve (b^2 - 4ac and 2a).
37-
const double ppcg_quadratic_discriminant_coefficient = 4.0;
38-
const double ppcg_quadratic_root_denominator_coefficient = 2.0;
39-
4026
} // namespace
4127
} // namespace hsolver
4228

@@ -141,43 +127,6 @@ struct HermitianLapack
141127
n, n, a, b, w, eigenvectors.data());
142128
std::copy(eigenvectors.begin(), eigenvectors.end(), a);
143129
}
144-
145-
static void potrf(int n, Scalar* a)
146-
{
147-
Real diag_max = 0;
148-
for (int i = 0; i < n; ++i)
149-
{
150-
diag_max = std::max(diag_max, std::abs(a[i + i * n]));
151-
}
152-
std::vector<Scalar> a0(a, a + n * n);
153-
154-
for (const double shift : ppcg_cholesky_shifts)
155-
{
156-
std::copy(a0.begin(), a0.end(), a);
157-
if (shift > 0.0)
158-
{
159-
for (int i = 0; i < n; ++i)
160-
{
161-
a[i + i * n] += Scalar(Real(shift) * std::max(diag_max, Real(1.0)), 0.0);
162-
}
163-
}
164-
try
165-
{
166-
container::kernels::lapack_potrf<Scalar, Device>()('U', n, a, n);
167-
return;
168-
}
169-
catch (const std::runtime_error&)
170-
{
171-
// Try the next diagonal shift.
172-
}
173-
}
174-
throw std::runtime_error("PPCG: potrf failed.");
175-
}
176-
177-
static void trtri(int n, Scalar* a)
178-
{
179-
container::kernels::lapack_trtri<Scalar, Device>()('U', 'N', n, a, n);
180-
}
181130
};
182131

183132
} // anonymous namespace
@@ -344,18 +293,6 @@ DiagoPPCG<T, Device>::gamma_dot(const T* x, const T* y) const
344293
return result;
345294
}
346295

347-
template <typename T, typename Device>
348-
T DiagoPPCG<T, Device>::complex_dot(const T* x, const T* y) const
349-
{
350-
T acc = T(0);
351-
for (int i = 0; i < n_dim_; ++i)
352-
{
353-
acc += std::conj(x[i]) * y[i];
354-
}
355-
reduce_pool_if_mpi_ready(&acc, 1);
356-
return acc;
357-
}
358-
359296
// =============================================================================
360297
// Gram matrix: out[i, j] = <a_i | b_j>
361298
// =============================================================================
@@ -859,81 +796,6 @@ void DiagoPPCG<T, Device>::update_one_block(
859796
scatter_cols(hpsi_.data(), cols, subspace.hpsi_new);
860797
}
861798

862-
} // namespace hsolver
863-
864-
865-
namespace hsolver {
866-
867-
// ---------------------------------------------------------------------------
868-
// Check S-orthonormality of a column block.
869-
// ---------------------------------------------------------------------------
870-
template <typename T, typename Device>
871-
bool DiagoPPCG<T, Device>::is_s_orthonormal(
872-
const T* psi, const T* spsi, int ncol) const
873-
{
874-
const Real orth_tol = Real(ppcg_orthogonality_tolerance_factor)
875-
* std::sqrt(std::numeric_limits<Real>::epsilon());
876-
std::vector<T> gram_s;
877-
gram(psi, spsi, ncol, ncol, gram_s, ncol);
878-
for (int j = 0; j < ncol; ++j)
879-
{
880-
for (int i = 0; i < ncol; ++i)
881-
{
882-
const T sij = gram_s[i + j * ncol];
883-
const T target = (i == j) ? T(1) : T(0);
884-
if (std::abs(sij - target) > orth_tol)
885-
{
886-
return false;
887-
}
888-
}
889-
}
890-
return true;
891-
}
892-
893-
// ---------------------------------------------------------------------------
894-
// Iterative S-Gram-Schmidt fallback with one reorthogonalization pass.
895-
// ---------------------------------------------------------------------------
896-
template <typename T, typename Device>
897-
void DiagoPPCG<T, Device>::s_gram_schmidt(
898-
T* psi, T* hpsi, T* spsi, int ncol) const
899-
{
900-
for (int j = 0; j < ncol; ++j)
901-
{
902-
for (int pass = 0; pass < 2; ++pass)
903-
{
904-
apply_s_current(psi + j * ld_psi_, spsi + j * ld_psi_, 1);
905-
for (int k = 0; k < j; ++k)
906-
{
907-
T coeff = complex_dot(psi + k * ld_psi_,
908-
spsi + j * ld_psi_);
909-
#ifdef _OPENMP
910-
#pragma omp parallel for schedule(static) if (n_dim_ > ppcg_openmp_work_threshold)
911-
#endif
912-
for (int ig = 0; ig < n_dim_; ++ig)
913-
{
914-
psi [idx(ig, j, ld_psi_)] -= coeff * psi [idx(ig, k, ld_psi_)];
915-
hpsi[idx(ig, j, ld_psi_)] -= coeff * hpsi[idx(ig, k, ld_psi_)];
916-
spsi[idx(ig, j, ld_psi_)] -= coeff * spsi[idx(ig, k, ld_psi_)];
917-
}
918-
}
919-
}
920-
apply_s_current(psi + j * ld_psi_, spsi + j * ld_psi_, 1);
921-
Real nrm = std::sqrt(std::max(
922-
gamma_dot(psi + j * ld_psi_, spsi + j * ld_psi_),
923-
Real(ppcg_numerical_threshold)));
924-
Real inv_nrm = Real(1) / nrm;
925-
#ifdef _OPENMP
926-
#pragma omp parallel for schedule(static) if (n_dim_ > ppcg_openmp_work_threshold)
927-
#endif
928-
for (int ig = 0; ig < n_dim_; ++ig)
929-
{
930-
psi [idx(ig, j, ld_psi_)] *= inv_nrm;
931-
hpsi[idx(ig, j, ld_psi_)] *= inv_nrm;
932-
spsi[idx(ig, j, ld_psi_)] *= inv_nrm;
933-
}
934-
}
935-
}
936-
937799
// ---------------------------------------------------------------------------
938800
// Rayleigh-Ritz: full subspace diagonalization + residual computation
939801
// ---------------------------------------------------------------------------

source/source_hsolver/diago_ppcg.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class DiagoPPCG
115115

116116
// Inner product <x|y> (real part only).
117117
Real gamma_dot(const T* x, const T* y) const;
118-
T complex_dot(const T* x, const T* y) const;
119118

120119
// Gram matrix: out[i, j] = <a_i | b_j>.
121120
void gram(const T* mat_a, const T* mat_b,
@@ -178,10 +177,6 @@ class DiagoPPCG
178177
int l,
179178
SmallSubspace& subspace);
180179

181-
bool is_s_orthonormal(const T* psi, const T* spsi, int ncol) const;
182-
183-
void s_gram_schmidt(T* psi, T* hpsi, T* spsi, int ncol) const;
184-
185180
void rayleigh_ritz(T* psi, Real* eigenvalue,
186181
std::vector<int>& active_cols,
187182
const std::vector<double>& ethr_band);

0 commit comments

Comments
 (0)