8000 kaffpa: 3.9x less total time (2.8x geometric mean) at unchanged partition quality by schulzchristian · Pull Request #171 · KaHIP/KaHIP · GitHub
[go: up one dir, main page]

Skip to content

kaffpa: 3.9x less total time (2.8x geometric mean) at unchanged partition quality - #171

Merged
schulzchristian merged 86 commits into
masterfrom
speedup-kaffpa
Nov 13, 2026
Merged

schulzchristian merged 86 commits into
masterfrom
speedup-kaffpa

Conversation

@schulzchristian
Copy link
Copy Markdown
Member

Summary

This PR makes kaffpa faster on every preconfiguration, graph class and k. On a fixed benchmark of 537 jobs (20 graphs, all six preconfigurations, k = 2, 8, 32, 64, 256), measured against current master (34e1d0a) back to back on the same machine:

  • total time 6503 s to 1666 s (ratio 0.2562, 3.90x faster)
  • shifted geometric mean of the per-job time ratio 0.3517 (2.84x faster)
  • partition quality unchanged: cut ratio Q = 1.00078 on seeds 1 to 3 and 1.00030 on seeds 1 to 6 (master vs master noise: 0.9980 to 1.0017), no crashes, no more imbalanced partitions than master.

The work was done in an algorithm engineering loop with a fixed benchmark and a fixed quality gate: every change was profiled, built, timed on the full benchmark and either kept or reverted. Changes come in two output classes:

  • (a) bit-identical: for a given seed the partition file is byte for byte the one master writes. This was checked by sha256 on every job of every full run (537 jobs x 3 repetitions) and on a crosscheck grid. Most changes are of this kind.
  • (b) changed tie or random decisions: the algorithm is the same, but some ties are broken differently or random numbers are drawn in a different order, so individual partitions differ. Each such change had to pass the quality gate described below.

The PR touches only lib/ and app/ (45 files, +2816 / -549). No CMake or compiler flag changes; still single-threaded. ParHIP has its own copy of the library (parallel/modified_kahip) and is not affected. All other command line programs were audited separately (28 paths, see below). Three defects found by that audit are fixed in this PR.

The history (85 commits) is kept as it was developed, including a few change/revert pairs of experiments that did not pay off (net zero, listed at the end). Commit messages that start with a number (112:, 123:) carry the experiment number of the development log.

Results vs master

Direct run: master and this branch alternately, 537 jobs x 3 repetitions each, median per job. Time is the wall clock time of the whole process (reading the graph, partitioning, writing the partition). Shifted geometric mean with shift 0.01 s.

preconfiguration jobs geomean ratio master total s PR total s total ratio
fast 100 0.426 170 49 0.286
eco 97 0.313 989 181 0.183
strong 73 0.319 2044 603 0.295
fastsocial 100 0.457 109 47 0.428
ecosocial 98 0.324 859 201 0.234
strongsocial 69 0.263 2335 586 0.251
all 537 0.352 6503 1666 0.256
graph class jobs geomean ratio master total s PR total s total ratio
mesh 228 0.391 2060 618 0.300
road 143 0.387 1924 572 0.297
social / web 166 0.278 2523 476 0.189
k jobs geomean ratio master total s PR total s total ratio
2 115 0.368 889 204 0.229
8 107 0.363 872 246 0.282
32 108 0.343 1241 325 0.262
64 108 0.328 1824 431 0.236
256 99 0.354 1681 461 0.274

Peak memory of the largest job is 0.59 GB instead of 0.49 GB (reusable per-node buffers and stamp arrays that are kept between calls).

Quality gate

Q is the geometric mean over the 537 jobs of (mean cut of the PR + 1) / (mean cut of master + 1), each mean over seeds 1 to 3. Lower is better; 1.001 means the cut is 0.1% larger on average. Every partition was checked by an independent checker that recomputes the cut and the block weights from the graph and the partition file.

Rules for a class (b) change:

  • no crashes;
  • Q <= 1.001 (a change with 1.001 < Q <= 1.003 was rerun on seeds 4 to 6 and decided by the 6-seed Q);
  • no more partitions above the strict balance bound than master's worst 3-seed set (71 of 1611);
  • on the crosscheck grid (small graphs x all preconfigurations x k 2, 8, 64, 256 x seeds 2, 3 x imbalance 1, 3, 5%), imbalanced partitions at most 1.1 x master + 2.

Noise of the metric: master on seeds 4 to 6 vs master on seeds 1 to 3 gives 0.99990; over the ten 3-vs-3 splits of master's seeds 1 to 6 it ranges from 0.9980 to 1.0017 (sd 0.0011).

Result for this branch:

value
Q, seeds 1 to 3 1.00078 (PASS)
Q, seeds 1 to 6 1.00030 (PASS)
crashes 0
imbalanced partitions, seeds 1 to 3 66 (master 65)
imbalanced partitions, seeds 1 to 6 128 (master 136)
grid: imbalanced partitions (864 runs) 132 (master 141)
Q by preconfiguration fast 1.0030, eco 1.0061, strong 1.0019, fastsocial 0.9982, ecosocial 0.9932, strongsocial 1.0035
Q by class mesh 1.0015, road 1.0065, social 0.9949
Q by k 2: 1.0003, 8: 0.9990, 32: 1.0022, 64: 1.0023, 256: 1.0001

On 6 seeds the largest groups are road 1.0030, eco 1.0029 and strongsocial 1.0007. Most of the remaining 0.08% (3 seeds) comes from the two parameter changes for strongsocial (R5, own section below); without them Q was 1.00045.

CLI audit

Every algorithm path reachable from a command line program was compared with master: 28 paths over all 11 programs of the default non-MPI build (15 kaffpa option paths such as --enforce_balance, --balance_edges, --imbalance 0/10/50, odd k, --enable_mapping, --time_limit, --mmap_io, connected blocks; global_multisection (2), node_separator, node_ordering, label_propagation (2), edge_partitioning (2), partition_to_vertex_separator, evaluator, edge_evaluator, graphchecker, interface_test). Graphs: 6 small graphs plus 5 weighted variants, several k, all preconfigurations, seeds 1 to 3, and seeds 4 to 9 for paths that looked suspect. A path counted as a loss only if its Q was outside the master-vs-master noise of that path and the loss repeated on new seeds.

The audit found three defects, all fixed in this PR (commits b76e198, c1dff95, 58415f8):

  1. label_propagation program: the active-node sweeps of the coarsening (0f77fd9) also ran when the program calls label propagation directly, so its result got worse (Q 1.129). Now they run only inside coarsening; the program is bit-identical to master again (117 of 117 runs).
  2. node_separator and node_ordering crashed (153 of 396 and 49 of 108 runs): the rewritten priority queue did not tolerate changeKey on a node that is not in the queue, which those programs do. The rewrite is now a separate class fastMaxNodeHeap, used only by k-way FM, 2-way FM and bipartition; maxNodeHeap.h is master's file again. 0 crashes.
  3. edge_partitioning: vertex cut 1.2% worse (Q 1.0119 on seeds 1 to 3, 1.0123 on seeds 4 to 9). An ablation pointed to the GPA edge filter (2de62c9): the split graph has many equally rated edges, and filtering before the sort changes their order. The early filter is now enabled only by kaffpa (new PartitionConfig::gpa_usable_edges_only); everyone else sorts the full list as master does and filters afterwards. Now Q 0.9946 (seeds 1 to 3), 1.0062 (seeds 4 to 6), within noise.

After the fixes all 28 paths pass. Notable: node_separator Q 1.0128 with a master-vs-master noise of 0.9485 (z 0.85); global_multisection 1.0027 (master itself is not deterministic there: 101 of 216 reruns with the same seed differ); node_ordering failures are 900 s timeouts only (master 24, PR 18). kaffpaE builds and runs (smoke test with 2 MPI processes) but was not part of the quality gate; it shares the partitioning code tested here.

How to reproduce

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DNOMPI=ON -DPARHIP=OFF
cmake --build build -j --target kaffpa
./build/kaffpa GRAPH --k=K --preconfiguration=CONFIG --seed=1 --output_filename=part

Benchmark: graphs 4elt, fe_body, fe_tooth, fe_rotor, 144, auto, delaunay_n18, rgg_n_2_18 (mesh), luxembourg, bel, nld, belgium, netherlands (road), PGPgiantcompo, email-EuAll, soc-Slashdot0902, loc-gowalla, coAuthorsDBLP, web-Google, cnr-2000 (social/web); preconfigurations fast, eco, strong, fastsocial, ecosocial, strongsocial; k 2, 8, 32, 64, 256; seed 1; default imbalance 3%. The 63 combinations that took over 120 s with master were left out, which gives 537 jobs. One job per physical core (16-core Xeon w5-3435X, pinned with taskset), 3 repetitions, median per job. GCC 13.3, Ubuntu 24.04. For class (a) you can check identity with sha256sum part against a master build with the same arguments. The scripts are not part of this PR; I am happy to share them.

Default out-of-tree build of this branch (all targets, including kaffpaE and ParHIP when MPI is found): same targets as master, no new compiler warnings (the only warning is master's unused repair_bipartition_connectivity in bipartition.cpp).

Changes by component

Notation: G / T is the shifted geometric mean / total time ratio vs master of the full 537-job run after the step (each full run measured against stored master times; the final direct run above is the reference). Component ratios are from per-component timers that were used during development and are removed again in 66bf9a8 (d_flow = flow refinement, d_multitry = multitry k-way FM, d_qgraph = quotient graph refinement, coarsen, initial). A/B numbers are single-core timing runs of the changed binary against the previous one on a few jobs (ratio of total time). Several small exact changes were measured together in one full run; the G/T step is then given once for the group.

1. IO and final output (all class (a))

  • e7d04bd Fast METIS reader, buffered partition writer, cheaper final metrics. The reader used std::getline + std::stringstream per line, about 15 to 19% of a fast/fastsocial job. The file is now read in one block and parsed by hand; the partition is written from one buffer; the final cut is computed once; max_communication_volume uses a stamp array instead of a per-node std::vector<bool>. Time outside partitioning (IO + final metrics) over all jobs: 102 s to 33.5 s. Together with 3866ed4 and b09ca9d: G 0.868.
  • c447c9a Final cut, boundary node count and maximum communication volume in one pass over the edges instead of four (the cut was computed twice). A/B 0.968 on small fast/fsocial/eco jobs (10 seeds). Full run G 0.3842 to 0.3797 (fast 0.463 to 0.453).
  • 4c28254 IO read and write buffers are no longer zeroed before they are overwritten. A/B 0.995 (small fast jobs 0.965 to 0.99). With ac73175: G 0.3797 to 0.3752.
  • 3866ed4 added per-component timers for development; they cost below noise and are removed again in 66bf9a8 (its commit message still describes the timer output; no timer code remains).

2. Memory and basic data structures (all class (a))

  • 4373685 Small-object allocator for the kaffpa program only (lib/tools/small_block_alloc.h, included from app/kaffpa.cpp, not on Windows). Global operator new/delete with per-size-class free lists in one reserved address range, no per-block header; blocks over 512 bytes go to malloc. Why it helps: malloc/free were 15 to 20% of the instructions in FM-heavy jobs (hash map nodes, small per-call objects, PartitionConfig copies). KaHIP never orders or hashes by pointer value, so results are identical. Partitioning time -3 to 8%, G 0.868 to 0.839.
  • b09ca9d node_hash_map (open addressing) for the node maps that are only probed, never iterated: vertex_moved_hashtable and the heap's node index. Same lookups, no per-entry allocation. Partitioning time geomean 0.944.
  • 2ed5733, 9b17cc6 stamped_node_map: a per-node array with a generation stamp, taken from a small pool, so creating and clearing a map is O(1) and lookups are direct array accesses; falls back to node_hash_map when the pool is exhausted. Used for the moved-node table and the heap index; 9b17cc6 stores stamp and value in one slot (one cache line per lookup). With bfc4e3f: d_multitry 0.811, d_qgraph 0.893, G 0.5060 to 0.4819, T 0.4447 to 0.4124. 9b17cc6 with a4f1ffb: G 0.3965 to 0.3927.
  • 02d686e The lookup-only start-node sets and SCC edge sets (unordered_map<NodeID,bool>) become stamped maps. Grouped with 133f8b1 and c1b2a17: G 0.4637 to 0.4571.
  • 4b636a0 Heap (now fastMaxNodeHeap) without the element array: entries hold (key, node), a stamped map gives the position, sifts move a hole instead of swapping. The comparisons are the same (ties included), so every entry ends at the same position as before. Removes a virtual destructor and 24-byte objects per entry. With 04989de: d_multitry 0.956, strong 0.971, G 0.4025 to 0.3965, T 0.3075 to 0.3020.
  • ac73175 Graph edge arrays are not zeroed on construction (default-init allocator; new_edge writes weight and rating). A/B 0.974 on small jobs.
  • c20ed8d nextBool takes the top bit of one mt19937 draw, which is exactly the value uniform_int_distribution(0,1) produced on libstdc++, without the distribution object. ecosocial coarsening 0.976, fastsocial 0.980.
  • 488f4a6 permutate_vector_good draws its swap positions 16 iterations ahead and prefetches them: same random sequence and same swaps, the cache misses overlap. Part of the GPA group below.
  • e0b69b3 lib/tools/std_sort_replica.h: a copy of libstdc++'s introsort (same pivot choice, same heap fallback, same final insertion sort) whose Hoare partition collects swap candidates blockwise without branches (BlockQuicksort style) and then swaps the same pairs in the same order. Needed because both callers (GPA edge sort, LP degree order) sort randomly permuted arrays with many ties, so a different sort algorithm would change the output. Unit test against std::sort on 400 arrays (1 to 1e9 distinct values, presorted inputs): identical, 0.66 of the time. A/B 0.992. Note: bit-identity relies on libstdc++'s std::sort; with another standard library the arrangement of ties may differ (as it already would with master).

3. 2-way FM (initial partitioning and pairwise refinement)

  • cf0ccc5 (a) Internal and external degrees of the nodes touched by a search are cached per FM call (stamped) and updated by +/- w when a neighbor moves, instead of rescanning each neighbor's edges per move. Initial partitioning -31%, fast 0.852, eco 0.867; loc-gowalla fast 3.3x. G 0.8106 to 0.7489.
  • cd5ca32 (a) two_way_fm::move_node is a template on the queue type, so the heaps are called without virtual dispatch. A/B 0.998.
  • 1be4f2b (b) The pair boundary is updated only for moves that are kept. During a search, the boundary is not read; so moves only update partition, block weights and the degree cache, the tail after the best prefix is undone by resetting those, and the kept prefix is replayed through the boundary updates in order (same operations as before for kept moves). The forward and backward boundary work of rolled-back moves disappears. Output changes only because the order of nodes in the boundary set differs, which changes the start-node order later. d_qgraph 0.840 (eco 0.501, ecosocial 0.570, fast 0.736). G 0.5739 to 0.5152, T 0.5140 to 0.4562. Q 0.99929 (eco 1.0021, strong 1.0036, road 1.0025).
  • ada0809 (a) extract_two_blocks sizes its edge arrays by the degree sums of the two blocks instead of m. A/B 1.000; part of the passenger group (fastsocial 0.951, initial 0.970), G 0.3897 to 0.3842.

4. k-way FM (multitry and quotient graph refinement)

  • 2f42328 (a) postMovedBoundaryNodeUpdates reads and writes the edge cut through the cached block-pair entry instead of a second hash lookup. d_qgraph 0.964, d_multitry 0.948, G 0.6924 to 0.6838.
  • 1307196 (a) complete_boundary keeps a flat k x k index of the block-pair entries (k <= 1024), filled on first access through the original map, so iteration order and insertion timing are unchanged. d_qgraph 0.985.
  • d03dc74 (a) Multitry reuses the gains computed in its start loop when it initializes the k-way queue, replaying the tie draws so the RNG stream is unchanged. With 1307196: total -1.9%, d_multitry 0.966, G 0.6752 to 0.6694.
  • 60f6dc3 (b) PartialBoundary (an unordered_map per block pair) becomes a dense node array plus a position index with swap-remove; iteration walks the array. Why faster: insert/delete/iterate without node allocations and pointer chasing (postMoved was 29% of loc-gowalla eco 32). Output changes because the iteration order of the boundary differs. d_qgraph 0.883, G 0.6643 to 0.6327, T 0.6613 to 0.6047, Q 0.99986.
  • b0f7fcb (b) move_node skips the gain computation for neighbors that are already moved and not queued (the result was thrown away), and the start loop computes a start node's gain only if it is not moved. The saved computations drew random numbers for ties, so the RNG stream changes. d_multitry 0.897, G 0.6327 to 0.6279, T 0.6047 to 0.5844, Q 0.99981.
  • 16b7ce3, b826b26 (b) Per-round connectivity cache for gain queries: per node a list of (block, connection weight) with weight > 0, built on the first query of a round and updated in move_node; a query costs O(adjacent blocks) instead of O(degree). Only nodes of degree >= 32 use it (below that the plain scan is faster), and the storage is shared across the searches of a round (16b7ce3 alone resized it per search). d_multitry 0.972 (soc-Slashdot 0.248, loc-gowalla 0.524), G 0.6279 to 0.6245, Q 0.99978.
  • b544769 (b) Boundary updates deferred to the end of a k-way round: a localized search reads only block weights and counts, so move_node skips postMovedBoundaryNodeUpdates; at round end the rolled-back tail is undone by resetting partition and weights, and the kept prefix is replayed in order through the boundary updates (same operations as before for kept moves). d_multitry 0.639, d_qgraph 0.836, G 0.5929 to 0.5739, T 0.5722 to 0.5140, Q 1.00049 (eco 1.0039, strongsocial 1.0043, road 1.0049).
  • 43eca8e (a) move_node prefetches the node entries of the first 32 neighbors and the edges of the next neighbor before the gain loop (move_node was 21% of netherlands strong 64, mostly latency of the neighbor adjacency). Part of the 7b25bfb group.
  • 2e2c0de (a) k-way move_node is a template on the queue type: no virtual dispatch for the heap, queue and moved tests once per neighbor. A/B 0.998.
  • cfdc6a0 (a) The quotient graph of a partition is built with its real edge count (edges collected first). A/B 0.992. 2e2c0de, 43ad743, cd5ca32, cfdc6a0 and ada0809 together: G 0.3927 to 0.3842, T 0.2986 to 0.2939.

5. Flow refinement

Flow refinement solves a max-flow problem on a stripe around the boundary of each block pair. Without most balanced cuts (eco, ecosocial) it needs the minimal source side, which is the same for every maximum flow; with most balanced cuts (strong, strongsocial) it uses the residual graph, whose set of minimum cuts is the same for every maximum flow but whose tie breaking in the cut enumeration depends on the flow.

  • b3fd20c (a) The flow graph is built as CSR in one pass, with a hashed old-to-new id map. d_qgraph eco 0.926, strong 0.920; with ed2f1a8 G 0.839 to 0.8106.
  • 3d92c87 (a) The BFS depth array of boundary_bfs is reused across calls instead of an O(n) vector per call. d_flow eco 0.846, ecosocial 0.818. With 14bc61e G 0.7489 to 0.7322.
  • 6bec0f2 (a) Push-relabel: char flags instead of vector<bool>, edges of a node through one pointer. d_flow 979 s to 901 s, G 0.7079 to 0.6986.
  • 074274a (a) convert_ds scans each stripe node once for flow edges and outer boundary flags. d_flow 0.962.
  • 4f371ac (a) Early exit: without most balanced cuts, a flow equal to the current cut ends the pair with everything undone, whatever the source set. If the capacity of the edges from the left stripe to the right stripe equals the current cut, the solver stops as soon as the sink holds that much. d_flow eco 0.846, ecosocial 0.793, G 0.6849 to 0.6752.
  • 716c9b9 (a) Most balanced residual graph: the positive-flow back edges of a node are counted once per node instead of scanning the target's adjacency per saturated edge (quadratic at hubs; cnr-2000 strongsocial 8: 0.900). 7ebff1f (a) rate_inner_outer computes weighted node degrees once into an array instead of once per incident edge (also quadratic at hubs; cnr-2000 strongsocial 2: 0.770). d7df6bb (a) dense reusable old-to-new array in convert_ds. Together: total -2.0%, d_flow 0.930, G 0.6694 to 0.6643, T 0.6748 to 0.6613.
  • bfc4e3f (a) Push-relabel discharge keeps distance and excess in locals, the active-node FIFO is a ring, the global relabeling BFS uses an array queue; same order everywhere. d_flow 0.961 (group with 2ed5733).
  • 79276a5 (a) The flow graph keeps its pending-edge and edge buffers for the next flow problem instead of regrowing them (convert_ds was 22% of web-Google eco 256, 3.5 points of it reallocation). With 71b5e60: G 0.4819 to 0.4769.
  • e02ff17 (a) Push-relabel per-node state (excess, distance, active, BFS mark) in one 16-byte record: one cache miss per target instead of up to three.
  • 7b25bfb (b for strong/strongsocial, (a) otherwise) Two-phase push-relabel: phase 1 discharges only nodes with label < n (a maximum preflow); phase 2 returns the remaining excess to the source with exact distances. The result is a maximum flow, but another one than before, so the most balanced cut breaks ties differently. With e02ff17 and 43eca8e: d_flow 0.875, strong 0.929, G 0.4769 to 0.4637, T 0.4077 to 0.3850, Q 0.99944 (strongsocial 1.0014, strong 1.0040).
  • 133f8b1 (a) Without most balanced cuts: maximum preflow on the reversed network (the sink side of the reversed problem is the source side of the minimal cut), no excess return. c1b2a17 (a) per-node arrays from spare buffers kept between flow problems, array queue for the source-set BFS. With 02d686e: eco 0.955, ecosocial 0.967, G 0.4637 to 0.4571, T 0.3850 to 0.3771.
  • 2f68977 (b for strong/strongsocial, (a) otherwise) Boykov-Kolmogorov maximum flow (lib/algorithms/bk_maxflow.h) instead of push-relabel. On these stripe networks (many short augmenting paths between a large source set and a large sink set) BK's two search trees, which are kept and repaired between augmentations, do much less work than push-relabel's relabeling. At termination the source tree is exactly the set reachable from the source in the residual graph, so the configurations without most balanced cuts use it directly and stay bit-identical; with most balanced cuts the residual graph of another maximum flow is used. The reversed network and the preflow-only options are dropped again. 0e1397a One edge pair with capacity w in both directions per stripe edge instead of two edges with zero-capacity partners (half the edges; the residual relation "flow below capacity" is the same). 89b1bcb (a) skip the unused source-set BFS with most balanced cuts. Together: d_flow 0.581, strong 0.840, strongsocial 0.827, G 0.4571 to 0.4219, T 0.3771 to 0.3222, Q 0.99932. Push-relabel is still used by the node separator flow solver.
  • 411c0cc (a) While the flow result is applied the partition is fixed, so "target has a neighbor in block b" is memoized per node and block for that batch. strongsocial 0.964 (d_flow 0.771), G 0.4055 to 0.4025, T 0.3133 to 0.3075.
  • 04989de (a) BK reads the residual capacity of a stripe edge's reverse from the edge itself (capacity + flow; pairs have the same capacity both ways) instead of touching the other node's edge array. A/B 0.997.

6. Label propagation coarsening (social configurations) and clustering

  • ed2f1a8 (a) Raw-pointer inner loop with hoisted invariants. Matching/clustering time ecosocial 0.967, fastsocial 0.988.
  • bdfc092 (a) The visiting order is random, so every node, its edges and its neighbors' cluster ids are cache misses; the loop prefetches node + 3, edges + 2 and the neighbor cluster ids + 1 ahead. coarsen 955 s to 819 s, fastsocial 0.913, ecosocial 0.941, G 0.7322 to 0.7079.
  • 05c1dba (a) ensemble_two_clusterings assigns first-occurrence ids with buckets and a stamp array instead of a hash map. strongsocial coarsening 0.837 (bel strongsocial 2: 0.801).
  • 0f77fd9 (b) Active-node label propagation: a node is visited again only if a neighbor changed cluster since its last visit, and the sweeps stop when an iteration changes nothing. Later sweeps then touch only the nodes whose neighborhood changed instead of all nodes. coarsen 0.702 (ecosocial 0.674, fastsocial 0.677, strongsocial 0.56), G 0.6245 to 0.5929, Q 0.99980. Used only inside coarsening (see the audit fix c1dff95: a template parameter, so the coarsening loop has no extra branch; a runtime flag cost 2.8%).
  • 0ab52e0 (a) The degree order is sorted once per ensemble instead of once per clustering (the graph is the same for all of them), and cluster ids are remapped with an array instead of an unordered_map. coarsen 0.908 (strongsocial 0.849), G 0.5152 to 0.5060, T 0.4562 to 0.4447.
  • a4f1ffb (a) Vote counter and size of a cluster in one array entry (the second sweep reads both). A/B 0.982.
  • 43ad743 (a) Degree order sorted on (degree, node) entries; the comparisons are the same, so the order is identical, without two random degree reads per comparison. A/B 0.989.
  • 002dd72 (a) Ensemble label propagation (strongsocial coarsening, up to 18 clusterings per level) runs on a copy of the graph stored in visiting order, built once per level and shared by all clusterings; clusters are labeled by position and mapped back. Every sweep is then a sequential scan. A/B 0.923 on strongsocial (0.82 to 0.98). With 2db8197 and 47905f0: G 0.3752 to 0.3712, T 0.2920 to 0.2818.
  • 4a1b787 (a) The single-clustering label propagation (fastsocial, ecosocial, initial partitioning coarsening) uses a visiting-order copy as well; the scattered loop is removed. A/B 0.987.
  • eff47d8 (a) The initial partitioning repetitions reuse the LP degree order and the visiting-order copy of the coarsest graph (the graph does not change between repetitions), and node_ordering caches the degree order keyed by the whole degree sequence. A/B 0.993 (luxembourg strongsocial 8: 0.962).

7. GPA matching (fast, eco, strong; also in the initial partitioning of every configuration)

  • 14bc61e (a) Sort (rating, edge) pairs instead of edge ids with an indirect rating lookup per comparison. Matching time fast 0.945, eco 0.967.
  • 7ebff1f see flow section (edge rating).
  • 37c8096 (a) The grow loop prefetches rating, edge and path entries of the edges ahead in rating order.
  • 2de62c9 (b, kaffpa only) The edge list is filtered before the tie-break permutation and the sort: one direction per edge, positive rating, weight bound. The grow loop takes the same candidates in rating order with random ties, but on half the elements and with fewer random draws. Because ties are permuted over a shorter list, the order of equal ratings changes. Enabled by kaffpa only (58415f8), see the audit. With 488f4a6 and 37c8096: strong coarsening 0.586, strong 0.940, eco 0.950, fast 0.888; G 0.4219 to 0.4055, T 0.3222 to 0.3133, Q 1.00045 (eco 1.0061, strong 1.0019).
  • e0b69b3 the sort replica (see section 2) is used for this sort.

8. Contraction and quotient graphs (all class (a))

  • 71b5e60 Quotient graph for clustering contraction: nodes bucketed per block in one array by counting instead of a vector per block (same increasing node order per block).
  • 2db8197 Cluster contraction builds the quotient graph from the coarse mapping directly and leaves the partition indices of the finer graph untouched. A/B 0.997.
  • cfdc6a0, ada0809, ac73175 see above.

9. Most balanced minimum cut (strong, strongsocial; all class (a))

  • 47905f0 The residual graph is built as CSR arrays from the flow graph (no graph_access copy), SCC uses vector stacks, component lists and the component graph use counting buckets. A/B 0.996 on strongsocial/strong (belgium strongsocial 256: 0.986).
  • 16df4ec The four topological sorts per cut (random DFS) run on CSR arrays with an iterative DFS in the same order and with the same random draws. A/B 1.008 alone (neutral within noise). Group with 4a1b787, e0b69b3, eff47d8: G 0.3601 to 0.3527, T 0.2588 to 0.2557.

10. Initial partitioning

  • Initial partitioning runs the same machinery on the coarsest graph many times, so it gains from the 2-way FM changes (cf0ccc5: initial partitioning time -31%; 1be4f2b, cd5ca32), from the GPA and LP changes used by its own coarsening (4a1b787, eff47d8: the repetitions reuse the degree order and visiting-order copy of the coarsest graph) and from fastMaxNodeHeap in bipartition. See the sections above.

11. CLI audit fixes (kaffpa output unchanged)

  • b76e198 label_propagation program back to full sweeps; the rewritten heap moved to fastMaxNodeHeap.h, maxNodeHeap.h restored to master's version (fixes the node_separator / node_ordering crashes).
  • c1dff95 the active-node gating of label propagation as a template parameter (A/B vs before the audit 1.003; a runtime flag cost 1.028).
  • 58415f8 the early GPA filter only when PartitionConfig::gpa_usable_edges_only is set, which app/kaffpa.cpp does.

After each of the three commits, kaffpa wrote the same partitions as before the audit on 2907 of 2907 runs (benchmark x seeds 1 to 3 plus a 6 x 6 x 4 x 3 x 3 grid of small graphs, configurations, k, seeds and imbalances).

12. Cleanup

  • 66bf9a8 removes the per-component timers again and gives the sort replica and the allocator plain names. Identical outputs to the state before (2907 of 2907), timing A/B against the state before the audit fixes 1.003 on 8 jobs x 3 repetitions (noise level; the audit fixes alone measured 1.003 as well).

Parameter change for strongsocial (R5): fewer ensemble clusterings

This is the only change that does less work by design rather than doing the same work faster, so it is listed separately. Please judge it on its own; it can be dropped by reverting d4b7462 and b51bfb4 (two lines in app/configuration.h, standardsnw).

strongsocial coarsens with an ensemble of number_of_clusterings label propagation clusterings per level, combined by overlap. On master the number depends on k: 18 for k = 2 to 3, 17 for k = 4 to 7, 15 for k = 8 to 15, 7 for k = 16 to 31 and 3 for k >= 32.

commit change Q all (3 seeds) Q strongsocial G T
(before) 1.00045 1.0009 0.3712 0.2818
d4b7462 9 clusterings for k < 8 (were 18 / 17) 1.00050 1.0013 0.3657 0.2738
b51bfb4 2 clusterings for k >= 32 (were 3) 1.00078 1.0035 0.3601 0.2588
  • strongsocial total time ratio 0.299 to 0.265 with both changes.
  • 6-seed check of the final branch: Q 1.00030, strongsocial 1.0007; imbalanced 128 vs master 136; grid 132 vs 141.
  • Rejected variant: halving the number for all k gave Q 1.00100 and strongsocial 1.0051 (cut +0.9% at k = 8), so the k = 8 to 31 values are unchanged.
  • The cost in cut is at most 0.35% on strongsocial (3 seeds) and 0.07% on 6 seeds.

Notes for reviewers

  • Global state. Several changes keep buffers between calls in function-level or file-level statics (BK solver arrays, flow graph and push-relabel spare buffers, the pool of stamped_node_map stores, the 2-way FM degree cache, the k-way gain cache, the BFS depth array). This is safe for the single-threaded programs and for repeated library calls in one thread. The library was already not reentrant on master (global random generator, other statics), but concurrent calls from several threads are now even less possible than before, and the buffers stay allocated until the process ends (sized by the largest graph seen).
  • Allocator. small_block_alloc.h is included only by app/kaffpa.cpp (not on Windows), so libkahip, kaffpaE and the other programs keep the system allocator. It reserves 128 GiB of address space with MAP_NORESERVE (only touched pages use memory), falls back to malloc if the reservation fails (for example under ulimit -v), never returns small blocks to the system, and is not thread-safe (kaffpa is single-threaded).
  • Standard library. Two changes reproduce libstdc++ behavior exactly: std_sort_replica (libstdc++'s introsort) and nextBool (the value uniform_int_distribution(0,1) gives on libstdc++). With libstdc++ the class (a) changes are bit-identical to master. With libc++ or MSVC, master's own results already depend on the library; this branch then gives the libstdc++ arrangement everywhere.
  • Code comments that say "rule (b)" mark class (b) changes (tie or random decisions change); everything else is meant to be bit-identical.
  • graph_access now stores its edge arrays with a default-initializing allocator (type change of two private members); the public interface is unchanged.
  • flow_graph is CSR now and needs finish_construction() before use; the node separator flow solver got 8000 that call (vertex_separator_flow_solver.cpp).

Reverted experiments in the history (net zero)

f6d8e1c / 1a5b445 (LP in-loop prefetch for high-degree nodes), 361d294 / 87d40d2 (more move_node prefetches), 59b2279 / 7a9721f (stripe bitmap), 82c92f3 / 02aba47 (LP active flags as a bitset), bb579f2 / f7d698c (two-stage LP prefetch), c2dccc1 / 81c50f3 (matching contraction edge count), df29da0 / 9789438 (SCC stacks on std::vector; 47905f0 later uses vector stacks in its own SCC code). They were slower or neutral and were reverted; I kept them so the history matches the measurements. I can squash them if you prefer.

Hypothesis: top-level scoped timers around graph IO, coarsening, initial
partitioning, refinement and output (plus detail timers for matching,
contraction, k-way FM, quotient-graph refinement and label propagation
refinement outside initial partitioning) cost well below 1% of the running
time, since they are entered a few hundred times per run.
Hypothesis: the std::getline/std::stringstream reader dominates the
non-partitioning time (19% of the per-job time for fast, 14% for fsocial).
Reading the file in one block and scanning it by hand, writing the partition
from one buffer, computing the final cut once and replacing the per-node
std::vector<bool> in max_communication_volume by a stamp array cut the
io+post time by at least 3x and the overall geomean by 4 to 7%.
Hypothesis: vertex_moved_hashtable and the node index of maxNodeHeap are
std::unordered_maps that are only probed, never iterated, so an
open-addressing map gives identical results. Their node allocations account
for much of the 15-20% malloc/free share in callgrind profiles of 2-way FM
and k-way FM; replacing them reduces the partitioning time (initial
partitioning and refinement) by 5 to 15%.
Hypothesis: malloc/free account for 15-20% of the instructions in FM-heavy
jobs (unordered_map nodes of PartialBoundary and the boundary-pair map,
PartitionConfig copies, small per-call objects). Replacing the global
operator new/delete by per-size-class free lists in one reserved address
range (no per-block header, blocks over 512 bytes go to malloc) cuts the
partitioning time by 3 to 8%. KaHIP never orders or hashes by pointer, so
results are unchanged.
…ugh one pointer per node with the same capacity casts
…f the LHS-stripe cut when that equals the current cut (result discarded by the caller)
…st use for k <= 1024, filled on first access through the map), edge cut through the lazy entry
…queue init, replaying the tie draws (038 retest on top of 041)
…f a node once instead of scanning the target's edges per saturated edge
…nged, stop when an iteration changes nothing
…round end), tail undone without boundary work
…with degree cache), tail undone without boundary work
… FIFOs for the active nodes and the global relabeling BFS
…er slots (089, discarded)"

This reverts commit bb579f2.
…its real edge count; edge-target buffer not value-initialized
…lt with its real edge count; edge-target buffer not value-initialized"

This reverts commit c2dccc1.
… new_edge writes the edge's weight and rating
…ectly, partition indices of the finer graph left untouched
…aph, SCC with vector stacks, counting buckets for component lists and the component graph
…built once per level and shared by all clusterings
- label_propagation program: active-node sweeps and the early stop (051) only inside coarsening (match());
  direct calls keep the original full sweeps, so the program's output is identical to the original again.
- the rewritten heap is now fastMaxNodeHeap, used only by the verified k-way FM, 2-way FM and bipartition;
  the original maxNodeHeap is restored verbatim for the node separator local searches, min-degree ordering
  and construct_mapping (the rewrite crashed node_separator and node_ordering on changeKey of nodes not in
  the heap, which the original tolerates).
… sweep; A/B vs e114 total 1.003, the plain flag cost 1.028)
Ablation on edge_partitioning (fast and eco, k 2 and 8, 6 graphs, seeds 1-6, vs original): HEAD Q 1.0342,
reverting 2de62c9 1.0042, reverting 1be4f2b / b544769 / 60f6dc3 1.032 / 1.035 / 1.023. The filter changes
the order of equally rated edges, and the split graphs have many of them. Without the new
gpa_usable_edges_only flag (set by app/kaffpa.cpp) the full list is permuted and sorted as in the original
and filtered afterwards, which keeps the original order. kaffpa identical to e114 on 2907 jobs.
… the small-block allocator

kaffpa prints no extra lines again (the timers were measurement instrumentation only). aae_sort.h is now
tools/std_sort_replica.h, aae_alloc.h is tools/small_block_alloc.h (included only on non-Windows builds,
since it uses mmap); no functional change.
Comment thread app/kaffpa.cpp
#include "random_functions.h"
#include "timer.h"
#ifndef _WIN32
#include "tools/small_block_alloc.h"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Small-object allocator (4373685), kaffpa only, not on Windows. malloc/free were 15 to 20% of the instructions in FM-heavy jobs (hash map nodes, small per-call objects). Size classes of 16 to 512 bytes with free lists in one reserved range, so no per-block header and no search. KaHIP never orders or hashes by pointer, so results are unchanged. Partitioning time -3 to 8%, benchmark G 0.868 to 0.839. Class (a).

Comment thread app/kaffpa.cpp
if(ret_code) {
return 0;
}
partition_config.gpa_usable_edges_only = true;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Audit fix (58415f8): only kaffpa filters the GPA edge list before the sort (class (b), passed the kaffpa quality gate). edge_partitioning lost 1.2% in vertex cut with the early filter because its split graphs are full of equally rated edges; without this flag the original full sort runs and the filter comes afterwards.

Comment thread app/kaffpa.cpp
std::cout << "cut \t\t" << qm.edge_cut(G) << std::endl;
std::cout << "finalobjective " << qm.edge_cut(G) << std::endl;
std::cout << "bnd \t\t" << qm.boundary_nodes(G) << std::endl;
EdgeWeight final_cut = 0, max_comm_vol = 0;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

c447c9a: final cut, boundary nodes and maximum communication volume in one pass over the edges instead of four (the cut was computed twice). Same printed values. A/B 0.968 on small fast jobs, G 0.3842 to 0.3797.

Comment thread app/configuration.h

if(2 <= partition_config.k && partition_config.k <= 3) {
partition_config.number_of_clusterings = 18;
partition_config.number_of_clusterings = 9;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

R5 (d4b7462), the one change that does less work by design: strongsocial uses 9 instead of 18 / 17 ensemble clusterings for k < 8. Q 1.00045 to 1.00050 overall, strongsocial 1.0009 to 1.0013; G 0.3712 to 0.3657, T 0.2818 to 0.2738. Revert this and the next hunk to keep master's strongsocial.

Comment thread app/configuration.h
partition_config.number_of_clusterings = 7;
} else {
partition_config.number_of_clusterings = 3;
partition_config.number_of_clusterings = 2;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

R5 (b51bfb4): 2 instead of 3 clusterings for k >= 32. Q 1.00078 overall (strongsocial 1.0035) on 3 seeds, 1.00030 (strongsocial 1.0007) on 6 seeds; G 0.3657 to 0.3601, T 0.2738 to 0.2588. Halving for all k was tried and rejected (Q 1.00100, strongsocial 1.0051).

}
}

// The degree order of the identity permutation depends only on the degree sequence. Initial
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

eff47d8 / 43ad743: the degree order of the identity permutation depends only on the degree sequence, and initial partitioning repeats the same coarsening, so the last result is reused when the sequence matches. The sort itself runs on (degree, node) entries with the same comparisons. A/B 0.989 and 0.993.

PRINT(std::cout << "no of initial partitioning repetitions = " << reps_to_do << std::endl;);
PRINT(std::cout << "no of nodes for partition = " << G.number_of_nodes() << std::endl;);
if(!((config.graph_allready_partitioned && config.no_new_initial_partitioning) || config.omit_given_partitioning)) {
// the repetitions coarsen the same (unchanged) graph G again: reuse its LP visiting-order copy
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

eff47d8: the repetitions of initial partitioning coarsen the same coarsest graph again; with the reuse graph set, label propagation builds the degree order and the visiting-order copy once for all repetitions. luxembourg strongsocial 8: 0.962.

bnd.fastComputeQuotientGraph(coarser, no_of_coarse_vertices);
//bnd.getUnderlyingQuotientGraph(coarser);
//
// the coarse graph is the quotient graph of the clustering, built from coarse_mapping directly
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

2db8197: the coarse graph is built from the coarse mapping directly, instead of first writing the mapping into G's partition indices and building the quotient graph from them. A/B 0.997. Class (a).

partition_weight_lhs = 0;
partition_weight_rhs = 0;
NodeID dummy_node = G.number_of_nodes() + 1;
// upper bounds for the edges of each block: the degree sums of its nodes (instead of m each)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ada0809: extract_two_blocks allocated m edges for each of the two subgraphs; the degree sums of the blocks are tight upper bounds. A/B 1.000 alone, part of the passenger group with G 0.3927 to 0.3842.

fG.new_edge(sourceID, sink, G.getNodeWeight(rhs_nodes[i]));
}

fG.finish_construction();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

flow_graph is CSR now and lays out its edges in finish_construction(); the separator flow solver builds a flow_graph too and needs the call. Covered by the node_separator path of the CLI audit (no crashes, Q 1.0128 vs a master-vs-master noise of 0.9485).

lib/tools/cpu_hints.h wraps __builtin_prefetch (GCC, Clang), _mm_prefetch
(MSVC x86/x64) or nothing, and floor(log2) of a 64-bit value
(__builtin_clzll, _BitScanReverse64 or a loop). The sort replica uses
ptrdiff_t for lengths and depth (long is 32 bits on Windows), and the graph
reader uses 64-bit file positions on Windows. Same code on Linux.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0