@@ -104,15 +104,40 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
104104 if (PARAM.inp .calculation == " nscf" && GlobalC::exx_info.info_global .cal_exx )
105105 { // if nscf, read HexxR first and reallocate hR according to the read-in HexxR
106106 const std::string file_name_exx = PARAM.globalv .global_readin_dir + " HexxR" + std::to_string (GlobalV::MY_RANK);
107- if (GlobalC::exx_info.info_ri .real_number )
107+ bool all_exist = true ;
108+ for (int is=0 ;is<PARAM.inp .nspin ;++is)
109+ {
110+ std::ifstream ifs (file_name_exx + " _" + std::to_string (is) + " .csr" );
111+ if (!ifs) { all_exist = false ; break ; }
112+ }
113+ if (all_exist)
108114 {
109- ModuleIO::read_Hexxs_csr (file_name_exx, GlobalC::ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxd);
110- if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxd, this ->hR ); }
115+ // Read HexxR in CSR format
116+ if (GlobalC::exx_info.info_ri .real_number )
117+ {
118+ ModuleIO::read_Hexxs_csr (file_name_exx, GlobalC::ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxd);
119+ if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxd, this ->hR ); }
120+ }
121+ else
122+ {
123+ ModuleIO::read_Hexxs_csr (file_name_exx, GlobalC::ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxc);
124+ if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxc, this ->hR ); }
125+ }
111126 }
112127 else
113128 {
114- ModuleIO::read_Hexxs_csr (file_name_exx, GlobalC::ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxc);
115- if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxc, this ->hR ); }
129+ // Read HexxR in binary format (old version)
130+ const std::string file_name_exx_cereal = PARAM.globalv .global_readin_dir + " HexxR_" + std::to_string (GlobalV::MY_RANK);
131+ if (GlobalC::exx_info.info_ri .real_number )
132+ {
133+ ModuleIO::read_Hexxs_cereal (file_name_exx_cereal, *Hexxd);
134+ if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxd, this ->hR ); }
135+ }
136+ else
137+ {
138+ ModuleIO::read_Hexxs_cereal (file_name_exx_cereal, *Hexxc);
139+ if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxc, this ->hR ); }
140+ }
116141 }
117142 this ->use_cell_nearest = false ;
118143 }
@@ -181,11 +206,32 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
181206 {
182207 // read in Hexx(R)
183208 const std::string restart_HR_path = GlobalC::restart.folder + " HexxR" + std::to_string (GlobalV::MY_RANK);
184- if (GlobalC::exx_info.info_ri .real_number ) {
185- ModuleIO::read_Hexxs_csr (restart_HR_path, GlobalC::ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxd);
209+ bool all_exist = true ;
210+ for (int is = 0 ; is < PARAM.inp .nspin ; ++is)
211+ {
212+ std::ifstream ifs (restart_HR_path + " _" + std::to_string (is) + " .csr" );
213+ if (!ifs) { all_exist = false ; break ; }
214+ }
215+ if (all_exist)
216+ {
217+ // Read HexxR in CSR format
218+ if (GlobalC::exx_info.info_ri .real_number ) {
219+ ModuleIO::read_Hexxs_csr (restart_HR_path, GlobalC::ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxd);
220+ }
221+ else {
222+ ModuleIO::read_Hexxs_csr (restart_HR_path, GlobalC::ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxc);
223+ }
186224 }
187- else {
188- ModuleIO::read_Hexxs_csr (restart_HR_path, GlobalC::ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxc);
225+ else
226+ {
227+ // Read HexxR in binary format (old version)
228+ const std::string restart_HR_path_cereal = GlobalC::restart.folder + " HexxR_" + std::to_string (GlobalV::MY_RANK);
229+ if (GlobalC::exx_info.info_ri .real_number ) {
230+ ModuleIO::read_Hexxs_cereal (restart_HR_path_cereal, *Hexxd);
231+ }
232+ else {
233+ ModuleIO::read_Hexxs_cereal (restart_HR_path_cereal, *Hexxc);
234+ }
189235 }
190236 }
191237
0 commit comments