Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,40 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
if (PARAM.inp.calculation == "nscf" && GlobalC::exx_info.info_global.cal_exx)
{ // if nscf, read HexxR first and reallocate hR according to the read-in HexxR
const std::string file_name_exx = PARAM.globalv.global_readin_dir + "HexxR" + std::to_string(GlobalV::MY_RANK);
if (GlobalC::exx_info.info_ri.real_number)
bool all_exist = true;
for (int is=0;is<PARAM.inp.nspin;++is)
{
std::ifstream ifs(file_name_exx + "_" + std::to_string(is) + ".csr");
if (!ifs) { all_exist = false; break; }
}
if (all_exist)
{
ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxd);
if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxd, this->hR); }
// Read HexxR in CSR format
if (GlobalC::exx_info.info_ri.real_number)
{
ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxd);
if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxd, this->hR); }
}
else
{
ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxc);
if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxc, this->hR); }
}
}
else
{
ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxc);
if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxc, this->hR); }
// Read HexxR in binary format (old version)
const std::string file_name_exx_cereal = PARAM.globalv.global_readin_dir + "HexxR_" + std::to_string(GlobalV::MY_RANK);
if (GlobalC::exx_info.info_ri.real_number)
{
ModuleIO::read_Hexxs_cereal(file_name_exx_cereal, *Hexxd);
if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxd, this->hR); }
}
else
{
ModuleIO::read_Hexxs_cereal(file_name_exx_cereal, *Hexxc);
if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxc, this->hR); }
}
}
this->use_cell_nearest = false;
}
Expand Down Expand Up @@ -181,11 +206,32 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
{
// read in Hexx(R)
const std::string restart_HR_path = GlobalC::restart.folder + "HexxR" + std::to_string(GlobalV::MY_RANK);
if (GlobalC::exx_info.info_ri.real_number) {
ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxd);
bool all_exist = true;
for (int is = 0; is < PARAM.inp.nspin; ++is)
{
std::ifstream ifs(restart_HR_path + "_" + std::to_string(is) + ".csr");
if (!ifs) { all_exist = false; break; }
}
if (all_exist)
{
// Read HexxR in CSR format
if (GlobalC::exx_info.info_ri.real_number) {
ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxd);
}
else {
ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxc);
}
}
else {
ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxc);
else
{
// Read HexxR in binary format (old version)
const std::string restart_HR_path_cereal = GlobalC::restart.folder + "HexxR_" + std::to_string(GlobalV::MY_RANK);
if (GlobalC::exx_info.info_ri.real_number) {
ModuleIO::read_Hexxs_cereal(restart_HR_path_cereal, *Hexxd);
}
else {
ModuleIO::read_Hexxs_cereal(restart_HR_path_cereal, *Hexxc);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions source/module_io/restart_exx_csr.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "module_base/abfs-vector3_order.h"
#include "module_cell/unitcell.h"
#include "module_ri/serialization_cereal.h"
#include <RI/global/Tensor.h>
#include <map>

Expand All @@ -15,6 +16,11 @@ namespace ModuleIO
const int nspin, const int nbasis,
std::vector<std::map<int, std::map<TAC, RI::Tensor<Tdata>>>>& Hexxs);

/// read Hexxs in cereal format
template<typename Tdata>
void read_Hexxs_cereal(const std::string& file_name,
std::vector<std::map<int, std::map<TAC, RI::Tensor<Tdata>>>>& Hexxs);

/// write Hexxs in CSR format
template<typename Tdata>
void write_Hexxs_csr(const std::string& file_name, const UnitCell& ucell,
Expand Down
13 changes: 13 additions & 0 deletions source/module_io/restart_exx_csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "module_cell/unitcell.h"
#include "module_io/csr_reader.h"
#include "module_io/write_HS_sparse.h"
#include "module_ri/serialization_cereal.h"
#include <RI/global/Tensor.h>
#include <map>

Expand Down Expand Up @@ -49,6 +50,18 @@ namespace ModuleIO
}
}

template<typename Tdata>
void read_Hexxs_cereal(const std::string& file_name,
std::vector<std::map<int, std::map<TAC, RI::Tensor<Tdata>>>>& Hexxs)
{
ModuleBase::TITLE("Exx_LRI", "read_Hexxs_cereal");
ModuleBase::timer::tick("Exx_LRI", "read_Hexxs_cereal");
std::ifstream ifs(file_name, std::ios::binary);
cereal::BinaryInputArchive iar(ifs);
iar(Hexxs);
ModuleBase::timer::tick("Exx_LRI", "read_Hexxs_cereal");
}

template<typename Tdata>
std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, Tdata>>>
calculate_RI_Tensor_sparse(const double& sparse_threshold,
Expand Down
Loading