Skip to content

Commit 4ff7cff

Browse files
authored
Fix warning when there is no plane wave for current k point (#7282)
1 parent c4abc01 commit 4ff7cff

4 files changed

Lines changed: 75 additions & 3 deletions

File tree

source/source_base/tool_quit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
133133
void CHECK_WARNING_QUIT(const bool error_in, const std::string &file,const std::string &calculation,const std::string &description)
134134
{
135135
#ifdef __NORMAL
136-
// only for UT, do nothing here
136+
if(error_in) std::cout << description << std::endl;
137137
#else
138138
if(error_in)
139139
{

source/source_basis/module_pw/pw_basis_k.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,19 @@ void PW_Basis_K::setupIndGk()
145145
}
146146
}
147147
this->npwk[ik] = ng;
148+
int ng_global_k = ng;
149+
#ifdef __MPI
150+
MPI_Allreduce(MPI_IN_PLACE, &ng_global_k, 1, MPI_INT, MPI_SUM, this->pool_world);
151+
#endif
152+
const char* no_pw_message = "Current core has no plane waves! Please reduce the cores.";
153+
if (ng_global_k == 0)
154+
{
155+
no_pw_message = "No plane waves are available for this k-point across the whole pool. Please increase ecutwfc or check KPT settings.";
156+
}
148157
ModuleBase::CHECK_WARNING_QUIT((ng == 0),
149158
"pw_basis_k.cpp",
150159
PARAM.inp.calculation,
151-
"Current core has no plane waves! Please reduce the cores.");
160+
no_pw_message);
152161
if (this->npwk_max < ng)
153162
{
154163
this->npwk_max = ng;

source/source_basis/module_pw/pw_distributeg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ void PW_Basis::distribute_g()
2525
{
2626
ModuleBase::WARNING_QUIT("divide", "No such division type.");
2727
}
28+
const char* no_pw_message = "Current core has no plane waves! Please reduce the cores.";
2829
ModuleBase::CHECK_WARNING_QUIT((this->npw == 0), "pw_distributeg.cpp", PARAM.inp.calculation,
29-
"Current core has no plane waves! Please reduce the cores.");
30+
no_pw_message);
3031
ModuleBase::timer::end(this->classname, "distributeg");
3132
return;
3233
}

source/source_basis/module_pw/test/test-other.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,66 @@ TEST_F(PWTEST,test_other)
139139
#ifdef __ENABLE_FLOAT_FFTW
140140
fftwf_cleanup();
141141
#endif
142+
}
143+
144+
TEST_F(PWTEST, test_no_plane_wave_message_global_empty_k)
145+
{
146+
ModulePW::PW_Basis_K pwktest(device_flag, precision_flag);
147+
ModuleBase::Matrix3 latvec(0.2, 0, 0, 0, 1, 0, 0, 0, 1);
148+
#ifdef __MPI
149+
pwktest.initmpi(nproc_in_pool, rank_in_pool, POOL_WORLD);
150+
#endif
151+
const int nks = 1;
152+
ModuleBase::Vector3<double> kvec_d[nks];
153+
kvec_d[0].set(0.5, 0.5, 0.5);
154+
155+
pwktest.initgrids(2, latvec, 4, 4, 4);
156+
pwktest.initparameters(true, 1e-4, nks, kvec_d);
157+
testing::internal::CaptureStdout();
158+
pwktest.setuptransform();
159+
std::string output = testing::internal::GetCapturedStdout();
160+
161+
EXPECT_THAT(output,
162+
testing::HasSubstr("No plane waves are available for this k-point across the whole pool. Please increase ecutwfc or check KPT settings."));
163+
}
164+
165+
TEST_F(PWTEST, test_no_plane_wave_message_parallel_local_empty)
166+
{
167+
#ifndef __MPI
168+
GTEST_SKIP() << "Requires MPI ranks to simulate local-empty but global-nonempty case.";
169+
#else
170+
if (nproc_in_pool <= 1)
171+
{
172+
GTEST_SKIP() << "Requires more than one MPI rank.";
173+
}
174+
175+
ModulePW::PW_Basis_K pwktest(device_flag, precision_flag);
176+
ModuleBase::Matrix3 latvec(0.2, 0, 0, 0, 1, 0, 0, 0, 1);
177+
pwktest.initmpi(nproc_in_pool, rank_in_pool, POOL_WORLD);
178+
179+
const int nks = 1;
180+
ModuleBase::Vector3<double> kvec_d[nks];
181+
kvec_d[0].set(0.0, 0.0, 0.0);
182+
183+
pwktest.initgrids(2, latvec, 4, 4, 4);
184+
pwktest.initparameters(true, 8.0, nks, kvec_d);
185+
testing::internal::CaptureStdout();
186+
pwktest.setuptransform();
187+
std::string output = testing::internal::GetCapturedStdout();
188+
189+
const int local_npwk = pwktest.npwk[0];
190+
int global_npwk = local_npwk;
191+
MPI_Allreduce(MPI_IN_PLACE, &global_npwk, 1, MPI_INT, MPI_SUM, POOL_WORLD);
192+
193+
const int local_target_rank = (local_npwk == 0 && global_npwk > 0) ? 1 : 0;
194+
int any_target_rank = local_target_rank;
195+
MPI_Allreduce(MPI_IN_PLACE, &any_target_rank, 1, MPI_INT, MPI_MAX, POOL_WORLD);
196+
EXPECT_EQ(any_target_rank, 1);
197+
198+
if (local_target_rank == 1)
199+
{
200+
EXPECT_THAT(output,
201+
testing::HasSubstr("Current core has no plane waves! Please reduce the cores."));
202+
}
203+
#endif
142204
}

0 commit comments

Comments
 (0)