Fill-reducing ordering

Before factoring, feral permutes the matrix to reduce fill-in — the new nonzeros created during elimination. A good ordering can change the factor size and factorization time by orders of magnitude, so the choice of ordering is the single most important tuning knob for large sparse problems. All orderings are clean-room implementations in pure Rust (workspace crates feral_amd, feral_amf, feral_metis, feral_scotch, feral_kahip); none link the original C/Fortran libraries.

Choosing a method

The method is a feral::symbolic::OrderingMethod, set on the Solver:

use feral::Solver;
use feral::symbolic::OrderingMethod;

let solver = Solver::new().with_ordering(OrderingMethod::Auto);

The variants:

VariantAlgorithm
AmdApproximate Minimum Degree.
AmfApproximate Minimum Fill (HAMF, the MUMPS variant).
MetisNDMETIS-style multilevel nested dissection.
ScotchNDScotch-style nested dissection.
KahipNDKaHIP flow-based nested dissection with data reduction.
AutoAdaptive: pick a method from cheap pattern metrics.
AutoRaceRun several candidates and keep the smallest factor.

Local (greedy) orderings

  • Amd — Approximate Minimum Degree eliminates the vertex of smallest approximate degree at each step, using a quotient-graph model with element absorption and supervariable detection. It is fast, low-memory, and the strongest general-purpose choice for small and medium matrices. This is the default for symbolic_factorize.
  • Amf — Approximate Minimum Fill scores by an estimate of the fill a pivot would create rather than its degree. It is the HAMF4 variant used by MUMPS, and tends to beat AMD slightly on the medium KKT systems that dominate interior-point workloads.

Nested dissection orderings

Nested dissection recursively finds a small vertex separator, numbers it last, and recurses on the two halves. It produces asymptotically better orderings than greedy methods on large, mesh-like graphs.

  • MetisND — multilevel nested dissection: coarsen the graph by heavy-edge matching, bisect at the coarsest level, then uncoarsen with Fiduccia–Mattheyses refinement, falling back to AMD on small leaves.
  • ScotchND — multilevel nested dissection with graph compression and direct vertex-separator refinement.
  • KahipND — flow-based nested dissection: it computes separators with max-flow/min-cut local improvement and applies exhaustive data reduction (degree-1/2, twin, and indistinguishable-vertex rules) before dissecting. Highest quality and highest setup cost; it is never chosen automatically.

Automatic selection

  • Auto chooses a method from a few cheap pattern metrics. Since 0.25.0 every branch ends at Amf: very large, very sparse graphs (n > 100_000, average degree < 5) went to Amd until then, and now go to Amf too (issue #246; on the Primal2_1000 LP KKT, n = 3.86M, a refactorization dropped from 999 s to 84 s, at a ~15% cost on PDE2_0000). Nested dissection's separator search does not pay off there, and AMF, like AMD, is a local ordering.

    Note: Auto does not currently select any nested-dissection method. The size rule would pick MetisND above n = 10_000, but a later catch (issues #67 and #73, measured on real factor-and-solve wall-clock across the corpus) reroutes every such decision to Amf. If you want nested dissection you must ask for it by name, or use AutoRace / Solver::with_ordering_race. The gates are tuned against the benchmark corpus and may change between releases.

  • AutoRace runs the symbolic analysis for each candidate ordering in feral::symbolic::race_candidates(n) and keeps the one whose factor is predicted smallest. Below RACE_LARGE_N (1 000 000) the candidates are RACE_CANDIDATES — Amd and MetisND; at or above it they are RACE_CANDIDATES_LARGE — Amd, MetisND, ScotchND and Amf (0.25.0). The MC64 matching behind LdltCompress is computed once per race and shared by every arm. It costs roughly the sum of those symbolic passes, worth it when one factorization is reused for many solves, since symbolic analysis is amortized and the numeric phase dominates.

    The candidate list shrank in 0.18.0: it previously raced ScotchND and KahipND as well, and measured over four real KKT patterns those two never won and were the two most expensive to analyse.

    Changing this list changes solver outcomes, not just timing. Selection is by predicted fill, and least fill is not the same as most numerically sound. On a near-singular KKT the arm the race keeps decides which inertia an interior-point host sees, and so which trajectory it takes. An Amf arm was tried during 0.18.0 development and made one collocation model converge to a point of local infeasibility; it was removed again.

    Selection is by predicted fill, which is not the same as predicted speed. When the two disagree it can pick a slightly slower ordering; Solver::with_ordering_race measures the numeric factorization instead, at a higher one-off cost.

Symbolic analysis (ordering + supernode detection) runs once and is cached on the Solver; refactorizing the same pattern with new values reuses it. So an expensive ordering like KahipND or AutoRace is cheap in amortized terms across a Newton run or a refactorization loop.

Choosing for your workload

Auto is tuned for the benchmark corpus as a whole. Two workload shapes do measurably better with an explicit choice, and the difference is large enough to be worth one line of configuration.

Collocation, optimal control, PDE-in-time — ask for MetisND. These are space-by-time product patterns: a sparse spatial graph crossed with a time axis. Nested dissection finds the separators; the local heuristics do not. Measured steady-state factor time per iterate, lower is better:

modelAmf (what Auto picks)MetisND
gas-network transient control, n = 224,646337.6 ms131.4 ms
2-D Poisson boundary control, n = 607,500509.5 ms440.3 ms
minimum-lap-time collocation, n = 126,02885.0 ms42.7 ms

Thin chains, QPs and small-front problems — leave Auto alone. On the same measurement MetisND is the wrong answer by a similar margin: 21.9 ms against 17.5 ms on a beam-control chain, 30.8 against 20.8 on a discrete-time control problem, 33.1 against 23.8 on a sparse QP.

There is no cheap structural test that separates the two groups — average degree puts members of each on both sides of the boundary — so this is a judgement about your problem, not something the library can infer.

If you would rather not hardcode it, and you factor one pattern many times (any interior-point or Newton loop), Solver::with_ordering_race measures instead of guessing: it runs each candidate once and keeps the fastest for that pattern. Across the ten families above it lands within 5% of the best fixed arm on 29 of 31 matrices. It costs a few extra factorizations once per pattern, which breaks even after roughly 15 — free inside a solve, a loss for a one-shot factorization.

Bounding memory

On very large systems, the wrong ordering can need more memory than the machine has, and the process can be killed during analysis, before any factorization starts. Solver::with_max_factor_bytes(Some(bytes)) turns that into an error you can handle:

let mut solver = Solver::new().with_max_factor_bytes(Some(8 << 30)); // 8 GiB
match solver.factor(&kkt, None) {
    FactorStatus::FatalError(FeralError::MemoryBudgetExceeded {
        predicted_bytes, stage, ..
    }) => { /* fall back: another ordering, a smaller model, ... */ }
    status => { /* as usual */ }
}

There are two checks. The first runs right after the ordering, on the predicted factor size, before the analysis allocates anything that scales with the factor. The second runs at the end of the analysis, on WorkEstimate::peak_bytes: the predicted high-water of Solver::factor on the sequential driver. That figure counts the factor as stored (dense supernode blocks, including the explicit zeros amalgamation adds), each supernode's index data, the analysis the Solver keeps, the numeric workspace and caches, and the contribution blocks, walked in the order the driver allocates and frees them. The same budget is available as SupernodeParams::max_factor_bytes for callers of symbolic_factorize_with_method.

The parallel driver holds more at once: blocks of finished subtrees waiting for their parent, and one workspace and frontal buffer per worker. WorkEstimate::peak_bytes_parallel(threads) bounds that over every schedule. When the budget admits peak_bytes but not the parallel bound, the Solver runs that factorization on the sequential driver instead of refusing (same factors, slower); Solver::ran_sequential_for_budget() says when this happened.

Measured heap high-water against the prediction (the input matrix, which is yours, excluded):

matrixdriverpredictedmeasured
Primal2_1000 LP KKT, n = 3.86M, AMFsequential4.92 GB4.86 GB
the same, AMDsequential8.58 GB8.56 GB
the same, AMFparallel, 4 threads10.1 GB (bound)5.9 GB
the same, AMDparallel, 4 threads34.9 GB (bound)11.7 GB

The sequential prediction is close. The parallel bound is loose when many subtrees have large fronts, which is why it switches drivers rather than refusing. Both assume no delayed pivots, which move columns into larger fronts; on hard indefinite systems leave some headroom. The process also pays allocator overhead on top of the heap (10–15% with 4 threads on the matrix above).

Bounding time

Solver::with_interrupt(Some(feral::Interrupt::after(duration))) stops the symbolic analysis (ordering, matching, supernode detection) once the deadline passes. Interrupt::none().with_flag(flag) does the same when another thread sets an Arc<AtomicBool>. Either way, factor returns FactorStatus::FatalError(FeralError::Interrupted { stage }), nothing is cached, and the Solver stays usable.

let deadline = Instant::now() + remaining_time;
solver.set_interrupt(Some(Interrupt::at(deadline)));
match solver.factor(&kkt, None) {
    FactorStatus::FatalError(FeralError::Interrupted { stage }) => {
        /* report a timeout, not a factorization failure */
    }
    status => { /* as usual */ }
}

The check runs at safe points inside the orderings (every 64 pivots for AMD/AMF; each level and refinement pass for METIS and SCOTCH; each recursion node for KaHIP), inside the MC64 matching, and between stages. So the time past the deadline is bounded by one of those steps rather than by the whole analysis. The numeric factorization itself does not check the interrupt.

References

Greedy orderings:

  • P. R. Amestoy, T. A. Davis, and I. S. Duff. An Approximate Minimum Degree Ordering Algorithm. SIAM J. Matrix Anal. Appl. 17(4):886–905, 1996. doi:10.1137/S0895479894278952
  • P. R. Amestoy, T. A. Davis, and I. S. Duff. Algorithm 837: AMD, an Approximate Minimum Degree Ordering Algorithm. ACM Trans. Math. Softw. 30(3):381–388, 2004. doi:10.1145/1024074.1024081
  • A. George and J. W. H. Liu. Computer Solution of Large Sparse Positive Definite Systems. Prentice-Hall, 1981. ISBN 0-13-165274-5. (Minimum-fill and elimination-tree foundations.)

Nested dissection:

  • A. George. Nested Dissection of a Regular Finite Element Mesh. SIAM J. Numer. Anal. 10(2):345–363, 1973. doi:10.1137/0710032
  • R. J. Lipton, D. J. Rose, and R. E. Tarjan. Generalized Nested Dissection. SIAM J. Numer. Anal. 16(2):346–358, 1979. doi:10.1137/0716027
  • G. Karypis and V. Kumar. A Fast and High Quality Multilevel Scheme for Partitioning Irregular Graphs. SIAM J. Sci. Comput. 20(1):359–392, 1998. doi:10.1137/S1064827595287997
  • F. Pellegrini and J. Roman. Scotch: A Software Package for Static Mapping by Dual Recursive Bipartitioning of Process and Architecture Graphs. HPCN Europe, LNCS 1067:493–498, 1996. doi:10.1007/3-540-61142-8_588
  • P. Sanders and C. Schulz. Engineering Multilevel Graph Partitioning Algorithms. ESA 2011, LNCS 6942:469–480. doi:10.1007/978-3-642-23719-5_40
  • W. Ost, C. Schulz, and D. Strash. Engineering Data Reduction for Nested Dissection. ALENEX 2021, 113–127. doi:10.1137/1.9781611976472.9

Refinement primitive:

  • C. M. Fiduccia and R. M. Mattheyses. A Linear-Time Heuristic for Improving Network Partitions. 19th Design Automation Conference, 175–181, 1982. doi:10.1109/DAC.1982.1585498