Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,18 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
else if (this->add_hexx_type == Add_Hexx_Type::R)
{
// read in Hexx(R)
const std::string restart_HR_path = PARAM.globalv.global_readin_dir + "HexxR" + std::to_string(GlobalV::MY_RANK);
bool all_exist = true;
const std::string restart_HR_path = GlobalC::restart.folder + "HexxR" + std::to_string(GlobalV::MY_RANK);
int all_exist = 1;
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 (!ifs) { all_exist = 0; break; }
}
// Add MPI communication to synchronize all_exist across processes
#ifdef __MPI
// don't read in any files if one of the processes doesn't have it
MPI_Allreduce(MPI_IN_PLACE, &all_exist, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
#endif
if (all_exist)
{
// Read HexxR in CSR format
Expand All @@ -228,11 +233,24 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
{
// 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);
std::ifstream ifs(restart_HR_path_cereal, std::ios::binary);
int all_exist_cereal = ifs ? 1 : 0;
#ifdef __MPI
MPI_Allreduce(MPI_IN_PLACE, &all_exist_cereal, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
#endif
if (!all_exist_cereal)
{
//no HexxR file in CSR or binary format
this->restart = false;
}
else {
ModuleIO::read_Hexxs_cereal(restart_HR_path_cereal, *Hexxc);
else
{
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
31 changes: 26 additions & 5 deletions source/module_io/test/read_input_ptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ TEST_F(InputParaTest, ParaRead)

// comment out this part of tests, since Parameter is in another directory now, mohan 2025-05-18
// besides, the following tests will cause strange error in MPI_Finalize()
// I tried the following modification, it worked well in my own environment, but not in the Github test, Xinyuan 2025-05-25
/*
TEST_F(InputParaTest, Check)
{
Expand All @@ -458,20 +459,40 @@ TEST_F(InputParaTest, Check)
emptyfile << "stru_file ./support/STRU \n";
emptyfile.close();
}
MPI_Barrier(MPI_COMM_WORLD);

bool original_check_mode = ModuleIO::ReadInput::check_mode;
ModuleIO::ReadInput::check_mode = true;
ModuleIO::ReadInput readinput(GlobalV::MY_RANK);

//
Parameter param;
testing::internal::CaptureStdout();
EXPECT_EXIT(readinput.read_parameters(param, "./empty_INPUT"), ::testing::ExitedWithCode(0), "");
std::string output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output, testing::HasSubstr("INPUT parameters have been successfully checked!"));
//
try {
readinput.read_parameters(param, "./empty_INPUT");

// if exit normally with exit(0)
std::string output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output, testing::HasSubstr("INPUT parameters have been successfully checked!"));

} catch (const std::exception& e) {
// if exit with error, then the test is failed
std::cerr << "Rank " << GlobalV::MY_RANK << " error: " << e.what() << std::endl;
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
} catch (...) {
// if exit with unknown error, then the test is failed
std::cerr << "Rank " << GlobalV::MY_RANK << " unknown error." << std::endl;
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
// Note : the EXPECT_EXIT is not working with MPI, so we use try-catch to test the exit
// EXPECT_EXIT(readinput.read_parameters(param, "./empty_INPUT"), ::testing::ExitedWithCode(0), "");
// std::string output = testing::internal::GetCapturedStdout();
// EXPECT_THAT(output, testing::HasSubstr("INPUT parameters have been successfully checked!"));
MPI_Barrier(MPI_COMM_WORLD);
if (GlobalV::MY_RANK == 0)
{
EXPECT_TRUE(std::remove("./empty_INPUT") == 0);
}
ModuleIO::ReadInput::check_mode = original_check_mode;
}
*/

Expand Down
Loading