Fix: Correct PW KPAR/BNDPAR occupations and distributed output - #7845
Conversation
|
Could you add some unit tests or integrate tests? |
17198ae to
d4eced0
Compare
Added. I also found that |
There was a problem hiding this comment.
Pull request overview
This PR fixes PW KPAR/BNDPAR occupation handling and distributed band, charge-density, and cube output.
Changes:
- Corrects global band and
ocp_setoccupation mapping. - Reconstructs distributed output data across MPI layouts.
- Updates documentation and adds regression coverage.
Critical blockers remain in source/source_base/parallel_grid.cpp and source/source_estate/elecstate_tools.cpp.
Reviewed changes
Copilot reviewed 51 out of 52 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Review status |
|---|---|
tests/integrate/tools/catch_properties.sh |
No final issue reported. |
tests/06_SDFT/14_PW_SDFT_10D10S_METHD2/result.ref |
No final issue reported. |
tests/06_SDFT/14_PW_SDFT_10D10S_METHD2/INPUT |
No final issue reported. |
tests/06_SDFT/14_PW_SDFT_10D10S_METHD2/band.txt.ref |
No final issue reported. |
tests/01_PW/CASES_GPU.txt |
No final issue reported. |
tests/01_PW/CASES_CPU.txt |
No final issue reported. |
tests/01_PW/211_PW_BPCG_KB_OCP_CHG/STRU |
No final issue reported. |
tests/01_PW/211_PW_BPCG_KB_OCP_CHG/result.ref |
No final issue reported. |
tests/01_PW/211_PW_BPCG_KB_OCP_CHG/README |
No final issue reported. |
tests/01_PW/211_PW_BPCG_KB_OCP_CHG/KPT |
No final issue reported. |
tests/01_PW/211_PW_BPCG_KB_OCP_CHG/INPUT |
No final issue reported. |
tests/01_PW/211_PW_BPCG_KB_OCP_CHG/chg.cube.ref |
No final issue reported. |
tests/01_PW/089_PW_get_wf_kpar/result.ref |
No final issue reported. |
tests/01_PW/089_PW_get_wf_kpar/README |
No final issue reported. |
tests/01_PW/089_PW_get_wf_kpar_bndpar/STRU |
No final issue reported. |
tests/01_PW/089_PW_get_wf_kpar_bndpar/result.ref |
No final issue reported. |
tests/01_PW/089_PW_get_wf_kpar_bndpar/README |
No final issue reported. |
tests/01_PW/089_PW_get_wf_kpar_bndpar/KPT |
No final issue reported. |
tests/01_PW/089_PW_get_wf_kpar_bndpar/INPUT |
No final issue reported. |
tests/01_PW/087_PW_get_pchg_kpar/result.ref |
No final issue reported. |
tests/01_PW/087_PW_get_pchg_kpar/README |
No final issue reported. |
tests/01_PW/087_PW_get_pchg_kpar/KPT |
No final issue reported. |
tests/01_PW/087_PW_get_pchg_kpar_bndpar/STRU |
No final issue reported. |
tests/01_PW/087_PW_get_pchg_kpar_bndpar/result.ref |
No final issue reported. |
tests/01_PW/087_PW_get_pchg_kpar_bndpar/README |
No final issue reported. |
tests/01_PW/087_PW_get_pchg_kpar_bndpar/KPT |
No final issue reported. |
tests/01_PW/087_PW_get_pchg_kpar_bndpar/INPUT |
No final issue reported. |
source/source_io/test/CMakeLists.txt |
No final issue reported. |
source/source_io/test_serial/CMakeLists.txt |
No final issue reported. |
source/source_io/module_wf/get_wf_pw.h |
No final issue reported. |
source/source_io/module_parameter/read_inp_tddft.cpp |
No final issue reported. |
source/source_io/module_parameter/read_inp_sys.cpp |
No final issue reported. |
source/source_io/module_output/write_cube.cpp |
No final issue reported. |
source/source_io/module_output/band_parallel_output.h |
No final issue reported. |
source/source_io/module_output/band_parallel_output.cpp |
No final issue reported. |
source/source_io/module_energy/write_eig_occ.cpp |
No final issue reported. |
source/source_io/module_energy/write_bands.cpp |
No final issue reported. |
source/source_io/module_ctrl/ctrl_output_pw.cpp |
No final issue reported. |
source/source_io/module_chgpot/get_pchg_pw.h |
No final issue reported. |
source/source_io/CMakeLists.txt |
No final issue reported. |
source/source_estate/test/elecstate_occupy_test.cpp |
No final issue reported. |
source/source_estate/test/elecstate_base_test.cpp |
No final issue reported. |
source/source_estate/occupy.h |
No final issue reported. |
source/source_estate/occupy.cpp |
No final issue reported. |
source/source_estate/elecstate_tools.cpp |
Critical issue: replicated non-BPCG SDFT band storage receives an incorrect prefix offset. |
source/source_cell/parallel_kpoints.cpp |
No final issue reported. |
source/source_cell/cal_atoms_info.h |
No final issue reported. |
source/source_base/parallel_grid.cpp |
Critical issue: grid distributions do not match the communicator used for KPAR+BNDPAR collection. |
source/Makefile.Objects |
No final issue reported. |
docs/parameters.yaml |
No final issue reported. |
docs/advanced/input_files/input-main.md |
No final issue reported. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
This PR fixes several PW KPAR/BNDPAR correctness issues. The changes correct fixed and explicitly supplied occupations under distributed k-point and band layouts, reconstruct complete band data before shared-file output, and fix the real-space grid collection used by charge-density
.cubeoutput.The
kpar,bndpar, andocp_setparameter descriptions are also updated to match the current implementation.Problems addressed
smearing_method=fixedandbndpar>1, every band group treated its local band zero as global band zero. Multiple groups therefore occupied their first local bands repeatedly, producing incorrect electron counts, charge densities, band energies, and SCF results.ocp_setvalidated its input length using the pool-local number of k-points and indexed the input with a local-band stride. KPAR could reject a correctly sized input, while BNDPAR could silently assign occupations to the wrong bands.out_chgused source ranks derived from a larger process layout as ranks inPOOL_WORLD. Under BPCG this could pass an invalid communicator rank toMPI_Recvafter the SCF calculation had completed.out_bandand eigenvalue/occupation output treated band-local matrices as if they contained all global bands. This could cause out-of-bounds access, omit bands owned by other band groups, duplicate k-point contributions, or allow multiple groups to write the same shared file.Validation
A standalone edge-case test was carried out with 21 calculations: 17 CPU cases and 4 GPU cases. PW CPU cases used 6 MPI ranks, 8 k-points, 7 bands, and BPCG. The following layouts were compared:
kpar=1,bndpar=1kpar=2,bndpar=1kpar=1,bndpar=33+2+2kpar=2,bndpar=3kpar=3,bndpar=23+3+2, and uneven band ownership,4+3The edge-case test covered
nspin=1andnspin=2, fixed occupations, k-point-dependentocp_setvalues, PW CPU/GPU execution, and LCAO temporarykpar=1/2/3diagonalization. Every PW case checked the complete occupation table, total energy, band table, charge-density.cubevalues, and.cubeintegral.All 21 cases completed successfully and reported no failures.
7.190692e-121.534826e-102.299966e-131.199041e-148.526513e-141.163514e-131.000589e-142.042810e-140.000000e+003.730349e-141.000589e-145.329071e-15