Commit a6e1a67
abacus_fixer
refactor(parallel): step-1a introduce ProcessTopology value class + divide_mpi_groups tests
Scope: 5 files changed, +482 lines (all additions; zero behavior change
for existing code paths). No existing API touched.
Build: cmake --build build exit=0.
Test : OMP_NUM_THREADS=1 mpirun -np 4 MODULE_BASE_ProcessTopology ->
7/7 tests passed (5x divide_mpi_groups + 2x ProcessTopology).
ProcessTopology (step 1a backbone, 规则1 / 规则2 / 规则3)
- New header-only + cpp class ProcessTopology in parallel_topology.h/.cpp:
* Immutably holds the six communicators that currently live as raw
globals (POOL_WORLD / KP_WORLD / INT_BGROUP / BP_WORLD /
GRID_WORLD / DIAG_WORLD) together with kpar / my_pool /
rank_in_pool / nproc_in_pool[...] / bndpar / my_bndgroup /
rank_in_bgroup / nproc_in_bgroup / world size&rank.
* Value semantics (trivially copyable ints + vector, no ref
members, no mutable workflow switches) - addresses the two
weaknesses observed in the old MPICommGroup (reference aliases
between ngroups <-> nprocs_in_inter and lack of RAII).
* Head-only-interface-minimal: includes only <vector> and <mpi.h>
conditionally; does NOT include parallel_comm.h, parallel_global.h
or any GlobalV header. All state flows in via constructor args,
so the class is unit-testable in isolation and does not
contribute to the 6-global-comm transit-include surface cleaned
in step 0.
* Default constructor produces a single-process fallback so any
non-__MPI build path (including LCAO serial sections) can still
take a `const ProcessTopology&` and work.
* pool_root_rank(pool) helper computes the world rank of a pool
root without reaching for GlobalV arrays - needed by both the
upcoming Parallel_Kpoints migration and cube-output rank
calculations.
- Base library wiring (CMakeLists rule, AGENTS.md deterministic-add
requirement): add parallel_topology.cpp to the `base` OBJECT
library source list directly after parallel_grid.cpp to keep the
parallel_* cluster together. Nothing in the main build links the
new object into paths that didn't already include `base`, so the
incremental link cost is zero for unchanged modules.
Parallel_Global::divide_mpi_groups tests (第一次为纯算术核心补单测)
- New target MODULE_BASE_ProcessTopology in test_parallel/CMakeLists.txt,
sources match ParaGlobal's transitive list plus parallel_topology.cpp.
- parallel_topology_test.cpp covers:
* DivideMpiGroups.EvenDivision 8 proc / 4 pools even
* DivideMpiGroups.UnevenDivision 5 proc / 2 pools (3+2)
* DivideMpiGroups.ExactlyOneProcessPerGroup - N proc / N pools
* DivideMpiGroups.OneGroup 5 proc / 1 pool
* DivideMpiGroups.UnevenLargePools 24 proc / 5 pools (5+5+5+5+4)
Each uses a local helper `divide_all` that enumerates every
rank 0..procs-1 against divide_mpi_groups, then `validate_divide`
asserts the group sizes sum to procs and every in-group rank is
unique within its group. This directly guards against regressions
in the upcoming `create_topology` factory because that factory is
the one caller that stitches `divide_mpi_groups` outputs into a
ProcessTopology object.
* ProcessTopology.DefaultConstructorIsSingleProcess (non-MPI fallback)
* ProcessTopology.ConstructAndAccessors - explicit 10-proc /
KPAR=3 / BNDPAR=2 construction, plus a copy-semantics check.
Governance notes:
- GlobalV / PARAM / GlobalC budget: added lines = 0 reads of any
global. The new class never includes global_variable.h or PARAM
headers; the constructor takes everything as explicit args.
- Added includes in parallel_topology.h are both self-contained uses
(<vector> is for member std::vector<int> nproc_in_pool_; <mpi.h>
conditionally declares the MPI_Comm members). They do not leak
declarations of the six global MPI_Comm variables - that surface
remains isolated to parallel_comm.h.
- No documentation change because no external interface (INPUT,
CLI, public class API used by non-parallel code) changed. The
class is a new internal component used via its constructor and
accessors; Parallel_Global::create_topology (next step) wires
it at the startup boundary where call sites already take explicit
parameters.
- C++11 compatible: using only std::vector, assert, int/long long
POD types; no auto-return-type deduction, no std::move-only
semantics required, no brace-init aggregates in new code beyond
ProcessTopology copy test (already allowed in C++11).
- One variable per declaration: ProcessTopology members and test
helper variables each get their own line; no comma-joined
declarations introduced.1 parent 2a7696f commit a6e1a67
5 files changed
Lines changed: 482 additions & 0 deletions
File tree
- source/source_base
- test_parallel
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
13 | 19 | | |
14 | 20 | | |
15 | 21 | | |
| |||
0 commit comments