Skip to content

Commit 754a300

Browse files
authored
Merge pull request #1183 from dyzheng/develop
Fix: Veff error when MPI_threads larger than nz
2 parents cc952b2 + 8e7040e commit 754a300

File tree

17 files changed

+145
-22
lines changed

17 files changed

+145
-22
lines changed

source/input.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ void Input::Default(void)
408408
// test only
409409
//==========================================================
410410
test_just_neighbor = false;
411+
test_skip_ewald = false;
411412

412413
//==========================================================
413414
// DFT+U Xin Qu added on 2020-10-29
@@ -1510,6 +1511,10 @@ bool Input::Read(const std::string &fn)
15101511
{
15111512
read_value(ifs, test_just_neighbor);
15121513
}
1514+
else if (strcmp("test_skip_ewald", word) == 0)
1515+
{
1516+
read_value(ifs, test_skip_ewald);
1517+
}
15131518
//--------------
15141519
//----------------------------------------------------------------------------------
15151520
// Xin Qu added on 2020-10-29 for DFT+U
@@ -2213,6 +2218,7 @@ void Input::Bcast()
22132218
Parallel_Common::bcast_int(td_vextout);
22142219
Parallel_Common::bcast_int(td_dipoleout);
22152220
Parallel_Common::bcast_bool(test_just_neighbor);
2221+
Parallel_Common::bcast_bool(test_skip_ewald);
22162222
Parallel_Common::bcast_int(GlobalV::ocp);
22172223
Parallel_Common::bcast_string(GlobalV::ocp_set);
22182224
Parallel_Common::bcast_int(out_mul); // qifeng add 2019/9/10

source/input.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ class Input
422422
//==========================================================
423423
// variables for test only
424424
//==========================================================
425-
bool test_just_neighbor;
425+
bool test_just_neighbor = false;
426+
bool test_skip_ewald = false;
426427

427428
private:
428429
//==========================================================

source/input_conv.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ void Input_Conv::Convert(void)
135135
GlobalV::VION_IN_H = INPUT.vion_in_h;
136136
GlobalV::TEST_FORCE = INPUT.test_force;
137137
GlobalV::TEST_STRESS = INPUT.test_stress;
138+
GlobalV::test_skip_ewald = INPUT.test_skip_ewald;
138139

139140
//----------------------------------------------------------
140141
// iteration (1/3)

source/module_base/global_variable.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ int test_wf = 0;
157157
int test_charge = 0;
158158
int test_potential = 0;
159159
int test_energy = 0;
160+
// for test purpose, skip ewald calculation
161+
bool test_skip_ewald = false;
160162
//----------------------------------------------------------
161163
// src_lcao
162164
//----------------------------------------------------------

source/module_base/global_variable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ extern int test_wf;
180180
extern int test_charge;
181181
extern int test_potential;
182182
extern int test_energy;
183+
extern bool test_skip_ewald;
183184
//==========================================================
184185
// src_onscaling
185186
//==========================================================

source/module_base/tool_quit.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,25 @@ void WARNING_QUIT(const std::string &file,const std::string &description)
128128
QUIT();
129129
}
130130

131+
132+
//Input judgement and communicate , if any judgement is true, do WARNING_QUIT
133+
void CHECK_WARNING_QUIT(bool error_in, const std::string &file,const std::string &description)
134+
{
135+
int error = (int)error_in;
136+
#ifdef __NORMAL
137+
// only for UT, do nothing here
138+
#else
139+
#ifdef __MPI
140+
int error_max = error;
141+
MPI_Reduce(&error, &error_max, 1, MPI_INT, MPI_MAX, 0, MPI_COMM_WORLD);
142+
MPI_Bcast(&error_max, 1, MPI_INT, 0, MPI_COMM_WORLD);
143+
error = error_max;
144+
#endif
145+
#endif
146+
if(error)
147+
{
148+
WARNING_QUIT(file, description);
149+
}
150+
}
151+
131152
}

source/module_base/tool_quit.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ void QUIT(void);
4343
*/
4444
void WARNING_QUIT(const std::string &file, const std::string &description);
4545

46+
/**
47+
* @brief Check, if true, WARNING_QUIT
48+
*
49+
* @param file The file where warning happens
50+
* @param description The warning information
51+
*/
52+
void CHECK_WARNING_QUIT(bool error, const std::string &file,const std::string &description);
53+
4654
} // namespace ModuleBase
4755

4856
#endif

source/module_esolver/esolver_ks_lcao_elec.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,10 @@ namespace ModuleESolver
256256
#endif
257257
// 1. calculate ewald energy.
258258
// mohan update 2021-02-25
259-
H_Ewald_pw::compute_ewald(GlobalC::ucell, GlobalC::rhopw);
259+
if(!GlobalV::test_skip_ewald)
260+
{
261+
H_Ewald_pw::compute_ewald(GlobalC::ucell, GlobalC::rhopw);
262+
}
260263

261264
//2. the electron charge density should be symmetrized,
262265
// here is the initialization

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ namespace ModuleESolver
180180
}
181181

182182
//calculate ewald energy
183-
H_Ewald_pw::compute_ewald(GlobalC::ucell, GlobalC::rhopw);
183+
if(!GlobalV::test_skip_ewald)
184+
{
185+
H_Ewald_pw::compute_ewald(GlobalC::ucell, GlobalC::rhopw);
186+
}
184187
//Symmetry_rho should be moved to Init()
185188
Symmetry_rho srho;
186189
for (int is = 0; is < GlobalV::NSPIN; is++)

source/module_hamilt/ks_pw/veff_pw.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,38 +46,47 @@ void Veff<OperatorPW>::act
4646
{
4747
if (this->npol == 1)
4848
{
49-
const double* current_veff = &(this->veff[0](current_spin, 0));
5049
wfcpw->recip2real(tmpsi_in, porter, ik);
51-
for (int ir = 0; ir < this->veff->nc; ++ir)
50+
// NOTICE: when MPI threads are larger than number of Z grids
51+
// veff would contain nothing, and nothing should be done in real space
52+
// but the 3DFFT can not be skipped, it will cause hanging
53+
if(this->veff->nc != 0)
5254
{
53-
porter[ir] *= current_veff[ir];
55+
const double* current_veff = &(this->veff[0](current_spin, 0));
56+
for (int ir = 0; ir < this->veff->nc; ++ir)
57+
{
58+
porter[ir] *= current_veff[ir];
59+
}
5460
}
5561
wfcpw->real2recip(porter, tmhpsi, ik, true);
5662
}
5763
else
5864
{
59-
const double* current_veff[4];
60-
for(int is=0;is<4;is++)
61-
{
62-
current_veff[is] = &(this->veff[0](is, 0));
63-
}
6465
std::complex<double> *porter1 = new std::complex<double>[wfcpw->nmaxgr];
6566
// fft to real space and doing things.
6667
wfcpw->recip2real(tmpsi_in, porter, ik);
6768
wfcpw->recip2real(tmpsi_in + this->max_npw, porter1, ik);
6869
std::complex<double> sup, sdown;
69-
for (int ir = 0; ir < this->veff->nc; ir++)
70+
if(this->veff->nc != 0)
7071
{
71-
sup = porter[ir] * (current_veff[0][ir] + current_veff[3][ir])
72-
+ porter1[ir]
73-
* (current_veff[1][ir]
74-
- std::complex<double>(0.0, 1.0) * current_veff[2][ir]);
75-
sdown = porter1[ir] * (current_veff[0][ir] - current_veff[3][ir])
76-
+ porter[ir]
77-
* (current_veff[1][ir]
78-
+ std::complex<double>(0.0, 1.0) * current_veff[2][ir]);
79-
porter[ir] = sup;
80-
porter1[ir] = sdown;
72+
const double* current_veff[4];
73+
for(int is=0;is<4;is++)
74+
{
75+
current_veff[is] = &(this->veff[0](is, 0));
76+
}
77+
for (int ir = 0; ir < this->veff->nc; ir++)
78+
{
79+
sup = porter[ir] * (current_veff[0][ir] + current_veff[3][ir])
80+
+ porter1[ir]
81+
* (current_veff[1][ir]
82+
- std::complex<double>(0.0, 1.0) * current_veff[2][ir]);
83+
sdown = porter1[ir] * (current_veff[0][ir] - current_veff[3][ir])
84+
+ porter[ir]
85+
* (current_veff[1][ir]
86+
+ std::complex<double>(0.0, 1.0) * current_veff[2][ir]);
87+
porter[ir] = sup;
88+
porter1[ir] = sdown;
89+
}
8190
}
8291
// (3) fft back to G space.
8392
wfcpw->real2recip(porter, tmhpsi, this->ik, true);

0 commit comments

Comments
 (0)