@@ -82,13 +82,13 @@ template <typename TK, typename TR>
8282OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
8383 HContainer<TR>*hR_in,
8484 const UnitCell& ucell_in,
85- const K_Vectors& kv_in,
86- std::vector<std::map<int , std::map<TAC, RI::Tensor<double >>>>* Hexxd_in,
87- std::vector<std::map<int , std::map<TAC, RI::Tensor<std::complex <double >>>>>* Hexxc_in,
85+ const K_Vectors& kv_in,
86+ std::vector<std::map<int , std::map<TAC, RI::Tensor<double >>>>* Hexxd_in,
87+ std::vector<std::map<int , std::map<TAC, RI::Tensor<std::complex <double >>>>>* Hexxc_in,
8888 Add_Hexx_Type add_hexx_type_in,
8989 const int istep,
9090 int * two_level_step_in,
91- const bool restart_in)
91+ const bool restart_in)
9292 : OperatorLCAO<TK, TR>(hsk_in, kv_in.kvec_d, hR_in),
9393 ucell (ucell_in),
9494 kv(kv_in),
@@ -105,42 +105,75 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
105105
106106 if (PARAM.inp .calculation == " nscf" && GlobalC::exx_info.info_global .cal_exx )
107107 { // if nscf, read HexxR first and reallocate hR according to the read-in HexxR
108- const std::string file_name_exx = PARAM.globalv .global_readin_dir + " HexxR" + std::to_string (GlobalV::MY_RANK);
109- bool all_exist = true ;
110- for (int is=0 ;is<PARAM.inp .nspin ;++is)
108+ auto file_name_list_csr = []() -> std::vector<std::string>
111109 {
112- std::ifstream ifs (file_name_exx + " _" + std::to_string (is) + " .csr" );
113- if (!ifs) { all_exist = false ; break ; }
114- }
115- if (all_exist)
110+ std::vector<std::string> file_name_list;
111+ for (int irank=0 ; irank<PARAM.globalv .nproc ; ++irank) {
112+ for (int is=0 ;is<PARAM.inp .nspin ;++is) {
113+ file_name_list.push_back ( PARAM.globalv .global_readin_dir + " HexxR" + std::to_string (irank) + " _" + std::to_string (is) + " .csr" );
114+ } }
115+ return file_name_list;
116+ };
117+ auto file_name_list_cereal = []() -> std::vector<std::string>
118+ {
119+ std::vector<std::string> file_name_list;
120+ for (int irank=0 ; irank<PARAM.globalv .nproc ; ++irank)
121+ { file_name_list.push_back ( " HexxR_" + std::to_string (irank) ); }
122+ return file_name_list;
123+ };
124+ auto check_exist = [](const std::vector<std::string> &file_name_list) -> bool
125+ {
126+ for (const std::string &file_name : file_name_list)
127+ {
128+ std::ifstream ifs (file_name);
129+ if (!ifs.is_open ())
130+ { return false ; }
131+ }
132+ return true ;
133+ };
134+
135+ std::cout<<" Attention: The number of MPI processes must be strictly identical between SCF and NSCF when computing exact-exchange." <<std::endl;
136+ if (check_exist (file_name_list_csr ()))
116137 {
138+ const std::string file_name_exx_csr = PARAM.globalv .global_readin_dir + " HexxR" + std::to_string (PARAM.globalv .myrank );
117139 // Read HexxR in CSR format
118140 if (GlobalC::exx_info.info_ri .real_number )
119141 {
120- ModuleIO::read_Hexxs_csr (file_name_exx, ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxd);
121- if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxd, this ->hR ); }
142+ ModuleIO::read_Hexxs_csr (file_name_exx_csr, ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxd);
143+ if (this ->add_hexx_type == Add_Hexx_Type::R)
144+ { reallocate_hcontainer (*Hexxd, this ->hR ); }
122145 }
123146 else
124147 {
125- ModuleIO::read_Hexxs_csr (file_name_exx, ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxc);
126- if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxc, this ->hR ); }
148+ ModuleIO::read_Hexxs_csr (file_name_exx_csr, ucell, PARAM.inp .nspin , PARAM.globalv .nlocal , *Hexxc);
149+ if (this ->add_hexx_type == Add_Hexx_Type::R)
150+ { reallocate_hcontainer (*Hexxc, this ->hR ); }
127151 }
128152 }
129- else
153+ else if ( check_exist ( file_name_list_cereal ()))
130154 {
131155 // Read HexxR in binary format (old version)
132- const std::string file_name_exx_cereal = PARAM.globalv .global_readin_dir + " HexxR_" + std::to_string (GlobalV::MY_RANK);
156+ const std::string file_name_exx_cereal = PARAM.globalv .global_readin_dir + " HexxR_" + std::to_string (PARAM.globalv .myrank );
157+ std::ifstream ifs (file_name_exx_cereal, std::ios::binary);
158+ if (!ifs)
159+ { ModuleBase::WARNING_QUIT (" OperatorEXX" , " Can't open EXX file < " + file_name_exx_cereal + " >." ); }
133160 if (GlobalC::exx_info.info_ri .real_number )
134161 {
135162 ModuleIO::read_Hexxs_cereal (file_name_exx_cereal, *Hexxd);
136- if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxd, this ->hR ); }
163+ if (this ->add_hexx_type == Add_Hexx_Type::R)
164+ { reallocate_hcontainer (*Hexxd, this ->hR ); }
137165 }
138166 else
139167 {
140168 ModuleIO::read_Hexxs_cereal (file_name_exx_cereal, *Hexxc);
141- if (this ->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer (*Hexxc, this ->hR ); }
169+ if (this ->add_hexx_type == Add_Hexx_Type::R)
170+ { reallocate_hcontainer (*Hexxc, this ->hR ); }
142171 }
143172 }
173+ else
174+ {
175+ ModuleBase::WARNING_QUIT (" OperatorEXX" , " Can't open EXX file in " + PARAM.globalv .global_readin_dir );
176+ }
144177 this ->use_cell_nearest = false ;
145178 }
146179 else
@@ -207,7 +240,7 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
207240 else if (this ->add_hexx_type == Add_Hexx_Type::R)
208241 {
209242 // read in Hexx(R)
210- const std::string restart_HR_path = PARAM.globalv .global_readin_dir + " HexxR" + std::to_string (GlobalV::MY_RANK );
243+ const std::string restart_HR_path = PARAM.globalv .global_readin_dir + " HexxR" + std::to_string (PARAM. globalv . myrank );
211244 bool all_exist = true ;
212245 for (int is = 0 ; is < PARAM.inp .nspin ; ++is)
213246 {
@@ -227,7 +260,7 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
227260 else
228261 {
229262 // Read HexxR in binary format (old version)
230- const std::string restart_HR_path_cereal = GlobalC::restart.folder + " HexxR_" + std::to_string (GlobalV::MY_RANK );
263+ const std::string restart_HR_path_cereal = GlobalC::restart.folder + " HexxR_" + std::to_string (PARAM. globalv . myrank );
231264 if (GlobalC::exx_info.info_ri .real_number ) {
232265 ModuleIO::read_Hexxs_cereal (restart_HR_path_cereal, *Hexxd);
233266 }
0 commit comments