@@ -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;
0 commit comments