@@ -207,13 +207,18 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
207207 else if (this ->add_hexx_type == Add_Hexx_Type::R)
208208 {
209209 // read in Hexx(R)
210- const std::string restart_HR_path = PARAM. globalv . global_readin_dir + " HexxR" + std::to_string (GlobalV::MY_RANK);
211- bool all_exist = true ;
210+ const std::string restart_HR_path = GlobalC::restart. folder + " HexxR" + std::to_string (GlobalV::MY_RANK);
211+ int all_exist = 1 ;
212212 for (int is = 0 ; is < PARAM.inp .nspin ; ++is)
213213 {
214214 std::ifstream ifs (restart_HR_path + " _" + std::to_string (is) + " .csr" );
215- if (!ifs) { all_exist = false ; break ; }
215+ if (!ifs) { all_exist = 0 ; break ; }
216216 }
217+ // Add MPI communication to synchronize all_exist across processes
218+ #ifdef __MPI
219+ // don't read in any files if one of the processes doesn't have it
220+ MPI_Allreduce (MPI_IN_PLACE, &all_exist, 1 , MPI_INT, MPI_MIN, MPI_COMM_WORLD);
221+ #endif
217222 if (all_exist)
218223 {
219224 // Read HexxR in CSR format
@@ -228,11 +233,24 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
228233 {
229234 // Read HexxR in binary format (old version)
230235 const std::string restart_HR_path_cereal = GlobalC::restart.folder + " HexxR_" + std::to_string (GlobalV::MY_RANK);
231- if (GlobalC::exx_info.info_ri .real_number ) {
232- ModuleIO::read_Hexxs_cereal (restart_HR_path_cereal, *Hexxd);
236+ std::ifstream ifs (restart_HR_path_cereal, std::ios::binary);
237+ int all_exist_cereal = ifs ? 1 : 0 ;
238+ #ifdef __MPI
239+ MPI_Allreduce (MPI_IN_PLACE, &all_exist_cereal, 1 , MPI_INT, MPI_MIN, MPI_COMM_WORLD);
240+ #endif
241+ if (!all_exist_cereal)
242+ {
243+ // no HexxR file in CSR or binary format
244+ this ->restart = false ;
233245 }
234- else {
235- ModuleIO::read_Hexxs_cereal (restart_HR_path_cereal, *Hexxc);
246+ else
247+ {
248+ if (GlobalC::exx_info.info_ri .real_number ) {
249+ ModuleIO::read_Hexxs_cereal (restart_HR_path_cereal, *Hexxd);
250+ }
251+ else {
252+ ModuleIO::read_Hexxs_cereal (restart_HR_path_cereal, *Hexxc);
253+ }
236254 }
237255 }
238256 }
0 commit comments