38template <
typename T = std::complex<
double>,
typename Device = base_device::DEVICE_CPU>
45 using Wide = std::complex<double>;
57 const int para_rr_method,
58 const int para_rr_block_size,
59 const bool use_overlap,
71 const double tolerance,
73 const std::vector<double>& ethr_band);
162 void form_residual(
const VectorImages& vectors,
const int count,
const Real* eigenvalues,
T* residual);
176 const int source_columns,
177 const int target_columns,
178 const T* coefficients,
179 const VectorImages& target,
181 int normalize_columns(
const VectorImages& block,
const int columns,
T* coefficients,
const int coefficient_rows);
185 template <
typename Value>
191 const VectorImages& basis,
const int columns,
const ProjectionCache* retained,
ct::Tensor& k,
ct::Tensor& g);
204 const Real* ritz_values,
205 const int zero_prefix,
206 ProjectionCache& cache);
210 const VectorImages& basis,
211 int& working_columns,
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
const T * prepare_rotation_coefficients(const ct::Tensor &coefficients)
Borrow host double coefficients on CPU, or convert/upload them into reusable algebra scratch.
Definition diago_lobpcg.cpp:659
copy_op copy_op_
Definition diago_lobpcg.h:153
dense::ParallelDenseEigensolver & rr_solver_
Definition diago_lobpcg.h:119
int n_band_
Definition diago_lobpcg.h:107
void form_projected_matrices(const VectorImages &basis, const int columns, const ProjectionCache *retained, ct::Tensor &k, ct::Tensor &g)
Form K = B^H H B and G = B^H S B; with a retained [X,P] block, compute only the new W panel.
Definition lobpcg_subspace.cpp:25
const LobpcgLocking locking_
Definition diago_lobpcg.h:118
const bool use_overlap_
Definition diago_lobpcg.h:117
axpy_op axpy_op_
Definition diago_lobpcg.h:154
ct::Tensor eig_
Definition diago_lobpcg.h:129
const T zero_
Definition diago_lobpcg.h:143
nrm2_op nrm2_op_
Definition diago_lobpcg.h:155
bool lock_converged(ct::Tensor &eig_prev, const ct::Tensor &tol_band, int &locked)
Lock the leading bands satisfying the eigenvalue-change tolerance; soft locking can reactivate them.
Definition diago_lobpcg.cpp:419
void rotate_images(const VectorImages &source, const int source_columns, const int target_columns, const T *coefficients, const VectorImages &target, T *scratch)
Apply the same right coefficient matrix to each supplied X/HX/SX image; scratch permits overlap.
Definition diago_lobpcg.cpp:552
ct::Tensor eig_device_
Definition diago_lobpcg.h:130
~DiagoLOBPCG()
Record the final owned algebra workspace capacity before its buffers are released.
Definition diago_lobpcg.cpp:56
ct::Tensor prec_
Definition diago_lobpcg.h:126
int n_dim_
Definition diago_lobpcg.h:108
const int para_rr_method_
Definition diago_lobpcg.h:115
void broadcast(Value *data, const int count) const
Share root-owned coefficients or status within the eigensolve communicator.
Definition lobpcg_internal.h:48
ct::Tensor x_new_
Definition diago_lobpcg.h:137
int rank_orthonormalize(const int m, T *x, T *sx)
Recovery-only metric normalization: use Cholesky for a well-conditioned block, otherwise spectral ran...
Definition lobpcg_recovery.cpp:276
std::complex< double > Wide
Accumulation and projected eigensolver precision.
Definition diago_lobpcg.h:45
typename GetTypeReal< T >::type Real
Real precision of the stored wavefunctions T.
Definition diago_lobpcg.h:44
VectorImages basis_images(const int first)
Return non-owning X/HX/SX pointers at one column offset in the shared trial-basis storage.
Definition diago_lobpcg.cpp:674
ct::DataType r_type_
Definition diago_lobpcg.h:122
bool diag(const HSOperator< T, Device > &op, T *psi_in, const int ld_psi, Real *eigenvalue_in, const double tolerance, const int max_iter, const std::vector< double > ðr_band)
Solve H X = S X Lambda by generalized RR in [X,P,W], with prefix locking and failure-only repair.
Definition diago_lobpcg.cpp:69
ct::kernels::synchronize_memory< Real, CtDevice, ct::DEVICE_CPU > syncmem_var_h2d_op
Definition diago_lobpcg.h:146
int normalize_columns(const VectorImages &block, const int columns, T *coefficients, const int coefficient_rows)
Scale nonzero columns by their global Euclidean norm and compact images and coefficients together.
Definition diago_lobpcg.cpp:581
ct::Tensor sx_new_
Definition diago_lobpcg.h:139
int iterations() const
Definition diago_lobpcg.h:75
std::string error_message_
Definition diago_lobpcg.h:111
ct::Tensor e_red_
Definition diago_lobpcg.h:136
ct::kernels::blas_axpy< T, CtDevice > axpy_op
Definition diago_lobpcg.h:150
base_device::memory::synchronize_memory_2d_op< T, Device, Device > syncmem_complex_2d_op
Definition diago_lobpcg.h:145
int iterations_
Definition diago_lobpcg.h:110
ct::kernels::set_memory< T, CtDevice > setmem_complex_op
Definition diago_lobpcg.h:147
const diag_comm_info comm_
Definition diago_lobpcg.h:114
void initialize(T *psi_in, const int ld_psi)
Copy the input X, seed optional buffer bands, and zero inactive rows in each spinor component.
Definition diago_lobpcg.cpp:337
void write_results(T *psi_in, const int ld_psi, Real *eigenvalue_in)
Copy only the requested Ritz pairs back to the caller, preserving its leading dimension.
Definition diago_lobpcg.cpp:543
ct::Tensor u_p_
Definition diago_lobpcg.h:141
ct::Tensor evec_
Definition diago_lobpcg.h:131
const LobpcgBasisLayout layout_
Definition diago_lobpcg.h:113
void allocate_workspace()
Allocate wavefunction blocks and small RR buffers for the current internal width, and record capacity...
Definition diago_lobpcg.cpp:702
int build_search(const HSOperator< T, Device > &op, const int locked, const int count, const int first_w)
Precondition the active residual, project out the locked prefix, then normalize and compact W.
Definition diago_lobpcg.cpp:382
void form_residual(const VectorImages &vectors, const int count, const Real *eigenvalues, T *residual)
Form R = HX - SX*Lambda for the supplied block; a null SX means S = I.
Definition diago_lobpcg.cpp:364
void retain_pair(const ct::Tensor &k, const ct::Tensor &g, const int rows, const ct::Tensor &x_coefficients, const int first_x, const int x_columns, const int p_columns, const Real *ritz_values, const int zero_prefix, ProjectionCache &cache)
Cache projections for the new [X,P] using coefficient-space products and the Ritz XX identities.
Definition lobpcg_subspace.cpp:276
const int para_rr_bs_
Definition diago_lobpcg.h:116
ct::kernels::synchronize_memory< T, CtDevice, ct::DEVICE_CPU > syncmem_complex_h2d_op
Definition diago_lobpcg.h:148
precondition_op< T, Device > precondition_op_
Definition diago_lobpcg.h:156
LinearAlgebra< T, Device > algebra_
Definition diago_lobpcg.h:158
ct::kernels::blas_copy< T, CtDevice > copy_op
Definition diago_lobpcg.h:149
ct::kernels::blas_nrm2< T, CtDevice > nrm2_op
Definition diago_lobpcg.h:151
int build_direction(const VectorImages &basis, const int dimension, const int q, const int active, const ct::Tensor &x_coefficients, const ct::Tensor &g)
Form P from the non-X Ritz coefficients, removing new locked components before normalization.
Definition diago_lobpcg.cpp:442
ct::DataType t_type_
Definition diago_lobpcg.h:123
typename ct::PsiToContainer< Device >::type CtDevice
Definition diago_lobpcg.h:46
void project_padding(T *x, const int columns) const
Zero unused rows of every spinor component so full-stride BLAS products exclude nonphysical entries.
Definition diago_lobpcg.cpp:683
int n_max_
Definition diago_lobpcg.h:109
bool recover_projected(const HSOperator< T, Device > &op, const VectorImages &basis, int &working_columns, const int wanted, ct::Tensor &projected, ct::Tensor &gram, SerialGvWorkspace &workspace)
After GV metric failure, refresh true H/S images and retry; if needed, repair only the increments.
Definition lobpcg_recovery.cpp:95
DiagoLOBPCG(const Real *precondition, const int nband, const int ndim, const int nmax, const LobpcgBasisLayout &layout, const diag_comm_info &comm, const int para_rr_method, const int para_rr_block_size, const bool use_overlap, const LobpcgLocking locking, dense::ParallelDenseEigensolver &rr_solver, dense::GpuDenseEigensolver &gpu_rr_solver)
Store the caller configuration and allocate Device wavefunction and host RR workspaces.
Definition diago_lobpcg.cpp:25
dense::GpuDenseEigensolver & gpu_rr_solver_
Definition diago_lobpcg.h:120
ct::Tensor space_
Definition diago_lobpcg.h:132
friend class LobpcgProjectionTest
Definition diago_lobpcg.h:41
ct::Tensor residual_
Definition diago_lobpcg.h:140
ct::Tensor hx_new_
Definition diago_lobpcg.h:138
dense::SerialGvWorkspace SerialGvWorkspace
Definition diago_lobpcg.h:86
int repair_basis(const HSOperator< T, Device > &op, const int added)
Preserve X, project increments with its actual S metric, then repair their rank and refresh H images.
Definition lobpcg_recovery.cpp:135
ct::Tensor sspace_
Definition diago_lobpcg.h:134
ct::Tensor hspace_
Definition diago_lobpcg.h:133
ct::Tensor ritz_coefficients_
Definition diago_lobpcg.h:135
bool solve_projected(const ct::Tensor &k, const ct::Tensor &g, const int dimension, const int wanted, SerialGvWorkspace &serial_workspace)
Solve K C = G C Theta for the wanted Ritz pairs and share the result; return false for metric failure...
Definition lobpcg_subspace.cpp:123
ct::DeviceType device_type_
Definition diago_lobpcg.h:124
What an iterative eigensolver needs from the generalized eigenproblem H x = e S x: the ability to app...
Definition hs_operator.h:24
Collective block algebra; only small coefficients cross the device boundary.
Definition linear_algebra.h:53
Definition dense_eigensolver.h:83
Definition dense_eigensolver.h:47
#define T
Definition exp.cpp:237
DataType
Definition tensor_enums.h:15
@ DT_COMPLEX_DOUBLE
Definition tensor_enums.h:22
@ DT_INVALID
Definition tensor_enums.h:16
DeviceType
Definition tensor_enums.h:28
@ UnKnown
Definition tensor_enums.h:29
@ CpuDevice
Definition tensor_enums.h:30
Definition dense_eigensolver.cpp:25
Definition dense_eigensolver.cpp:23
LobpcgLocking
Definition diago_lobpcg.h:26
@ Hard
Definition diago_lobpcg.h:27
@ Soft
Definition diago_lobpcg.h:28
T type
Definition macros.h:8
Definition memory_op.h:77
T type
Definition tensor_types.h:76
A functor to set memory to a constant value.
Definition memory.h:37
Synchronizes memory between devices.
Definition memory.h:58
Definition diago_lobpcg.h:91
ct::Tensor device_product
Definition diago_lobpcg.h:102
ct::Tensor k
Root-owned projections of [X,P]; empty on other ranks.
Definition diago_lobpcg.h:94
~ProjectionCache()
Definition lobpcg_subspace.cpp:385
ct::Tensor device_result
Definition diago_lobpcg.h:103
ct::Tensor h_product
Host scratch for Q*C_P and the packed coefficient matrix [C_X,C_P].
Definition diago_lobpcg.h:97
ct::Tensor device_matrix
Device scratch for the same retained-block products; host K/G remain authoritative.
Definition diago_lobpcg.h:100
ct::Tensor device_coefficients
Definition diago_lobpcg.h:101
ct::Tensor g
Definition diago_lobpcg.h:95
ct::Tensor structural_coefficients
Definition diago_lobpcg.h:98
int columns
Definition diago_lobpcg.h:92
Definition diago_lobpcg.h:80
T * sx
Matching S images; null denotes S = I.
Definition diago_lobpcg.h:83
T * hx
Matching H images; null when a transformation does not need them.
Definition diago_lobpcg.h:82
T * x
Borrowed column block on Device.
Definition diago_lobpcg.h:81
Definition diago_lobpcg.h:33
int npol
Spinor components sharing the column storage stride ndim / npol.
Definition diago_lobpcg.h:35
int npw
Local physical plane-wave rows in each spinor component.
Definition diago_lobpcg.h:34
Definition dense_eigensolver.h:22
Definition diag_comm_info.h:12
Definition bpcg_kernel_op.h:78