ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
hamilt::Operator< T, Device > Class Template Reference

#include <operator.h>

Inheritance diagram for hamilt::Operator< T, Device >:
Collaboration diagram for hamilt::Operator< T, Device >:

Public Types

typedef std::tuple< const psi::Psi< T, Device > *, const psi::Range, T * > hpsi_info
 input type of hPsi: (psi_input, range, hpsi_pointer)

Public Member Functions

 Operator ()
virtual ~Operator ()
virtual hpsi_info hPsi (hpsi_info &input) const
 Core hot-path: compute H|psi> by traversing the operator chain.
virtual void init (const int ik_in)
virtual void add (Operator *next)
virtual int get_ik () const
virtual void act (const int nbands, const int nbasis, const int npol, const T *tmpsi_in, T *tmhpsi, const int ngk_ik=0, const bool is_first_node=false) const
virtual void act (const psi::Psi< T, Device > &psi_in, psi::Psi< T, Device > &psi_out, const int nbands) const
int get_act_type () const
calculation_type get_cal_type () const

Public Attributes

Operator * next_op = nullptr
 interface type 3: return a Psi-type HPsi

Protected Types

using set_memory_op = base_device::memory::set_memory_op<T, Device>

Protected Member Functions

T * get_hpsi (const hpsi_info &info) const

Protected Attributes

int ik = 0
int act_type = 1
 determine which act() interface would be called in hPsi()
bool in_place = false
enum calculation_type cal_type
Operator * next_sub_op = nullptr
bool is_first_node = true
psi::Psi< T, Device > * hpsi = nullptr
Device * ctx = {}

Member Typedef Documentation

◆ hpsi_info

template<typename T, typename Device = base_device::DEVICE_CPU>
typedef std::tuple<const psi::Psi<T, Device> *, const psi::Range, T *> hamilt::Operator< T, Device >::hpsi_info

input type of hPsi: (psi_input, range, hpsi_pointer)

hpsi_info bundles the input and output of hPsi():

  • std::get<0>: pointer to psi::Psi<T, Device> (input wavefunction)
  • std::get<1>: psi::Range specifying which bands to operate on
  • std::get<2>: T* pointer to output hpsi buffer (can equal psi_in for in-place)

◆ set_memory_op

template<typename T, typename Device = base_device::DEVICE_CPU>
using hamilt::Operator< T, Device >::set_memory_op = base_device::memory::set_memory_op<T, Device>
protected

Constructor & Destructor Documentation

◆ Operator()

template<typename T, typename Device>
Operator::Operator ( )
Here is the caller graph for this function:

◆ ~Operator()

template<typename T, typename Device>
Operator::~Operator ( )
virtual
Here is the call graph for this function:

Member Function Documentation

◆ act() [1/2]

template<typename T, typename Device = base_device::DEVICE_CPU>
virtual void hamilt::Operator< T, Device >::act ( const int nbands,
const int nbasis,
const int npol,
const T * tmpsi_in,
T * tmhpsi,
const int ngk_ik = 0,
const bool is_first_node = false ) const
inlinevirtual

do operation : |hpsi_choosed> = V|psi_choosed> V is the target operator act on choosed psi, the consequence should be added to choosed hpsi interface type 1: pointer-only (default)

Note
PW: nbasis = max_npw * npol, nbands = nband * npol, npol = npol. Strange but PAY ATTENTION!!!

Reimplemented in hamilt::Ekinetic< OperatorPW< T, Device > >, hamilt::Meta< OperatorPW< T, Device > >, hamilt::Nonlocal< OperatorPW< T, Device > >, hamilt::OnsiteProj< OperatorPW< T, Device > >, hamilt::OperatorEXXPW< T, Device >, hamilt::TDEkineticPW< T, Device >, hamilt::TDNonlocalPW< T, Device >, hamilt::Veff< OperatorPW< T, Device > >, RI_Benchmark::OperatorRIHartree< T >, and TestOp< T, Device >.

Here is the caller graph for this function:

◆ act() [2/2]

template<typename T, typename Device = base_device::DEVICE_CPU>
virtual void hamilt::Operator< T, Device >::act ( const psi::Psi< T, Device > & psi_in,
psi::Psi< T, Device > & psi_out,
const int nbands ) const
inlinevirtual

developer-friendly interfaces for act() function interface type 2: input and change the Psi-type HPsi

◆ add()

template<typename T, typename Device>
void Operator::add ( Operator< T, Device > * next)
virtual
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_act_type()

template<typename T, typename Device = base_device::DEVICE_CPU>
int hamilt::Operator< T, Device >::get_act_type ( ) const
inline

type 1 (default): pointer-only act(const T* psi_in, T* psi_out) type 2: use the Psiclass act(const Psi& psi_in, Psi& psi_out)

Here is the caller graph for this function:

◆ get_cal_type()

template<typename T, typename Device = base_device::DEVICE_CPU>
calculation_type hamilt::Operator< T, Device >::get_cal_type ( ) const
inline
Here is the caller graph for this function:

◆ get_hpsi()

template<typename T, typename Device>
T * Operator::get_hpsi ( const hpsi_info & info) const
protected
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_ik()

template<typename T, typename Device = base_device::DEVICE_CPU>
virtual int hamilt::Operator< T, Device >::get_ik ( ) const
inlinevirtual
Here is the caller graph for this function:

◆ hPsi()

template<typename T, typename Device>
Operator< T, Device >::hpsi_info Operator::hPsi ( hpsi_info & input) const
virtual

Core hot-path: compute H|psi> by traversing the operator chain.

This is the central computational kernel of ABACUS, called O(n_bands * n_iter * n_kpoints) times during a single SCF calculation. It accounts for 18-25% of total runtime.

Algorithm:

  1. Unwrap the input hpsi_info to get psi, band range, and output buffer
  2. Allocate or reuse the temporary hpsi buffer via get_hpsi()
  3. Call act() on the first operator node (is_first_node=true) – this node zeros hpsi
  4. Iterate through next_op linked list, calling act() on each subsequent node (is_first_node=false) Each node accumulates its contribution: hpsi += O|psi>
  5. If in_place mode, copy temporary hpsi back to the caller-provided buffer
  6. Return wrapped hpsi_info for downstream use

The operator chain typically includes (in order): Ekinetic → Veff → Nonlocal → Meta → OnsiteProj

Parameters
inputhpsi_info tuple: (psi_input, band_range, hpsi_output_pointer)
  • psi_input: the wavefunction Psi object
  • band_range: which bands to compute (range_1 to range_2 inclusive)
  • hpsi_output_pointer: pre-allocated buffer for H|psi> result. If equal to psi_input pointer, in_place mode is used (temporary buffer allocated internally).
Returns
hpsi_info containing (internal_hpsi, range, caller_hpsi_pointer)
Note
This function is performance-critical. The operator chain traversal is the innermost loop of iterative diagonalization methods (CG, Davidson, BPCG).
For PW calculations, each act() call may involve FFT transforms (Veff), BLAS3 gemm operations (Nonlocal), or element-wise vector ops (Ekinetic).
See also
Operator::act(), HamiltPW, DiagoCG::diag()
Here is the call graph for this function:

◆ init()

template<typename T, typename Device>
void Operator::init ( const int ik_in)
virtual

Member Data Documentation

◆ act_type

template<typename T, typename Device = base_device::DEVICE_CPU>
int hamilt::Operator< T, Device >::act_type = 1
protected

determine which act() interface would be called in hPsi()

◆ cal_type

template<typename T, typename Device = base_device::DEVICE_CPU>
enum calculation_type hamilt::Operator< T, Device >::cal_type
protected

◆ ctx

template<typename T, typename Device = base_device::DEVICE_CPU>
Device* hamilt::Operator< T, Device >::ctx = {}
protected

◆ hpsi

template<typename T, typename Device = base_device::DEVICE_CPU>
psi::Psi<T, Device>* hamilt::Operator< T, Device >::hpsi = nullptr
mutableprotected

◆ ik

template<typename T, typename Device = base_device::DEVICE_CPU>
int hamilt::Operator< T, Device >::ik = 0
protected

◆ in_place

template<typename T, typename Device = base_device::DEVICE_CPU>
bool hamilt::Operator< T, Device >::in_place = false
mutableprotected

◆ is_first_node

template<typename T, typename Device = base_device::DEVICE_CPU>
bool hamilt::Operator< T, Device >::is_first_node = true
protected

◆ next_op

template<typename T, typename Device = base_device::DEVICE_CPU>
Operator* hamilt::Operator< T, Device >::next_op = nullptr

interface type 3: return a Psi-type HPsi

◆ next_sub_op

template<typename T, typename Device = base_device::DEVICE_CPU>
Operator* hamilt::Operator< T, Device >::next_sub_op = nullptr
protected

The documentation for this class was generated from the following files: