Skip to content
Merged
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
2 changes: 1 addition & 1 deletion source/source_base/tool_quit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
void CHECK_WARNING_QUIT(const bool error_in, const std::string &file,const std::string &calculation,const std::string &description)
{
#ifdef __NORMAL
// only for UT, do nothing here
if(error_in) std::cout << description << std::endl;
#else
if(error_in)
{
Expand Down
11 changes: 10 additions & 1 deletion source/source_basis/module_pw/pw_basis_k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,19 @@ void PW_Basis_K::setupIndGk()
}
}
this->npwk[ik] = ng;
int ng_global_k = ng;
#ifdef __MPI
MPI_Allreduce(MPI_IN_PLACE, &ng_global_k, 1, MPI_INT, MPI_SUM, this->pool_world);
#endif
const char* no_pw_message = "Current core has no plane waves! Please reduce the cores.";
if (ng_global_k == 0)
{
no_pw_message = "No plane waves are available for this k-point across the whole pool. Please increase ecutwfc or check KPT settings.";
}
ModuleBase::CHECK_WARNING_QUIT((ng == 0),
"pw_basis_k.cpp",
PARAM.inp.calculation,
"Current core has no plane waves! Please reduce the cores.");
no_pw_message);
if (this->npwk_max < ng)
{
this->npwk_max = ng;
Expand Down
3 changes: 2 additions & 1 deletion source/source_basis/module_pw/pw_distributeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ void PW_Basis::distribute_g()
{
ModuleBase::WARNING_QUIT("divide", "No such division type.");
}
const char* no_pw_message = "Current core has no plane waves! Please reduce the cores.";
ModuleBase::CHECK_WARNING_QUIT((this->npw == 0), "pw_distributeg.cpp", PARAM.inp.calculation,
"Current core has no plane waves! Please reduce the cores.");
no_pw_message);
ModuleBase::timer::end(this->classname, "distributeg");
return;
}
Expand Down
62 changes: 62 additions & 0 deletions source/source_basis/module_pw/test/test-other.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,66 @@ TEST_F(PWTEST,test_other)
#ifdef __ENABLE_FLOAT_FFTW
fftwf_cleanup();
#endif
}

TEST_F(PWTEST, test_no_plane_wave_message_global_empty_k)
{
ModulePW::PW_Basis_K pwktest(device_flag, precision_flag);
ModuleBase::Matrix3 latvec(0.2, 0, 0, 0, 1, 0, 0, 0, 1);
#ifdef __MPI
pwktest.initmpi(nproc_in_pool, rank_in_pool, POOL_WORLD);
#endif
const int nks = 1;
ModuleBase::Vector3<double> kvec_d[nks];
kvec_d[0].set(0.5, 0.5, 0.5);

pwktest.initgrids(2, latvec, 4, 4, 4);
pwktest.initparameters(true, 1e-4, nks, kvec_d);
testing::internal::CaptureStdout();
pwktest.setuptransform();
std::string output = testing::internal::GetCapturedStdout();

EXPECT_THAT(output,
testing::HasSubstr("No plane waves are available for this k-point across the whole pool. Please increase ecutwfc or check KPT settings."));
}

TEST_F(PWTEST, test_no_plane_wave_message_parallel_local_empty)
{
#ifndef __MPI
GTEST_SKIP() << "Requires MPI ranks to simulate local-empty but global-nonempty case.";
#else
if (nproc_in_pool <= 1)
{
GTEST_SKIP() << "Requires more than one MPI rank.";
}

ModulePW::PW_Basis_K pwktest(device_flag, precision_flag);
ModuleBase::Matrix3 latvec(0.2, 0, 0, 0, 1, 0, 0, 0, 1);
pwktest.initmpi(nproc_in_pool, rank_in_pool, POOL_WORLD);

const int nks = 1;
ModuleBase::Vector3<double> kvec_d[nks];
kvec_d[0].set(0.0, 0.0, 0.0);

pwktest.initgrids(2, latvec, 4, 4, 4);
pwktest.initparameters(true, 8.0, nks, kvec_d);
testing::internal::CaptureStdout();
pwktest.setuptransform();
std::string output = testing::internal::GetCapturedStdout();

const int local_npwk = pwktest.npwk[0];
int global_npwk = local_npwk;
MPI_Allreduce(MPI_IN_PLACE, &global_npwk, 1, MPI_INT, MPI_SUM, POOL_WORLD);

const int local_target_rank = (local_npwk == 0 && global_npwk > 0) ? 1 : 0;
int any_target_rank = local_target_rank;
MPI_Allreduce(MPI_IN_PLACE, &any_target_rank, 1, MPI_INT, MPI_MAX, POOL_WORLD);
EXPECT_EQ(any_target_rank, 1);

if (local_target_rank == 1)
{
EXPECT_THAT(output,
testing::HasSubstr("Current core has no plane waves! Please reduce the cores."));
}
#endif
}
Loading