diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp index c4c01f9cde..13572cc8e9 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp @@ -104,15 +104,40 @@ OperatorEXX>::OperatorEXX(HS_Matrix_K* 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;isadd_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; } @@ -181,11 +206,32 @@ OperatorEXX>::OperatorEXX(HS_Matrix_K* 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); + } } } diff --git a/source/module_io/restart_exx_csr.h b/source/module_io/restart_exx_csr.h index 7dbb778c2b..1eab69f4ef 100644 --- a/source/module_io/restart_exx_csr.h +++ b/source/module_io/restart_exx_csr.h @@ -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 #include @@ -15,6 +16,11 @@ namespace ModuleIO const int nspin, const int nbasis, std::vector>>>& Hexxs); + /// read Hexxs in cereal format + template + void read_Hexxs_cereal(const std::string& file_name, + std::vector>>>& Hexxs); + /// write Hexxs in CSR format template void write_Hexxs_csr(const std::string& file_name, const UnitCell& ucell, diff --git a/source/module_io/restart_exx_csr.hpp b/source/module_io/restart_exx_csr.hpp index e18a9d5a8d..6f6f3dd2ae 100644 --- a/source/module_io/restart_exx_csr.hpp +++ b/source/module_io/restart_exx_csr.hpp @@ -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 #include @@ -49,6 +50,18 @@ namespace ModuleIO } } + template + void read_Hexxs_cereal(const std::string& file_name, + std::vector>>>& 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 std::map, std::map>> calculate_RI_Tensor_sparse(const double& sparse_threshold,