Skip to content

Fix: if restart but can't find Hexx files, warning and run as usual (automatically initialized the density) #6194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 18 additions & 3 deletions source/module_io/test/read_input_ptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,24 @@ TEST_F(InputParaTest, Check)
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
FAIL() << "read_parameters threw an exception: " << e.what();
} catch (...) {
// if exit with unknown error, then the test is failed
FAIL() << "read_parameters threw an unknown exception.";
}
// 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!"));
if (GlobalV::MY_RANK == 0)
{
EXPECT_TRUE(std::remove("./empty_INPUT") == 0);
Expand Down
Loading