Where the flop count stopped predicting the time

The message and the word

Three factorisations of one matrix on sixteen processors: 48 communication rounds, 4, and 4. The words sent are 1,170, 1,170 and 2,160 — so the method with the fewest rounds sends the most words, and the count that separates the three is the one no operation count can see.

Worth reading first: A reduction that changes the order · Orthogonal is a number.

The cost field exists because counting arithmetic stopped predicting anything. Its model counts words moved between a fast memory of M words and a slow one, and with that counter it measured the field’s founding result: a blocked and an unblocked elimination perform exactly 72,568 operations, choose the same pivots, return a residual agreeing to every digit, and move 41,332 words against 19,476.

That model has a shape it cannot express, and the field wrote the gap down as a deferral: parallel communication counted in messages rather than words. A machine with p processors charges twice — once for how much data crosses the network, and once for how many times the processors have to stop and talk to each other. The second is latency, it is of the order of a microsecond however few words the message carries, and a word of bandwidth is of the order of a nanosecond. A thousand words in one message and one word in one message cost about the same. One word in a thousand messages costs a thousand times more.

No duration appears anywhere in this essay, for the reason the field states about its own counts: a duration is a fact about a machine and a count is a fact about an algorithm.

Communication for a 512×12 factorisation on 16 processorsTwo counts for the same factorisation. Rounds on the critical path: 48 for the column sweep, 4 for the reduction tree, 4 for Cholesky QR — a factor of n between the first and the other two. Words sent: 1170, 1170 and 2160 — the sweep and the tree send the same number, and the method with the fewest rounds sends the most.rounds on the critical pathHouseholder sweep48reduction tree4Cholesky QR4words sentHouseholder sweep1170reduction tree1170Cholesky QR2160two counts, two rankingsrounds, sweep ÷ tree12words, Cholesky ÷ tree1.8arithmetic, tree ÷ sweep1.5the rounds separate the threeand the words do not
Fig. 1 Two counts for the same 512×12 factorisation on sixteen processors. Rounds on the critical path: 48 for the column sweep, 4 for the reduction tree, 4 for Cholesky QR. Words sent: 1,170, 1,170 and 2,160. The rounds separate the three by a factor of twelve; the words rank them differently and by much less. Drag the processor count and the ratio does not move.

The model, and what is counted

p processors, each holding a horizontal slice of a tall matrix. Three quantities, counted by a counter the algorithms call rather than by a formula written beside them:

  • rounds — communication steps on the critical path, which is the latency cost;
  • messages — point-to-point sends in total;
  • words — numbers crossing the network, which is the bandwidth cost.

The calls sit next to the arithmetic they belong to, because that is the only place a model like this can be wrong. A count summarised at the end of a function is a claim about what a distributed implementation would do; a count next to the line that needs the data is a description of it.

Three factorisations of one matrix

Householder, column by column. Each column needs its norm over all p slices, which is a reduction, and the reflector’s inner products with the trailing columns need another. n columns, log₂p levels each: n log₂p rounds. This is the algorithm matrix.js implements and it is the one that talks the most.

The reduction tree. Factorise each slice locally, then combine R factors pairwise up a binary tree: log₂p rounds, whatever n is. The breadth phase measured its arithmetic: 1.65·10⁻¹⁵ backward error against a Householder sweep’s 9.95·10⁻¹⁵ on a 512×12 matrix at κ = 7,151, with the error not growing with the depth of the tree — 3.38, 4.26, 1.65, 1.48·10⁻¹⁵ at depths one to four.

And Cholesky QR. Form G = AᵀA — one reduction of an n×n matrix — factor G = RᵀR, set Q = AR⁻¹. One reduction, which is the fewest any factorisation can use.

p sweep rounds tree rounds Cholesky rounds sweep words tree words Cholesky words
4 24 2 2 234 234 432
8 36 3 3 546 546 1,008
16 48 4 4 1,170 1,170 2,160
32 60 5 5 2,418 2,418 4,464

The sweep’s rounds are exactly n times the tree’s at every p — 12 here — because the sweep synchronises once per column and the tree once per level. And the words do not separate them at all: the sweep and the tree send the identical number, and the method with the fewest rounds sends nearly twice as many as either, because a Gram matrix is a square and an R factor is a triangle.

A model that counts only words ranks these three wrong. That is the deferral, discharged: the whole reason the tall-skinny QR was developed is invisible to the field’s existing counter, and the refusal this essay publishes is fed exactly that — the claim that counting words separates the sweep from the tree, on a case where the two counts are equal.

And the tree does more arithmetic, not less

A communication-avoiding algorithm is not a cheaper algorithm. The tree performs p local factorisations of (m/p)×n blocks plus p − 1 combines of 2n×n blocks, which by the standard operation count 2mn² − 2n³/3 comes to 178,560 against the sweep’s 146,304 at m = 512, n = 12, p = 8 — 22% more.

It is worth having anyway because the arithmetic is local and the communication is not, which is the whole premise of the field. But it is a trade, it is the opposite way round from what “avoiding” tends to suggest, and it is one of this family’s published refusals.

The price of the fewest messages

‖QᵀQ − I‖ of the implied Q, against the condition numberLoss of orthogonality against κ, both axes logarithmic, for three factorisations of the same 256×8 matrix. The column sweep and the reduction tree run from 2.7·10⁻¹⁴ to 1.5·10⁻¹⁰. Cholesky QR — the one with a single reduction — runs from 2.3·10⁻¹³ to 1.8·10⁻⁵, a fitted slope of 1.97 against the others' near-flat one.10²10³10⁴10⁵10⁶10⁻¹⁴10⁻¹²10⁻¹⁰10⁻⁸10⁻⁶condition number κ‖QᵀQ − I‖Cholesky QRsweeptreethe price of one roundfitted slope, Cholesky QR2‖QᵀQ − I‖ at κ = 10·10⁵1.8·10⁻⁵the sweep's, at the same κ1.5·10⁻¹⁰one reduction instead of nand the condition number squared
Fig. 2 ‖QᵀQ − I‖ of the Q each method’s R implies, against the condition number, both axes logarithmic. The sweep and the tree run from 10⁻¹⁴ to 10⁻¹⁰ across five decades. Cholesky QR runs from 2.3·10⁻¹³ to 1.8·10⁻⁵ — a fitted slope of 1.97, which is κ².
κ sweep tree Cholesky QR
10² 2.7·10⁻¹⁴ 1.2·10⁻¹⁴ 2.3·10⁻¹³
10³ 1.6·10⁻¹³ 6.3·10⁻¹⁴ 3.9·10⁻¹¹
10⁴ 3.4·10⁻¹² 8.6·10⁻¹³ 2.3·10⁻⁹
10⁵ 7.1·10⁻¹² 1.5·10⁻¹¹ 3.2·10⁻⁷
10⁶ 1.5·10⁻¹⁰ 5.1·10⁻¹¹ 1.8·10⁻⁵

The orthogonality is measured the same way for all three: ‖QᵀQ − I‖ with Q = AR⁻¹. That is a uniform quantity and it is the one a real code meets — Cholesky QR forms Q exactly this way, and a least-squares solve through any of these R factors is exactly this Q applied to a right-hand side. Comparing each method’s own internal Q would be comparing three different objects, and would let the method that never forms one escape the comparison.

The slope is the assertion rather than any single value, because a slope is a claim about the mechanism and a number at one κ is a claim about one matrix.

Which is a square this site has met twice already

κ² is not a new quantity here. The road that squares the problem measures what forming AᵀA does to a least-squares problem: the condition number squares, and below ε = √u the Gram matrix of a perfectly ordinary matrix comes out exactly singular — every entry of AᵀA equal to one.

Cholesky QR forms AᵀA. That is not an analogy or a family resemblance; it is the same line of arithmetic, appearing in a different field for a different reason, with the same consequence. What is new is why somebody would do it: not because the normal equations are the obvious derivation, but because AᵀA is a sum over the slices and therefore one reduction, and one reduction is the minimum.

So the trade is not between speed and elegance. It is the same κ² this site has measured twice, being paid for a round trip.

Least squares by QR and by the normal equations in binary32Relative error of the computed coefficients against epsilon, on log axes. The QR route is a flat line near the bottom; the normal-equations route climbs and then stops, at the epsilon where the cross-product matrix becomes exactly singular.10⁻⁸10⁻⁷10⁻⁶10⁻⁵10⁻⁴10⁻³10⁻²10⁻¹10⁻⁹10⁻⁷10⁻⁵10⁻³10⁻¹10¹ε in Läuchli's matrix (smaller ε, larger κ)relative error in the coefficientsAᵀA exactly singularnormal equationsQRκ from 1.7·10⁸ to 17the cliff is at √u = 2.4·10⁻⁴
Fig. 3 The same square in the least-squares field, at 24 bits: the normal-equation route loses accuracy like κ² and then, below ε = √u, stops having an answer at all. The essay above is that curve arriving as a decision about a network.

Past the cliff: refuse, or lie, and it is erratic which

Past the cliff: what each method returnsLoss of orthogonality at four condition numbers past κ²u = 1. Cholesky QR returns a factor whose implied Q is 0.37 away from orthogonal at κ = 10⁸ and 1.49 at 10¹² — and at 3·10¹⁰ it refuses outright, on a pivot of -6.5·10⁻¹⁷. The sweep and the tree return a usable factorisation of every one of these matrices.‖QᵀQ − I‖ of the implied Qκ = 10⁸, Cholesky0.37κ = 10⁸, sweep8.5·10⁻⁹κ = 10¹⁰, Cholesky1.3κ = 10¹⁰, sweep3·10⁻⁷κ = 3·10¹⁰, Choleskyrefusedκ = 3·10¹⁰, sweep6.7·10⁻⁶κ = 10¹², Cholesky1.5κ = 10¹², sweep1.4·10⁻⁴the safe run is the one that failsrefusals in the range1wholly non-orthogonal returns2the pivot it refused on-6.5·10⁻¹⁷one of these outcomes is safeand it is the refusal
Fig. 4 Four condition numbers past κ²u = 1. At 10⁸ Cholesky QR returns a factor whose implied Q is 0.37 from orthogonal; at 10¹⁰, 1.27, which is total loss; at 3·10¹⁰ it refuses, on a pivot of −6.5·10⁻¹⁷; and at 10¹² it succeeds again and returns 1.49. The sweep and the tree return a usable factorisation of every one of those matrices.

Read the last two rows together. The method declines a matrix at κ = 3·10¹⁰ — the Gram matrix is numerically indefinite, Cholesky meets a nonpositive pivot, and there is nothing to return — and then succeeds on a harder matrix at 10¹², handing back a triangular factor whose implied Q is not orthogonal in any sense.

The failure that is safe is the refusal. The failure that is dangerous is the success, and which of the two happens is decided by rounding near a boundary rather than by the conditioning. This site has recorded that shape once before, in the mixed-precision field: near a threshold the outcome is genuinely erratic — at κu ≈ 6 the same format finishes 40× short at one matrix size and 7,000× at another.

Both behaviours are asserted, and the assertion is written to require both. An assertion that the method refuses past the cliff would describe something that reliably declines, and it does not.

What this says about choosing a factorisation

Three statements, in the order a decision would use them.

Count rounds, not words. On the shapes this essay draws, the word counts rank the three methods in an order that has nothing to do with what a machine charges for, and the round counts differ by a factor of n.

The tree is the answer for a tall matrix, and its cost is 22% more arithmetic, all of it local. Its backward error does not grow with the depth of the tree, which the breadth phase measured separately at depths one to four — so the reduction can be as deep as the machine is wide.

And Cholesky QR is usable exactly when κ² u ≪ 1, which is a computable condition and is the whole of its applicability. Where it holds, one reduction is genuinely one reduction and the method is excellent. Where it does not, the failure is either a refusal or an answer that looks like the others, and no amount of communication analysis will tell them apart.

That last point is the one the field’s own habit is for. A method is chosen on a cost model; the cost model is right; and the quantity the cost model cannot see is the one that decides whether the answer is an answer. The residual is not the only thing worth printing next to a factorisation — for these three the residuals are equal to rounding, and ‖QᵀQ − I‖ is what separates them by eleven orders of magnitude.

Four factorisations of one 512×12 matrix, κ = 7151A ranked bar chart of the departure from orthogonality, on a logarithmic scale. Classical Gram–Schmidt loses 4.6·10⁻¹⁰, modified 1.5·10⁻¹², Householder 2·10⁻¹⁴. The reduction tree, which touches the matrix once instead of 12 times, is of the same size as Householder's — and its error does not grow with the depth of the tree.classical Gram–Schmidt4.62·10⁻¹⁰modified Gram–Schmidt1.49·10⁻¹²Householder, one sweep2.03·10⁻¹⁴reduction tree, 16 leaves1.48·10⁻¹⁵departure from orthogonality, logarithmicthe tree, at four depths‖AᵀA − RᵀR‖/‖AᵀA‖, depth 13.4·10⁻¹⁵‖AᵀA − RᵀR‖/‖AᵀA‖, depth 24.3·10⁻¹⁵‖AᵀA − RᵀR‖/‖AᵀA‖, depth 31.7·10⁻¹⁵‖AᵀA − RᵀR‖/‖AᵀA‖, depth 41.5·10⁻¹⁵the same algebra, four timestwo of them are products of reflections
Fig. 5 The tree’s backward error against its depth, from the field’s own essay: 3.38, 4.26, 1.65 and 1.48·10⁻¹⁵ at depths one to four, on a 512×12 matrix at κ = 7,151, against a Householder sweep’s 9.95·10⁻¹⁵ and classical Gram–Schmidt’s 4.6·10⁻¹⁰. Depth is free, which is what makes the round count above worth spending arithmetic on.

What the model does not have

Bandwidth and latency together. Real cost models are α + βw per message — a fixed cost plus a per-word one — and the interesting algorithms are chosen by minimising a weighted sum rather than either count alone. Everything here reports the two counts separately and refuses to weight them, because the weight is the machine and the site’s rule is that no duration appears in a cost claim.

Topology. The reduction tree here is binary and the network is assumed to be able to carry any pair of processors talking. A real machine has a topology, and a reduction on a torus costs differently from one on a fat tree.

And overlap. Nothing here models communication happening while arithmetic happens, which is the first thing any real implementation does and which changes what “critical path” means.

The same arithmetic, twice, with M = 144 words of fast memoryThree counters against the matrix size on logarithmic axes. The operation count is one curve, because both orderings perform exactly the same operations — 338,120 of them at n = 80. The words moved between fast and slow memory are two curves a factor of 3.24 apart. The factorisations they produce are identical to the last bit.10²10³10⁴10⁵matrix size ncountoperations, bothwords, unblockedwords, blocked (b = 6)the answer does not move‖PA − LU‖/‖A‖, unblocked2.8·10⁻¹⁶‖PA − LU‖/‖A‖, blocked2.8·10⁻¹⁶difference between them0the dashed curve is both orderings' operation countthe solid pair is what they cost
Fig. 6 The counter this field already had. Words moved between two levels of memory is a bandwidth count; none of the three numbers here changes when the same work is split across more processors, which is what the round count above is for.
QᵀQ from classical Gram–Schmidt and from Householder on the 8×8 Hilbert matrixTwo eight-by-eight tables of QᵀQ. The upper one has ones on the diagonal and entries as large as one off it; the lower one is the identity to three decimal places everywhere.A = H8 · κ = 1.5·10¹⁰ · both factorisations reconstruct A to 6·10⁻¹⁷the diagonal is 1 in both — every column is a unit vector either way1.000000000001.000000000001.000000000001.000000000001.00000.002-0.002000001.0000.125-0.13300000.0020.1251.000-1.0000000-0.002-0.133-1.0001.000classical Gram–Schmidt1.000000000001.000000000001.000000000001.000000000001.000000000001.000000000001.000000000001.000Householderclassical ‖QᵀQ − I‖1.4Householder ‖QᵀQ − I‖1.4·10⁻¹⁵largest off-diagonal 1 against 3.1·10⁻¹⁶length is not angle
Fig. 7 The measurement that separates the three factorisations, from the field that introduced it. ‖QᵀQ − I‖ is a number rather than an adjective, and it is the number the communication analysis cannot see.
Separating two eigenvalues, against how close they areIterations against the gap between the two largest eigenvalues, on a logarithmic gap axis. The single-vector method needs 17, 18, 20, 22 steps as the gap closes through four decades. The block of two needs 11 at every gap — and spends 22 products with A doing it, which is no less arithmetic. What it saves is synchronisations.10⁻⁴10⁻³10⁻²10⁻¹0510152025gap between the two eigenvaluesiterationsone vectorblock iterationsblock productsiterations, not arithmeticsingle-vector steps at 0.117single-vector steps at 0.000122block iterations, every gap11the same products with Aand half the synchronisations
Fig. 8 The same currency in the eigenvalue field: a block method that spends the same arithmetic as a single-vector one and half the iterations. An iteration is a synchronisation, which is exactly what this essay’s rounds are counting.
Words moved against the block size, n = 96, M = 100A U-shaped curve on logarithmic axes. Too small a block refactors the panel too often; too large a block does not fit in the fast memory and the tiled update evicts what it is about to read. The minimum is at b = 8, which is √M − 2. The three-line count says √(M/3) = 5, which has the right scaling and the wrong constant.110¹10²10⁵block size bwords movedthe count: √(M/3) = 5measured best: b = 8words movedat the best block1.2·10⁵at b = 15.5·10⁵at b = 243.2·10⁵derived from M with no measurement, and scannedthe two agree
Fig. 9 What a machine parameter does to an algorithm’s shape when it is a memory size rather than a processor count: the optimum block is √M − 2 exactly, and the three-line model that predicts √(M/3) has the wrong constant and the wrong form.

What the model assumes, and where it would be wrong

A cost model is a claim about a machine, and the honest way to present one is with its assumptions where a reader can check them rather than in a footnote.

One reduction is log₂p rounds. That is a binary tree, and it assumes any pair of processors can talk at the same cost. A real machine has a topology; a reduction on a torus is a different count from one on a fat tree, and on a machine with hardware collectives it may be one round rather than log₂p. What survives topology is the ratio between the three methods, because all three pay the same per-reduction price and differ only in how many reductions they need.

The sweep needs one reduction per column. That is the standard distributed Householder QR, and it is the count that makes the ratio exactly n. A code that reformulates the sweep to reduce several columns at once — which is what a blocked panel factorisation does — moves that count down by the panel width, and the tree is then better by n/b rather than by n. That is a real and well-known refinement and it does not change the shape: the tree’s count contains no n at all.

And no message is charged for its own size. Real models are α + βw per message, and the interesting algorithms minimise a weighted sum of the two counts. Everything here reports the counts separately and refuses to weight them, because the weight is a property of a machine and this site’s rule for the whole cost field is that no duration appears in a cost claim.

Two things the model has no way to express, both of which a real implementation depends on: overlap, where communication happens while arithmetic does and the critical path is neither count alone; and memory hierarchy on each node, which is the quantity cost.js counts and which is orthogonal to everything here.

The three residuals, and why they are not the measurement

Every figure in this essay prints ‖AᵀA − RᵀR‖/‖AᵀA‖ for the method it draws, and the numbers are 1.2·10⁻¹⁵, 8.2·10⁻¹⁶ and 1.2·10⁻¹⁶ at κ = 10³ — the Cholesky route’s is the smallest of the three.

That is not a paradox and it is the reason this essay exists in the form it does. R is the triangular factor of this matrix, to rounding, by all three routes; what differs is what happens when a right-hand side is solved through it, which is the quantity ‖QᵀQ − I‖ of the implied Q measures.

The site’s rule is that no decomposition is drawn without its residual printed, and this is the case where obeying the rule and stopping there would mislead. The badge says the factorisation is fine. The factorisation is fine. What is not fine is the basis it implies, and the field that measures orthogonality as a number rather than an adjective is the one that can say so.

What a decision would use

Three statements, in the order a choice would need them.

Count rounds, not words. On these shapes the word counts rank the three methods in an order with nothing to do with what a machine charges for, and the round counts differ by a factor of n.

The tree is the answer for a tall matrix, at 22% more arithmetic, all of it local, with a backward error that does not grow with the depth of the tree — measured at depths one to four in this field already.

And Cholesky QR is usable exactly when κ²u ≪ 1, which is computable before the factorisation is attempted. Where it holds, one reduction is genuinely one reduction. Where it does not, the failure is either a refusal or an answer indistinguishable from the others by any residual, and no amount of communication analysis separates them.

What is left

The 2.5D and communication-avoiding factorisations of square matrices, where the same analysis applies to LU and to matrix multiplication and where the lower bounds are genuinely deep — a result of the form no algorithm can send fewer than this many words is a different kind of statement from anything measured here.

And CholeskyQR2, which is the standard repair: run Cholesky QR twice, on the grounds that the second pass sees a matrix whose condition number is the square root of what the first pass had to deal with. It is two reductions rather than one, and whether the ‖QᵀQ − I‖ curve above flattens under it is a measurement this site could make and has not.

What links here

Computed from the collection, not written here: the essays that point at this one.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A flat tag is an object no other essay names yet.

Communication lower boundCondition numberData movementHouseholder reflectionLatencyNormal equationsOrthogonalityReduction treeTall skinny qr