Skip to content

Commit cd270a7

Browse files
chengleizhengchengleizheng
andauthored
Fix 007_PW_UPF201_USPP_Fe in 01_PW: G=0 indexing in nspin=2 mixing inner products (Useful Information to know why previous versions yield small energy differences when nspin=2 with different number of processors) (deepmodeling#7825)
* Fix(charge): replace hardcoded index 0 with ig_gge0 for the G=0 term in mixing inner products * update 007 result.ref and CASES_GPU.txt * add threshold file for 096_PW_PBE0_AFM, just like 096_PW_PBE0_FM --------- Co-authored-by: chengleizheng <you@example.com>
1 parent b3691d0 commit cd270a7

4 files changed

Lines changed: 24 additions & 7 deletions

File tree

source/source_estate/module_charge/mix_resid.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,23 @@ double Charge_Mixing::inner_product_recip_rho(std::complex<double>* rho1, std::c
171171
// including |G|=0 term.
172172
double sum2 = 0.0;
173173

174-
sum2 += fac2 * (conj(rhog1[0][0] - rhog1[1][0]) * (rhog2[0][0] - rhog2[1][0])).real();
174+
// The G=0 component is the ig_gge0-th element of the local G-list on the
175+
// rank that owns it, not necessarily element 0: the local G-list is built
176+
// by scanning (x,y) sticks in grid order, so element 0 is the first plane
177+
// wave of the first owned stick. Using a hardcoded index 0 made the inner
178+
// product partition-dependent for pools with more than one rank.
179+
if (ig0 >= 0)
180+
{
181+
sum2 += fac2 * (conj(rhog1[0][ig0] - rhog1[1][ig0]) * (rhog2[0][ig0] - rhog2[1][ig0])).real();
182+
}
175183

176184
double mag = 0.0;
177185
#ifdef _OPENMP
178186
#pragma omp parallel for reduction(+ : mag)
179187
#endif
180188
for (int ig = 0; ig < this->rhopw->npw; ig++)
181189
{
190+
if (ig == ig0) { continue; }
182191
mag += (conj(rhog1[0][ig] - rhog1[1][ig]) * (rhog2[0][ig] - rhog2[1][ig])).real();
183192
}
184193
mag *= fac2;
@@ -342,14 +351,21 @@ double Charge_Mixing::inner_product_recip_hartree(std::complex<double>* rhog1, s
342351
// including |G|=0 term.
343352
double sum2 = 0.0;
344353

345-
sum2 += fac2 * (conj(rhog1[0 + this->rhopw->npw]) * rhog2[0 + this->rhopw->npw]).real();
354+
// Same G=0 indexing remark as in inner_product_recip_rho: use ig_gge0
355+
// instead of a hardcoded index 0, otherwise the inner product (and hence
356+
// the DIIS mixing coefficients) depends on how the pool is divided.
357+
if (ig0 >= 0)
358+
{
359+
sum2 += fac2 * (conj(rhog1[ig0 + this->rhopw->npw]) * rhog2[ig0 + this->rhopw->npw]).real();
360+
}
346361

347362
double mag = 0.0;
348363
#ifdef _OPENMP
349364
#pragma omp parallel for reduction(+ : mag)
350365
#endif
351366
for (int ig = 0; ig < this->rhopw->npw; ig++)
352367
{
368+
if (ig == ig0) { continue; }
353369
mag += (conj(rhog1[ig + this->rhopw->npw]) * rhog2[ig + this->rhopw->npw]).real();
354370
}
355371
mag *= fac2;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -673.8349306935572258
2-
etotperatomref -673.8349306936
1+
etotref -673.8349346996149052
2+
etotperatomref -673.8349346996
33
totalforceref 0.000000
4-
totalstressref 66620.323844
5-
totaltimeref 1.34
4+
totalstressref 66620.327426
5+
totaltimeref 1.18
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
threshold 0.001

tests/01_PW/CASES_GPU.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ scf_out_elf
88
004_PW_UPF201_Si
99
005_PW_UPF201_UPF100
1010
006_PW_UPF201_Eu
11-
#007_PW_UPF201_USPP_Fe
11+
007_PW_UPF201_USPP_Fe
1212
008_PW_UPF201_USPP_NaCl
1313
009_PW_UPF201_USPP
1414
010_PW_0TYPE

0 commit comments

Comments
 (0)