ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
bse_util.h
Go to the documentation of this file.
1#ifndef ABACUS_SOURCE_LCAO_MODULE_BSE_BSE_UTIL_H
2#define ABACUS_SOURCE_LCAO_MODULE_BSE_BSE_UTIL_H
3
4
5#include <ATen/core/tensor.h>
6#include "source_psi/psi.h"
13#include <RI/global/Tensor.h>
14#include <array>
15#include <map>
16namespace BSE_Util
17{
19inline void print_mem_estimate(const std::string& name,
20 const size_t& local_size,
21 const size_t& type_size)
22{
23 double mem_MB = static_cast<double>(local_size * type_size) / (1024.0 * 1024.0);
24 double mem_GB = mem_MB / 1024.0;
25
26 GlobalV::ofs_running << "Allocating " << name << ", memory size: ";
27 if (mem_GB >= 1.0) {
28 GlobalV::ofs_running << std::fixed << std::setprecision(5) << mem_GB << " GB";
29 } else {
30 GlobalV::ofs_running << std::fixed << std::setprecision(5) << mem_MB << " MB";
31 }
32 GlobalV::ofs_running << std::endl;
33}
34
36using TA = int;
37using TC = std::array<int, 3>;
38using TAC = std::pair<int, TC>;
39template <typename T>
40using TLRI = std::map<TA, std::map<TAC, RI::Tensor<T>>>;
41template <typename T>
42bool move_R_tensor(TLRI<T>& tensor_map, const TA ia, const TA ja, const TC& R_original, const TC& R_new)
43{
44 auto it_a = tensor_map.find(ia);
45 if (it_a == tensor_map.end()) return false;
46
47 auto& map_ja = it_a->second;
48
49 const TAC old_key{ja, R_original};
50 auto it_b = map_ja.find(old_key);
51 if (it_b == map_ja.end()) return false;
52
53 const TAC new_key{ja, R_new};
54 assert(map_ja.count(new_key) == 0 && "Error: target R tensor already exists in move_R_tensor!");
55
56 map_ja[new_key] = std::move(it_b->second);
57 map_ja.erase(it_b);
58 return true;
59}
60
64
66template <typename T>
68
70
72#ifdef __MPI
75template<typename T>
77 const psi::Psi<T>& c,
78 const Parallel_Blkcyclic& pc,
79 const int& ik,
80 const int& naos,
81 const int& imo1, // imo1 → imo2, for excitation imo1[1,nocc], imo2[nocc+1,nocc+nvirt]
82 const int& imo2,
83 const Parallel_Orbitals& pmat,
84 const T& factor = (T)1.0);
85
86#endif
87
89template<typename T>
91 const psi::Psi<T>& c,
92 const int& ik,
93 const int& naos,
94 const int& imo1, // imo1 → imo2, for excitation imo1[1,nocc], imo2[nocc+1,nocc+nvirt]
95 const int& imo2,
96 const T& factor = (T)1.0);
97
98}
99
100#endif // ABACUS_SOURCE_LCAO_MODULE_BSE_BSE_UTIL_H
Parallel block-cyclic matrix distribution.
Definition parallel_blkcyc.h:25
Definition parallel_orbitals.h:16
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
Definition psi.h:37
#define T
Definition exp.cpp:237
Definition bse_util.cpp:5
std::map< TA, std::map< TAC, RI::Tensor< T > > > TLRI
Definition bse_util.h:40
container::Tensor cal_dm_trans_onebase_blas(const psi::Psi< double > &c, const int &ik, const int &naos, const int &imo1, const int &imo2, const double &factor)
Definition bse_util.cpp:93
container::DeviceType DEV
Definition bse_util.h:63
int TA
================ RI ==================
Definition bse_util.h:36
container::DataType DAT
================ Container ===============
Definition bse_util.h:62
void print_mem_estimate(const std::string &name, const size_t &local_size, const size_t &type_size)
================ info ==================
Definition bse_util.h:19
std::pair< int, TC > TAC
Definition bse_util.h:38
container::Tensor cal_dm_trans_onebase_pblas(const psi::Psi< double > &c, const Parallel_Blkcyclic &pc, const int &ik, const int &naos, const int &imo1, const int &imo2, const Parallel_Orbitals &pmat, const double &factor)
Definition bse_util.cpp:8
container::DataTypeToEnum< T > DAT_ENUM
Struct to get DataType enum for different tensor data types, not used currently.
Definition bse_util.h:67
std::array< int, 3 > TC
Definition bse_util.h:37
bool move_R_tensor(TLRI< T > &tensor_map, const TA ia, const TA ja, const TC &R_original, const TC &R_new)
Definition bse_util.h:42
std::ofstream ofs_running
Definition global_variable.cpp:38
DataType
Definition tensor_enums.h:15
DeviceType
Definition tensor_enums.h:28
Definition tensor_enums.h:60