24template <
typename T = std::complex<
double>,
typename Device = base_device::DEVICE_CPU>
57 void init_iter(
const int nband,
const int nband_l,
const int nbasis,
const int ndim);
71 const std::vector<double>& ethr_band);
this class is used to perform parallel matrix multiplication C = alpha * A^H * B + beta * C Here,...
Definition para_gemm.h:25
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
void orth_projection(const ct::Tensor &psi_in, const ct::Tensor &spsi_in, ct::Tensor &hsub_in, ct::Tensor &grad_out, ct::Tensor &sgrad_out)
Orthogonalize column vectors in grad to column vectors in psi.
Definition diago_bpcg.cpp:175
ct::Tensor hpsi
Definition diago_bpcg.h:106
int n_dim
valid dimension of psi
Definition diago_bpcg.h:81
ct::Tensor h_prec
Definition diago_bpcg.h:93
ct::Tensor spsi
Definition diago_bpcg.h:107
void calc_hsub_with_block(const HSOperator< T, Device > &op, T *psi_in, ct::Tensor &psi_out, ct::Tensor &hpsi_out, ct::Tensor &spsi_out, ct::Tensor &hsub_out, ct::Tensor &workspace_in, ct::Tensor &eigenvalue_out)
Apply the Hamiltonian operator to psi and obtain the hpsi matrix.
Definition diago_bpcg.cpp:246
void init_iter(const int nband, const int nband_l, const int nbasis, const int ndim)
Initialize the class before diagonalization.
Definition diago_bpcg.cpp:37
void calc_hsub_with_block_exit(ct::Tensor &psi_out, ct::Tensor &hpsi_out, ct::Tensor &hsub_out, ct::Tensor &workspace_in, ct::Tensor &eigenvalue_out)
Apply the Hamiltonian operator to psi and obtain the hpsi matrix.
Definition diago_bpcg.cpp:277
ct::Tensor prec
Definition diago_bpcg.h:93
int n_basis
the number of cols of the input psi
Definition diago_bpcg.h:79
ModuleBase::gemm_op< T, Device > gemm_op
Definition diago_bpcg.h:367
void rotate_wf(const ct::Tensor &hsub_in, ct::Tensor &psi_out, ct::Tensor &workspace_in)
Inplace matrix multiplication to obtain the initial guessed wavefunction.
Definition diago_bpcg.cpp:193
const T zero_
Definition diago_bpcg.h:126
ct::kernels::set_memory< Real, ct_Device > setmem_var_op
Definition diago_bpcg.h:352
~DiagoBPCG()
Destructor for DiagoBPCG class.
Definition diago_bpcg.cpp:32
ct::kernels::synchronize_memory< Real, ct::DEVICE_CPU, ct_Device > syncmem_var_d2h_op
Definition diago_bpcg.h:356
void diag_hsub(const ct::Tensor &psi_in, const ct::Tensor &hpsi_in, ct::Tensor &hsub_out, ct::Tensor &eigenvalue_out)
Diagonalization of the subspace matrix.
Definition diago_bpcg.cpp:230
ct::kernels::synchronize_memory< T, ct_Device, ct_Device > syncmem_complex_op
Definition diago_bpcg.h:361
int nline
max iter steps for all-band cg loop
Definition diago_bpcg.h:83
const T * zero
Definition diago_bpcg.h:125
const T * one
Definition diago_bpcg.h:125
ct::Tensor grad
Definition diago_bpcg.h:113
int n_band
the number of bands of all processes
Definition diago_bpcg.h:75
void calc_grad_with_block(const ct::Tensor &prec_in, ct::Tensor &err_out, ct::Tensor &beta_out, ct::Tensor &psi_in, ct::Tensor &hpsi_in, ct::Tensor &spsi_in, ct::Tensor &grad_out, ct::Tensor &grad_old_out)
Calculate the gradient for all bands used in CG method.
Definition diago_bpcg.cpp:145
ct::DataType t_type
Definition diago_bpcg.h:90
ct::Tensor sgrad
Definition diago_bpcg.h:115
void line_minimize(ct::Tensor &grad_in, ct::Tensor &hgrad_in, ct::Tensor &sgrad_in, ct::Tensor &psi_out, ct::Tensor &hpsi_out, ct::Tensor &spsi_out)
Optimize psi together with hpsi and spsi.
Definition diago_bpcg.cpp:98
ct::kernels::resize_memory< Real, ct_Device > resmem_var_op
Definition diago_bpcg.h:353
ct::Tensor hgrad
Definition diago_bpcg.h:114
const T one_
Definition diago_bpcg.h:126
void diag(const HSOperator< T, Device > &op, T *psi_in, Real *eigenvalue_in, const std::vector< double > ðr_band)
Diagonalize the Hamiltonian using the BPCG method.
Definition diago_bpcg.cpp:295
int n_band_l
the number of bands of current process
Definition diago_bpcg.h:77
Device * ctx
ctx is nothing but the devices used in gemm_op (Device * ctx = nullptr;),
Definition diago_bpcg.h:123
ct::kernels::set_memory< T, ct_Device > setmem_complex_op
Definition diago_bpcg.h:358
ModuleBase::PGemmCN< T, Device > pmmcn
parallel matrix multiplication
Definition diago_bpcg.h:85
typename ct::PsiToContainer< Device >::type ct_Device
Definition diago_bpcg.h:351
ct::Tensor beta
The coefficient for mixing the current and previous step gradients, used in iterative methods.
Definition diago_bpcg.h:96
const T neg_one_
Definition diago_bpcg.h:126
ct::kernels::synchronize_memory< Real, ct_Device, ct::DEVICE_CPU > syncmem_var_h2d_op
Definition diago_bpcg.h:355
DiagoBPCG(const Real *precondition)
Constructor for DiagoBPCG class.
Definition diago_bpcg.cpp:18
ct::Tensor err_st
Error state value, if it is smaller than the given threshold, then exit the iteration.
Definition diago_bpcg.h:98
ct::kernels::delete_memory< T, ct_Device > delmem_complex_op
Definition diago_bpcg.h:359
PLinearTransform< T, Device > plintrans
Definition diago_bpcg.h:86
void calc_hpsi_with_block(const HSOperator< T, Device > &op, const T *psi_in, ct::Tensor &hpsi_out)
Apply the H operator to psi and obtain the hpsi matrix.
Definition diago_bpcg.cpp:211
ct::Tensor eigen
Calculated eigen.
Definition diago_bpcg.h:100
ct::Tensor grad_old
Definition diago_bpcg.h:116
void calc_spsi_with_block(const HSOperator< T, Device > &op, const T *psi_in, ct::Tensor &spsi_out)
Apply the overlap operator to a wavefunction block.
Definition diago_bpcg.cpp:221
ct::DataType r_type
Definition diago_bpcg.h:89
ct::Tensor hsub
Definition diago_bpcg.h:109
void orth_cholesky(ct::Tensor &workspace_in, ct::Tensor &psi_out, ct::Tensor &hpsi_out, ct::Tensor &spsi_out, ct::Tensor &hsub_out)
S-orthogonalize and normalize the column vectors in psi_out using Cholesky decomposition.
Definition diago_bpcg.cpp:120
bool test_error(const ct::Tensor &err_in, const std::vector< double > ðr_band)
Checks if the error satisfies the given threshold.
Definition diago_bpcg.cpp:72
const T * neg_one
Definition diago_bpcg.h:125
ct::kernels::resize_memory< T, ct_Device > resmem_complex_op
Definition diago_bpcg.h:360
void calc_prec()
Update the precondition array.
Definition diago_bpcg.cpp:169
typename GetTypeReal< T >::type Real
Definition diago_bpcg.h:31
ct::kernels::delete_memory< Real, ct_Device > delmem_var_op
Definition diago_bpcg.h:354
ct::Tensor work
work for some calculations within this class, including rotate_wf call
Definition diago_bpcg.h:119
ct::DeviceType device_type
Definition diago_bpcg.h:91
base_device::memory::synchronize_memory_2d_op< T, Device, Device > syncmem_complex_2d_op
Definition diago_bpcg.h:362
What an iterative eigensolver needs from the generalized eigenproblem H x = e S x: the ability to app...
Definition hs_operator.h:24
#define T
Definition exp.cpp:237
DataType
Definition tensor_enums.h:15
@ DT_INVALID
Definition tensor_enums.h:16
DeviceType
Definition tensor_enums.h:28
@ UnKnown
Definition tensor_enums.h:29
Definition dense_eigensolver.cpp:23
Definition diag_lcao.h:14
T type
Definition macros.h:8
Definition math_kernel_op.h:298
Definition memory_op.h:77
T type
Definition tensor_types.h:76
Deletes memory on a device.
Definition memory.h:135
A functor to resize memory allocation.
Definition memory.h:19
A functor to set memory to a constant value.
Definition memory.h:37
Synchronizes memory between devices.
Definition memory.h:58