Sparsity, and what elimination costs

The order decides the memory

Four elimination orderings on one matrix give factors of 1,739, 1,354, 1,413 and 1,026 entries. All four factorisations are exact, all four return the same answer, and the one with the better asymptotics is not the one that wins.

The factor is not sparse establishes that elimination creates entries, that they can be counted from the graph before any arithmetic runs, and that the count grows faster than the matrix does. It leaves open the question that decides whether a problem is solvable: how much of that fill is a consequence of the matrix and how much is a consequence of the order the variables were eliminated in.

The answer is: a great deal of it is the order. And the order is free.

Nonzeros in the Cholesky factor of the 12×12 grid Laplacian, by orderingA horizontal bar chart comparing the number of nonzero entries in the Cholesky factor under four elimination orderings, with reference marks for the matrix itself and for a dense factor.natural1739reverse Cuthill–McKee1354minimum degree1026nested dissection1413matrix: 408 entries · dense factor: 10440bandwidth 12 · 4.26× the matrixbandwidth 12 · 3.32× the matrixbandwidth 123 · 2.51× the matrixbandwidth 108 · 3.46× the matrixn = 144, five-point stencilevery ordering fills in; none avoids it
Fig. 1 Four orderings of the same grid Laplacian, ranked by the number of entries in the resulting Cholesky factor. The matrix’s own count and a dense factor’s are marked for scale. Drag the grid size and watch the ranking hold — and one of them fail to overtake.

Why the order is free

This is the premise everything rests on, and it takes four lines to check rather than to assume.

Renumbering the variables replaces A by PAPᵀ for a permutation P. That is a symmetric permutation: the same reordering applied to the equations and to the unknowns. It changes the matrix, it changes the factor, it changes the fill — and it does not change the problem. Solve PAPᵀy = Pb, unpermute y, and the answer is the answer.

The site checks it rather than stating it. On the 7×7 grid, factorised under a minimum-degree ordering and unpermuted, the relative error against the known solution is 3.1·10⁻¹⁶. The permuted matrix has exactly as many nonzeros as the original, which is the other half: a permutation moves entries around and does not create or destroy any.

So ordering is the rare decision that is pure gain. It costs nothing in accuracy, nothing in stability, nothing in the answer — for a symmetric positive definite matrix, where no pivoting is required for stability and the elimination order is therefore unconstrained.

The four

Natural is the ordering the matrix arrived in — for the grid, row by row. It is the baseline and it is what a code gets by not thinking about the question.

Reverse Cuthill–McKee is a breadth-first sweep from a low-degree vertex, taking neighbours in order of increasing degree, then reversed. It optimises bandwidth rather than fill: it tries to push every nonzero close to the diagonal, on the grounds that a factor of a banded matrix is contained within the band. The reversal looks arbitrary and is not — Cuthill–McKee’s ordering and its reverse have the same bandwidth, and the reverse has a profile that is never worse and usually much better.

Minimum degree eliminates, at each step, the variable coupled to the fewest others, then adds the clique that elimination creates and repeats. It is a greedy heuristic with no optimality guarantee whatsoever, and it is what essentially every sparse direct solver has used for forty years.

Nested dissection finds a separator that splits the graph in two, numbers it last, and recurses. It is the only one of the four with an asymptotic guarantee: on a k×k grid it gives O(n log n) fill, against natural ordering’s O(n1.5)O(n^{1.5}).

The numbers

On the 12×12 grid — 144 variables, 408 entries in the matrix’s lower triangle, 10,440 in a dense factor:

Ordering Entries in L Times the matrix
Natural 1,739 4.26
Nested dissection 1,413 3.46
Reverse Cuthill–McKee 1,354 3.32
Minimum degree 1,026 2.51

The spread between best and worst is a factor of 1.7, and the spread between the best and a dense factorisation is a factor of ten. Both are worth having and the second is the one that decides feasibility.

The result that was not expected

The table is ordered by measured fill and nested dissection is third.

It is the ordering with the proof. Its complexity bound is better than minimum degree’s — minimum degree has no bound at all — and on a grid, which is the structure nested dissection was designed for, it loses to the heuristic by 38%.

That is not a bug in the implementation, and it is not a bad grid size. It holds at every size on the slider, from 6×6 to 16×16. The crossover, where the asymptotics start to pay, is further out than this figure reaches.

The reason is that the asymptotic statement is about the leading term and the sizes anybody draws are governed by the constant. Nested dissection numbers separators last, which is optimal in the limit and wasteful at small sizes where the separator is a large fraction of the whole graph. Minimum degree makes locally good choices with no plan at all, and on a moderate grid a sequence of locally good choices is very hard to beat.

A complexity class is a statement about a limit and a matrix has a size, which is the same lesson as the bound that is never attained reaching from the elimination field: the growth factor’s bound is 5.5·10¹¹ and the measured median is 3.23. In both cases the theory is correct and the number it gives is not the number that governs the computation.

The honest position is that production solvers use both, and choose between them by trying them — which is an unsatisfying answer that happens to be the true one. Modern codes tend to use nested dissection at the top levels, where the graph is large enough for the asymptotics to matter, and switch to minimum degree on the subgraphs once they are small.

Fill growth under natural: the factor rises as n^1.49A log-log plot of nonzero count against matrix dimension. The matrix's own count is a straight line of slope one; the factor's is steeper; a dense factor is steeper still.10²10².³10²10³10⁴n (dimension)nonzerosdense factorfactor, n^1.49matrix, n^1.05grid Laplacians from 5×5 to 12×12fitted, not quoted
Fig. 2 The same four orderings as growth exponents rather than counts. A better ordering lowers the line; nested dissection also lowers its slope, which is the property that eventually wins and has not won yet at any size drawn here.

What minimum degree is actually doing, and what it costs to do it

The heuristic that wins is worth a closer look, partly because it is the one in the libraries and partly because the plain version described above is not the one they run.

At each step it computes the degree of every remaining vertex, picks the smallest, eliminates it, and adds the resulting clique. The rationale is direct: eliminating a vertex of degree d creates at most d(d−1)/2 edges, so taking the smallest d minimises the immediate damage. It is greedy in the strict sense — it optimises the current step with no consideration of the next.

The trouble is the bookkeeping. Adding a clique changes the degrees of everything in it, so degrees must be recomputed, and the cliques accumulate until the graph being maintained is denser than the matrix. A naive implementation — which is what this site’s is, because at these sizes clarity is worth more than speed — costs more than the factorisation it is choosing the order for.

Production implementations spend essentially all their complexity on avoiding that. Quotient graphs represent a clique by a single node rather than by its edges, so the elimination graph never becomes dense. Approximate minimum degree replaces the exact degree with a bound that is cheap to update, and is the standard because the approximation costs a little fill and saves a great deal of time. Supernodes detect vertices with identical adjacency and eliminate them together, which is both faster and gives the numeric phase dense blocks to work on.

The pattern is worth noting: forty years of work on this ordering has gone almost entirely into computing it faster, and hardly any into computing a better one. That is a judgement about where the remaining value is, and the table above supports it — the spread between the four orderings is a factor of 1.7, and the spread between a good implementation and a naive one is far larger.

Bandwidth is a different objective, and it shows

Reverse Cuthill–McKee is optimising something else, and putting it in a fill table slightly misrepresents it.

A band solver stores everything within the bandwidth, whether or not it is nonzero, and its cost is therefore set by the bandwidth alone. For such a solver RCM is exactly the right ordering, and the figure asserts what it promises: it never increases the bandwidth, and on the grid it reduces it substantially.

For a general sparse solver, which stores only what is nonzero, bandwidth is the wrong target — a matrix can have a large bandwidth and very little fill. RCM lands third-best on fill here because reducing bandwidth reduces fill as a side effect rather than as an aim.

Which is worth naming as a general trap: an ordering is only good relative to a cost model, and comparing orderings without saying which storage scheme is in use compares them at cross purposes. The figure prints the bandwidth beside each bar for that reason.

Nested dissection, and why its guarantee is the interesting one

The ordering that comes third is the only one whose behaviour can be predicted rather than measured, and the argument for it is short enough to give.

Take the k×k grid and cut it with a vertical line of k vertices. Number everything to the left first, everything to the right second, and the separator last. Now consider what elimination does: a variable on the left and a variable on the right are not adjacent, and eliminating left-hand variables can never couple them, because every path between the two halves passes through the separator — which has not been eliminated yet.

So the two halves fill in independently, and the only coupling created between them is within the separator’s own block, which is k×k and dense. Recurse on each half and the same argument applies again. The total is a sum over levels of separator blocks, and it comes to O(n log n) entries against natural ordering’s O(n1.5)O(n^{1.5}).

The construction generalises: what it needs is a small separator, a set of vertices whose removal splits the graph into pieces of bounded size. Planar graphs have separators of size O(√n), which is the theorem that makes the whole approach work for two-dimensional problems, and three-dimensional grids have separators of size O(n2/3)O(n^{2/3}), which is why the exponents are worse there.

What the argument does not supply is a way to find a good separator on a graph that is not a grid. On the grid it is a line, and this site’s implementation uses that directly rather than searching. General-purpose implementations use multilevel graph partitioning to find one, and the quality of that partitioner is most of what decides whether nested dissection beats minimum degree on a particular matrix.

What no ordering does

The refusal in the library is the belief this essay could otherwise create, and it is worth stating plainly.

No ordering removes fill. The best of the four still produces a factor 2.5 times the size of the matrix. Every ordering, at every grid size drawn, adds entries — that is asserted for all four on every frame, and an ordering that produced zero fill on this matrix would fail the build.

The arrowhead in two ends of the same arrow is the exception that makes the belief tempting: there, one ordering genuinely gives no fill at all. It is a very special structure, and reading it as the general case is the misunderstanding the refusal exists to catch.

And the underlying reason nothing better is available: finding the ordering that minimises fill is NP-hard. Every ordering in this table is a heuristic, including the one with the asymptotic guarantee — the guarantee is about a bound on the fill, not about achieving the minimum. There is no algorithm anybody expects to find that would fill the bottom row of that table with the true optimum.

What is asserted here

Every ordering still fills in, all four, at every grid size.

Every ordering beats a dense factorisation, which is the other end of the same claim and would catch an ordering that had gone catastrophically wrong.

Some ordering beats the natural one — the claim that the decision is worth making at all.

RCM does not increase the bandwidth, which is the thing RCM is actually for.

And a symmetric permutation returns the same solution, to 3.1·10⁻¹⁶, with the permuted matrix having the same number of entries as the original.

The refusals: the claim that two orderings give the same fill must throw, and so must the claim that a good ordering eliminates fill. Both do.

The other cost the count does not show

Fill is measured in entries, and entries are what decide whether the factor fits. They are not what decides how long the factorisation takes.

The arithmetic cost of eliminating a vertex of degree d is about d²/2 operations, so the total work is the sum of squared degrees over the elimination — a quantity that grows faster than the fill it produces. On the model problem the fill grows as n1.5n^{1.5} and the work as n2n^2, and the ratio between them widens with size.

That means the ordering table understates its own case. An ordering that reduces fill by a factor of 1.7 reduces the operation count by rather more than 1.7, because the entries it avoided creating were also entries later steps would have had to process. Both numbers are reported by a real solver’s symbolic phase, and the operation count is the one to look at when time rather than memory is binding.

There is a third quantity, and on current hardware it is often the one that matters most: how much of the work happens in dense blocks. A factorisation organised into supernodes runs its arithmetic as dense matrix-matrix products, which reach a large fraction of a machine’s peak throughput, while the same operation count scattered over individual entries does not. Two orderings with identical fill and identical operation counts can differ severalfold in time for that reason alone — which is a consideration no count in this essay captures, and a reason the choice between orderings is ultimately settled by measurement.

Where this leaves a practitioner

Three things, and the first is nearly always enough.

Use the library’s default and do not think about it. Every sparse solver applies a fill-reducing ordering automatically, usually approximate minimum degree, and the difference between it and the best available choice is tens of per cent. The difference between it and no ordering is the factor of 1.7 in the table, and rises with size.

Look at the fill count when memory is the binding constraint. The symbolic phase reports it before the numeric phase allocates, so the question “will this fit” is answerable in advance and cheaply. That is a more definite planning basis than almost anything else in this subject.

And reorder once, not every time. For a sequence of solves with the same structure and changing values — which is what a time-stepping code does — the ordering and the symbolic factorisation depend only on the pattern. They are computed once and reused, and only the numeric factorisation repeats.

The arrowhead matrix, eliminated from each endThree sparsity plots. The first shows an arrowhead matrix with a dense first row and column. The second shows its Cholesky factor, completely dense. The third shows the factor obtained after moving the dense row to the end, which has no fill at all.the matrix43 entriestip eliminated first253 entriestip eliminated last43 entries‖A − LLᵀ‖/‖A‖, tip first1.4·10⁻¹⁶‖A − LLᵀ‖/‖A‖, tip last0dense factor is n(n+1)/2 = 253 · sparse factor is 2n − 1 = 43one row swapped to the endnothing numerical chose between them
Fig. 3 The extreme case, where the same decision spans everything there is to span. One row moved from the front of the ordering to the back, and the factor goes from completely dense to no fill at all — with both factorisations exact to rounding.
The 12×12 grid Laplacian and its Cholesky factor, ordered by naturalTwo square sparsity plots side by side. The left shows the nonzeros of the matrix; the right shows the nonzeros of its Cholesky factor, with the entries created by elimination marked in a second colour.the matrix, lower triangle408 entriesits Cholesky factor1739 entries · 1331 created‖A − LLᵀ‖/‖A‖1.4·10⁻¹⁶fill, symbolic1331fill, numeric1331n = 144 · density 3.2% · bandwidth 12same matrix, renumberedthe answer is identical to rounding
Fig. 4 And the same four orderings drawn as structure rather than counted. The left panel is identical in every frame; everything that moves is on the right, and none of it is visible to anybody who only ever sees the answer.
Growth factor under partial pivoting: the bound, the worst case, and realityGrowth factor against matrix size on a logarithmic vertical axis. The two-to-the-n bound rises as a straight line; Wilkinson's matrix sits exactly on it; random matrices stay near one.0816243240110²10⁴10⁶10⁸10¹⁰10¹²10¹⁴matrix size ngrowth factor max|u| / max|a|the 2ⁿ⁻¹ boundworst of 30 randommedian randomWilkinson's matrix sits on the bound30 Gaussian matrices per sizeat n = 40: bound 5.5·10¹¹, worst 4.8
Fig. 5 The same lesson from the elimination field. A bound of 5.5·10¹¹ against a measured median of 3.23 — theory that is correct and gives a number which does not govern the computation, which is exactly nested dissection’s position in the table above.
Gaussian elimination on a 4×4, one step at a timeFour copies of the same matrix: as given, and after each of the three elimination steps. The pivot in use is outlined and the entries reduced to zero are greyed.21-13-3-121-212-443-12as givenrows in the order 1 2 3 443-1201.251.252.502.51.5-30-0.5-0.52after step 1pivot 443-1202.51.5-3000.5400-0.21.4after step 2pivot 2.543-1202.51.5-3000.540003after step 3pivot 0.5‖PA − LU‖/‖A‖0largest multiplier0.75row order 4 3 2 1the pivot is chosen
Fig. 6 The arithmetic each ordering is rearranging. Every entry a step modifies in a position that held a zero is one unit of the counts above, and the ordering decides how many such positions there are.
Incomplete Cholesky on the 12×12 grid: κ 67.8 → 6.84A semi-logarithmic plot of relative residual against iteration for conjugate gradients with and without an incomplete Cholesky preconditioner, the preconditioned curve falling faster.061218243036424810⁻¹¹10⁻⁹10⁻⁷10⁻⁵10⁻³10⁻¹iteration‖r‖ / ‖b‖plain CGIC(0) CGwhat the preconditioner didκ(A)68κ(L⁻¹AL⁻ᵀ)6.8‖A − LLᵀ‖/‖A‖0.0842D Laplacian, n = 144√κ ratio predicts 3.15×
Fig. 7 Where the ordering decision reaches the other field. An incomplete factorisation keeps the matrix’s own pattern, so it sidesteps the question this essay answers — and pays for that with a factor that is no longer exact.