Repository navigation
refactor(parallel_grid): pass KPAR into z_distribution as a parameter - #8114
Merged
Merged
Conversation
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].
Agent Governance Check
|
mohanchen
approved these changes
Oct 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Parallel_Grid::z_distribution()previously readGlobalV::KPARdirectly, so itsbehaviour depended on global state rather than on its caller. This PR makes
kparan explicit parameter: the caller
Parallel_Grid::init()suppliesGlobalV::KPAR, and thez_distribution()body no longer reads any global variable.This is a narrow, behaviour-preserving refactor that removes one cross-layer
dependency on
GlobalV::KPARinsidesource/source_base/parallel_grid.*.Changes
source/source_base/parallel_grid.hvoid z_distribution(void);→void z_distribution(const int kpar);source/source_base/parallel_grid.cppParallel_Grid::init()now callsthis->z_distribution(GlobalV::KPAR);Parallel_Grid::z_distribution(const int kpar)useskparfor thestartpallocation and the pool loop instead of
GlobalV::KPAR.assert(kpar > 0);at the top ofz_distribution(). This preserves theprotection that the caller's
assert(GlobalV::KPAR > 0)previously providedfor
startp[0], now that the function can be called with anykpar.Behaviour / Compatibility
init()passes exactly the same value (GlobalV::KPAR)that
z_distribution()used to read itself.tested from its arguments alone.
Scope Note
This PR intentionally contains only the
z_distribution(kpar)change. Theunrelated
Parallel_Grid::initsplit intoinit_serial/init_parallelsubroutines is kept in a separate PR / branch (
refactor-parallel-grid-init) andis not part of this diff.
Verification
Environment:
cmake+make,ENABLE_MPI=ON,ENABLE_LCAO=ON(existingbuild/).