5#include <RI/global/Tensor.h>
16 int read_value(std::ifstream& ifs,
T* ptr,
const int& size) {
for (
int i = 0;i < size;++i) { ifs >> ptr[i]; }
return size; }
17 template<
typename T,
typename... Args>
18 int read_value(std::ifstream& ifs,
T* ptr,
const int& size, Args&&... args)
21 for (
int i = 0;i < size;++i) { size_now +=
read_value(ifs, ptr + size_now, args...); }
24 template<
typename T,
typename... Args>
27 std::ifstream ifs(
file);
28 const int res =
read_value(ifs, ptr, size, args...);
36 for (
int i = 0;i < size;++i) { ofs <<
filter(ptr[i]) <<
" "; }
40 template<
typename T,
typename... Args>
41 int write_value(std::ofstream& ofs,
const T* ptr,
const int& size, Args&&... args)
44 for (
int i = 0;i < size;++i) { size_now +=
write_value(ofs, ptr + size_now, args...); }
48 template<
typename T,
typename... Args>
49 int write_value(
const std::string&
file,
const int& prec,
const T* ptr,
const int& size, Args&&... args)
51 std::ofstream ofs(
file);
52 ofs << std::setprecision(prec) << std::scientific;
53 const int res =
write_value(ofs, ptr, size, args...);
60 for (
int i = 0;i < size;++i) { std::cout <<
filter(ptr[i]) <<
" "; }
61 std::cout << std::endl;
64 template<
typename T,
typename... Args>
68 for (
int i = 0;i < size;++i) { size_now +=
print_value(ptr + size_now, args...); }
69 std::cout << std::endl;
76 assert(
psi.get_k_first() == 0);
77 std::cout << label <<
": band " << ib <<
"\n";
78 for (
int ik = 0;ik <
psi.get_nk();++ik)
80 std::cout <<
"iks=" << ik <<
"\n";
81 for (
int i = 0;i <
psi.get_nbasis();++i)
83 std::cout <<
filter(
psi(ib, ik, i)) <<
" ";
91 assert(
psi.get_k_first() == 0);
92 std::ofstream ofs(filename +
"_" + std::to_string(rank) +
".dat");
93 ofs << std::setprecision(precision) << std::scientific;
94 ofs <<
psi.get_nbands() <<
" " <<
psi.get_nk() <<
" " <<
psi.get_nbasis() <<
"\n";
100 const std::string& filename,
const int& rank,
const double&
threshold = 1e-10,
const int& precision = 8)
102 std::ofstream ofs(filename +
"_" + std::to_string(rank) +
".dat");
103 ofs << std::setprecision(precision) << std::scientific;
104 ofs << nband <<
" " << nk <<
" " << nbasis <<
"\n";
105 assert(nband * nk * nbasis ==
write_value(ofs,
psi, nband, nk, nbasis));
111 std::ifstream ifs(filename +
"_" + std::to_string(rank) +
".dat");
112 int nbands, nks, nbasis;
113 ifs >> nbands >> nks >> nbasis;
115 assert(
psi.size() ==
read_value(ifs,
psi.get_pointer(), nbands, nks, nbasis));
119 template<
typename T >
122 assert(
psi.get_k_first() == 1);
123 for (
int ik = 0;ik <
psi.get_nk();++ik)
125 std::cout << label <<
": k " << ik <<
"\n";
126 for (
int ib = 0;ib <
psi.get_nbands();++ib)
128 std::cout <<
"ib=" << ib <<
": ";
129 for (
int i = 0;i <
psi.get_nbasis();++i)
131 std::cout <<
filter(
psi(ik, ib, i)) <<
" ";
140 std::cout << label <<
"\n";
147 std::cout << std::endl;
154 std::cout <<
"first " << nnz <<
" non-zero elements of " << label <<
"\n";
155 int inz = 0;
int i = 0;
156 while (inz < nnz && i < nrxx) {
if (rho[++i] - 0.0 >
threshold) { std::cout << rho[i] <<
" ";++inz; } };
160 using TC = std::array<int, 3>;
161 using TAC = std::pair<int, TC>;
163 using TLRIX = std::map<int, std::map<TAC, std::vector<T>>>;
168 std::cout << label <<
"\n";
169 for (
const auto& tmp1 : CsX)
171 const int& iat1 = tmp1.first;
172 for (
const auto& tmp2 : tmp1.second)
174 const int& iat2 = tmp2.first.first;
175 const auto& R = tmp2.first.second;
176 auto& t = tmp2.second;
177 const int nocc = t.size() / nvirt;
178 std::cout <<
"iat1=" << iat1 <<
" iat2=" << iat2 <<
" R=(" << R[0] <<
" " << R[1] <<
" " << R[2] <<
")\n";
179 for (
int io = 0;io < nocc;++io)
181 for (
int iv = 0;iv < nvirt;++iv) { std::cout <<
filter(t[io * nvirt + iv]) <<
" "; }
190 template <
typename T>
191 using TLRI = std::map<int, std::map<TAC, RI::Tensor<T>>>;
193 void print_CV(
const TLRI<T>& Cs,
const std::string& label,
const double&
threshold = 1e-10)
195 std::cout << label <<
"\n";
196 for (
const auto& tmp1 : Cs)
198 const int& iat1 = tmp1.first;
199 for (
const auto& tmp2 : tmp1.second)
201 const int& iat2 = tmp2.first.first;
202 const auto& R = tmp2.first.second;
203 auto& t = tmp2.second;
204 if (R !=
TC({ 0, 0, 0 })) {
continue;}
205 std::cout <<
"iat1=" << iat1 <<
" iat2=" << iat2 <<
" R=(" << R[0] <<
" " << R[1] <<
" " << R[2] <<
")\n";
206 if (t.shape.size() == 2)
208 for (
int iabf1 = 0;iabf1 < t.shape[0];++iabf1)
210 for (
int iabf2 = 0;iabf2 < t.shape[1];++iabf2)
212 std::cout <<
filter(t(iabf1, iabf2)) <<
" ";
217 else if (t.shape.size() == 3)
219 const int nabf = t.shape[0];
220 const int nw1 = t.shape[1];
221 const int nw2 = t.shape[2];
222 std::cout <<
"size: " << nabf <<
" " << nw1 <<
" " << nw2 <<
"\n";
223 for (
int iabf = 0;iabf < nabf;++iabf)
225 for (
int iw1 = 0;iw1 < nw1;++iw1)
227 for (
int iw2 = 0;iw2 < nw2;++iw2)
229 std::cout <<
filter(t(iabf, iw1, iw2)) <<
" ";
This class packs the basic information of 2D-block-cyclic parallel distribution of an arbitrary matri...
Definition parallel_2d.h:12
int get_row_size() const
number of local rows
Definition parallel_2d.h:21
int get_col_size() const
number of local columns
Definition parallel_2d.h:27
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
void * data() const
Get a pointer to the data buffer of the tensor.
Definition tensor.cpp:73
#define T
Definition exp.cpp:237
void print_psi_bandfirst(const psi::Psi< T > &psi, const std::string &label, const int &ib, const double &threshold=1e-10)
Definition lr_util_print.h:74
psi::Psi< T > read_psi_bandfirst(const std::string &filename, const int &rank)
Definition lr_util_print.h:109
void print_grid_nonzero(T *rho, const int &nrxx, const int &nnz, const std::string &label, const double &threshold=1e-5)
Definition lr_util_print.h:152
std::array< int, 3 > TC
Definition lr_util_print.h:160
void print_psi_kfirst(const psi::Psi< T > &psi, const std::string &label, const double &threshold=1e-10)
Definition lr_util_print.h:120
int read_value(std::ifstream &ifs, T *ptr, const int &size)
Definition lr_util_print.h:16
std::pair< int, TC > TAC
Definition lr_util_print.h:161
constexpr T filter(const T &v, const double &threshold=1e-10)
Definition lr_util_print.h:10
int write_value(std::ofstream &ofs, const T *ptr, const int &size)
Definition lr_util_print.h:34
std::map< int, std::map< TAC, std::vector< T > > > TLRIX
Definition lr_util_print.h:163
void write_psi_bandfirst(const psi::Psi< T > &psi, const std::string &filename, const int &rank, const double &threshold=1e-10, const int &precision=8)
Definition lr_util_print.h:89
void print_CsX(const TLRIX< T > &CsX, const int nvirt, const std::string &label, const double &threshold=1e-10)
Definition lr_util_print.h:166
int print_value(const T *ptr, const int &size)
Definition lr_util_print.h:58
void print_tensor(const container::Tensor &t, const std::string &label, const Parallel_2D *pmat, const double &threshold=1e-10)
Definition lr_util_print.h:138
std::map< int, std::map< TAC, RI::Tensor< T > > > TLRI
Definition ri_cv_io_test.cpp:12
file(GLOB ATen_CORE_SRCS "*.cpp") set(ATen_CPU_SRCS $
Definition CMakeLists.txt:1
#define threshold
Definition sph_bessel_recursive_test.cpp:4