Skip to content

refactor(stodft): replace new[]/delete[] with std::vector in info_gatherv - #8149

Merged
mohanchen merged 2 commits into
deepmodeling:developfrom
xinchenhou:task1-stodft-vector
Oct 16, 2026
Merged

mohanchen merged 2 commits into
deepmodeling:developfrom
xinchenhou:task1-stodft-vector

Conversation

@xinchenhou

Copy link
Copy Markdown

What this PR does

Replace raw new[]/delete[] with std::vector in source/source_pw/module_stodft/sto_tool.h.

Why

  • std::vector manages memory automatically, removing the need for manual delete[].
  • This follows the ABACUS governance rule: "Prefer std::vector over raw new/delete for dynamic arrays".

Changes

  • info_gatherv::nrecv and info_gatherv::displs changed from int* to std::vector<int>.
  • Constructor initializes vectors in the member initializer list.
  • Destructor removed; std::vector handles cleanup.
  • MPI_Allgather now receives nrecv.data() instead of raw pointer.
  • Added #include <vector> to sto_tool.h because std::vector<int> is now a member type of info_gatherv and member variables require complete types (forward declaration is not possible for template classes).
  • Updated call sites in source/source_pw/module_stodft/sto_elecond.cpp to pass nrecv.data() / displs.data() to the existing int* interfaces (gatherchi_op, Parallel_Common::gatherv_data).

Note on file count: The original task description mentioned modifying only one file, but sto_elecond.cpp consumes info_gatherv::nrecv/displs as raw int*. After the change to std::vector<int>, those call sites require .data() to compile. Hence two files are modified, but the diff remains under 20 lines.

Verification performed

  • Build: cmake --build build -j 8 (with ENABLE_LCAO=OFF, ENABLE_ELPA=OFF due to local environment constraints)
  • Unit test: ctest --test-dir build -R MODULE_PW_Sto -V
    • Result: 100% tests passed, 0 tests failed out of 3
    • MODULE_PW_Sto_Tool_UTs PASSED (covers sto_tool.h)
    • MODULE_PW_Sto_Hamilt_UTs PASSED
    • MODULE_PW_Sto_HSolver_UTs PASSED
  • Governance check: python3 tools/03_code_analysis/agent_governance_check.py --staged
    • Result: 3 warnings, 0 errors
    • Warning 1 (header include): Justified — std::vector<int> is a member type and requires complete type, cannot forward declare
    • Warning 2 (no test changes): Justified — pure refactor with no behavior change, existing tests already cover the modified code
    • Warning 3 (no docs changes): Justified — internal implementation detail, no public API or user-facing behavior change

Documentation

No documentation update needed. This change is internal to info_gatherv and does not affect any public API, user-facing behavior, or input parameters.

Checklist

  • No new #define private public in tests
  • No new .hpp implementation headers
  • No default arguments added to existing interfaces
  • C++11 compatible (uses std::vector::data() which is C++11)
  • One variable per line declared

@mohanchen mohanchen added Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 labels Oct 15, 2026

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review of b9acd92: no correctness regression identified in the ownership conversion or caller updates. No builds or runtime tests were run; CI retrieval was unavailable.

Comment thread source/source_pw/module_stodft/sto_tool.h
@mohanchen
mohanchen merged commit ae23b2c into deepmodeling:develop Oct 16, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants