Skip to content

refactor(parallel_grid): pass KPAR into z_distribution as a parameter - #8114

Merged
mohanchen merged 4 commits into
developfrom
refactor-parallel-grid-kpar
Oct 10, 2026
Merged

mohanchen merged 4 commits into
developfrom
refactor-parallel-grid-kpar

Conversation

@MrLi000001

Copy link
Copy Markdown
Collaborator

Summary

Parallel_Grid::z_distribution() previously read GlobalV::KPAR directly, so its
behaviour depended on global state rather than on its caller. This PR makes kpar
an explicit parameter: the caller Parallel_Grid::init() supplies
GlobalV::KPAR, and the z_distribution() body no longer reads any global variable.

This is a narrow, behaviour-preserving refactor that removes one cross-layer
dependency on GlobalV::KPAR inside source/source_base/parallel_grid.*.

Changes

  • source/source_base/parallel_grid.h
    • void z_distribution(void); → void z_distribution(const int kpar);
  • source/source_base/parallel_grid.cpp
    • Parallel_Grid::init() now calls this->z_distribution(GlobalV::KPAR);
    • Parallel_Grid::z_distribution(const int kpar) uses kpar for the startp
      allocation and the pool loop instead of GlobalV::KPAR.
    • Added assert(kpar > 0); at the top of z_distribution(). This preserves the
      protection that the caller's assert(GlobalV::KPAR > 0) previously provided
      for startp[0], now that the function can be called with any kpar.

Behaviour / Compatibility

  • No functional change: init() passes exactly the same value (GlobalV::KPAR)
    that z_distribution() used to read itself.
  • The function body is now free of global reads, so it can be reasoned about and
    tested from its arguments alone.
  • No INPUT parameter, documented behaviour, or public interface changes.

Scope Note

This PR intentionally contains only the z_distribution(kpar) change. The
unrelated Parallel_Grid::init split into init_serial / init_parallel
subroutines is kept in a separate PR / branch (refactor-parallel-grid-init) and
is not part of this diff.

Verification

Environment: cmake + make, ENABLE_MPI=ON, ENABLE_LCAO=ON (existing build/).

  • Build (passed):

z_distribution() read GlobalV::KPAR directly, so its behaviour depended on global state. Take kpar as an explicit parameter, with Parallel_Grid::init() supplying GlobalV::KPAR, so the function body no longer reads any global variable.

The added assert(kpar > 0) replaces the protection the caller assert(GlobalV::KPAR > 0) used to give startp[0].
@github-actions

Copy link
Copy Markdown

Agent Governance Check

Severity Rule Location Reason Suggested action Exception
warning Global dependency budget source/source_base/parallel_grid.cpp:97 Added line introduces 1 GlobalV/GlobalC/PARAM reference(s); PR total added=1, removed=2, net_delta=-1. Confirm this is a migration-neutral move or partial cleanup, and explain the remaining global dependency rationale. allowed
warning PR metadata completeness pull_request.body missing sections: Linked Issue, Unit Tests and/or Case Tests for my changes, What's changed? Fill the PR template with issue linkage, test evidence, and a concise change summary. allowed
warning Test evidence review pull_request.body Source code changed without test path changes or PR test evidence. Add focused tests, update a relevant case, or document why tests are not required. allowed
warning Documentation sync review pull_request.body Source changes have no docs change or explicit no-docs-needed statement. Add documentation updates for behavior/interface changes, or state why documentation is not required. allowed

@mohanchen mohanchen added the Refactor Refactor ABACUS codes label Oct 10, 2026
@mohanchen
mohanchen merged commit 7e03609 into develop Oct 10, 2026
29 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants