ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
sto_che.h
Go to the documentation of this file.
1#ifndef STO_CHE_H
2#define STO_CHE_H
6
7#include <memory>
8#include <vector>
9
10template <typename REAL, typename Device = base_device::DEVICE_CPU>
11class StoChe
12{
13 private:
14#ifdef __DSP
15 using resmem_var_op = base_device::memory::resize_memory_op_mt<REAL, Device>;
16 using delmem_var_op = base_device::memory::delete_memory_op_mt<REAL, Device>;
17#else
20#endif
22
25 {
26 void operator()(REAL* p) const
27 {
28 if (p)
29 {
30 delmem_var_op()(p);
31 }
32 }
33 };
34
35 public:
36 StoChe() = default;
37 ~StoChe() = default;
38
39 StoChe(const StoChe&) = delete;
40 StoChe& operator=(const StoChe&) = delete;
41 StoChe(StoChe&&) noexcept = default;
42 StoChe& operator=(StoChe&&) noexcept = default;
43
45 void init(const int& nche, const int& method, const REAL& emax_sto, const REAL& emin_sto);
46
47 int nche = 0;
48 std::unique_ptr<REAL, delmem_var_deleter> spolyv;
49 std::vector<REAL> spolyv_cpu;
50 int method_sto = 0;
51
53 std::unique_ptr<ModuleBase::Chebyshev<REAL, Device>> p_che;
54
55 REAL emax_sto = 0.0;
56 REAL emin_sto = 0.0;
57
58 private:
59 Device* ctx = {};
60};
61
70template <typename REAL, typename Device>
71REAL vTMv(const REAL* v, const REAL* M, const int n)
72{
73 Device* ctx = {};
74 base_device::DEVICE_CPU* cpu_ctx = {};
75 using ct_Device = typename container::PsiToContainer<Device>::type;
76 const char normal = 'N';
77 const REAL one = 1;
78 const int inc = 1;
79 const REAL zero = 0;
80 REAL* y = nullptr;
82 ModuleBase::gemv_op<REAL, Device>()(normal, n, n, &one, M, n, v, inc, &zero, y, inc);
83 REAL result = 0;
84 REAL* dot_device = nullptr;
86 container::kernels::blas_dot<REAL, ct_Device>()(n, y, 1, v, 1, dot_device);
88 dot_device,
89 1);
92 return result;
93}
94
95#endif
base_device::memory::resize_memory_op< REAL, Device > resmem_var_op
Definition sto_che.h:18
std::unique_ptr< REAL, delmem_var_deleter > spolyv
[Device] coefficients of Chebyshev expansion
Definition sto_che.h:48
base_device::memory::delete_memory_op< REAL, Device > delmem_var_op
Definition sto_che.h:19
StoChe(const StoChe &)=delete
Device * ctx
Definition sto_che.h:59
base_device::memory::synchronize_memory_op< REAL, base_device::DEVICE_CPU, Device > syncmem_var_d2h_op
Definition sto_che.h:21
REAL emin_sto
minimum energy for normalization
Definition sto_che.h:56
std::vector< REAL > spolyv_cpu
[CPU] coefficients of Chebyshev expansion (method==1 only)
Definition sto_che.h:49
REAL emax_sto
maximum energy for normalization
Definition sto_che.h:55
int nche
order of Chebyshev expansion
Definition sto_che.h:47
std::unique_ptr< ModuleBase::Chebyshev< REAL, Device > > p_che
Chebyshev expansion. Stores the plan of FFTW and should be initialized at the beginning of the calcul...
Definition sto_che.h:53
StoChe(StoChe &&) noexcept=default
~StoChe()=default
int method_sto
method for the stochastic calculation
Definition sto_che.h:50
void init(const int &nche, const int &method, const REAL &emax_sto, const REAL &emin_sto)
(Re)allocate Chebyshev expansion buffers. Safe to call multiple times.
Definition sto_che.cpp:7
StoChe()=default
StoChe & operator=(const StoChe &)=delete
Definition clebsch_gordan_coeff.cpp:8
REAL vTMv(const REAL *v, const REAL *M, const int n)
calculate v^T*M*v
Definition sto_che.h:71
Definition math_kernel_op.h:254
deleter for device-side spolyv buffer
Definition sto_che.h:25
void operator()(REAL *p) const
Definition sto_che.h:26
Definition memory_op.h:115
Definition memory_op.h:17
T type
Definition tensor_types.h:76
Definition blas.h:33
#define private
Definition test_io_sys_var.cpp:11