Where the flop count stopped predicting the time

Memory bought with messages

Holding four copies of the data instead of one is supposed to cut a matrix multiplication's communication by √4. Measured on a machine of 64 processors it costs 14% more traffic; at 576 it saves 44%, which is 72% of what the law promises. The memory is exactly four times, and that part is not asymptotic.

Worth reading first: A reduction that changes the order · The same arithmetic at a different price.

Every trade this site’s cost field has measured so far spends one countable thing to buy another.

Blocking spends nothing: the blocked and unblocked eliminations perform 72,568 operations each, return a bit-identical factorisation, and move 19,476 words against 41,332. The reduction tree spends arithmetic — 22% more flops — to buy synchronisations, a factor of n of them.

This one spends memory, and the exchange rate is supposed to be a square root.

What 4 layers save, against the size of the machineThe traffic of a flat layout divided by the traffic of a 4-layer one, at four processor counts, on a logarithmic horizontal axis. The upper line is the √4 the asymptotic analysis promises and the lower one is break-even. The measurement runs from 0.88 at 64 processors — a loss — to 1.44 at 576, and it is the same curve at every matrix size, because every word counted here is exactly proportional to n².10²11.251.51.7522.25processorstraffic saved, as a factorthe √4 the law promisesbreak-evenmeasureda limit is not a sizesaving at p = 640.88saving at p = 5761.4what the law promises2memory, as a factor4a loss at sixty-four processorsand 72% of the law at five hundred
Fig. 1 What four copies of the data buy in traffic, at four machine sizes. The upper line is the asymptotic law and the lower one is break-even.

The construction

A matrix multiplication C = AB on p processors. The two-dimensional layout puts them on a √p × √p grid: each holds one block of A, one of B and one of C, and the algorithm sweeps. At step k every processor in block-column k broadcasts its A block along its row and every processor in block-row k broadcasts its B block down its column, and each accumulates one block product.

The 2.5D layout uses the same p processors as c layers of a √(p/c) × √(p/c) grid. Each layer takes a distinct 1/c of the summation index, runs the same sweep over its own share, and the layers are added at the end. The grid is smaller by √c, so there are fewer steps and the blocks are larger, and the standard analysis says the words moved fall like 1/√c.

Three phases, then, and the counting has to include all three: replicating A and B to the other layers, the sweep inside each layer, and the reduction that adds the layers.

Counted rather than modelled

Every broadcast and every reduction here goes through the same Network the communication field already uses, and the algorithm actually multiplies the matrices — so the product is available to be checked against a direct one, and it is, at every layer count and every machine size, to 4·10⁻¹⁶.

That check is not a formality. A communication model that does not compute the answer can count whatever it likes, and the way these analyses are usually presented — a table of asymptotic volumes — has no way to be wrong about an algorithm nobody ran.

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. 2 The field’s own reason for counting two things rather than one: three factorisations of a matrix rank differently in messages and in words. The measurement below counts words; the rounds tell a different story and are printed beside them.

What four layers are worth

processors flat, words four layers saving
64 129,024 146,880 0.88×
144 202,752 184,064 1.10×
256 276,480 221,040 1.25×
576 423,936 294,848 1.44×

A 96×96 multiplication, whole-machine word counts.

At 64 processors replication costs 14% more traffic than not replicating. The crossing is between 64 and 144. At 576 the saving is 1.44, which is 72% of the √4 = 2 the law promises — and the trend is still rising, so the law is the limit of this column and not a value in it.

Why the law is optimistic, in one line each

The three phases scale differently, and only one of them is what the law counts.

The sweep moves about 2n²√(p/c) words: the grid has √(p/c) steps, each broadcasting to √(p/c) − 1 destinations, each block being n²c/p words. That falls like 1/√c — and by slightly more than the law says, because the number of steps falls like c while the block size grows like √c.

The replication moves 2n²(c − 1) words, and that does not depend on p at all. It is filling c − 1 extra copies of two matrices, and the machine’s size does not enter.

The reduction moves about n²c words, and neither does that.

So the saving is 2n²√p(1 − 1/√c) and the cost is about n²(3c − 2), and the first grows with the machine while the second does not. Below a crossing the fixed costs win. The crossing is at about a hundred processors on this problem, and it moves with n only through the ratio n²/n² — which is to say it does not move with n at all. The last section is about what happened when the figure tried to put a slider on that.

The rounds, which move the other way

The word count is one of the two currencies this field insists on, and the other one does not favour the layered layout either.

At 256 processors the flat sweep takes 16 rounds — one per step of a 16×16 grid — and the layered one takes 17: eight sweep steps, one replication round, and eight rounds of the final reduction over 256 processors. The layered algorithm has fewer sweep steps and more rounds in total, because the two collective phases it adds are themselves logarithmic in the machine.

That is a small number and it is the wrong direction, and it is worth printing because the whole argument for these layouts is usually made in one currency. A machine whose cost is dominated by latency rather than bandwidth reads this table and finds nothing to buy; a machine dominated by bandwidth reads the previous table and finds 1.44× at 576 processors for four times the memory.

Neither reading is the correct one, which is the position the message and the word already established for three factorisations and is being confirmed here for two layouts of one multiplication.

And the memory is not asymptotic

The other side of the trade is exact.

c layers hold c copies of A and B, so the machine holds four times the data — measured as blocks held rather than modelled, because it is a count of what the algorithm allocates. There is no regime in which that is 3.8 or 4.2; it is four.

So the trade at 576 processors is: four times the memory for 1.44 times less traffic. Whether that is worth making is a question about which resource is scarce, and the honest form of the answer is that the memory is spent immediately and in full while the traffic saving arrives slowly and never reaches its own headline.

Words moved against the block size, n = 48, 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.6·10⁴at b = 13.9·10⁴at b = 243.9·10⁴derived from M with no measurement, and scannedthe two agree
Fig. 3 The same shape one level down the memory hierarchy, from the blocking essays: a fast memory whose size decides a block size, with a measured optimum that the closed-form count gets the scaling of and not the constant. Every trade in this field has that structure.

What one layer is

The layered algorithm at c = 1 is the flat one — same grid, same sweep, no replication and no reduction — and that is asserted rather than assumed, because it is what makes the comparison a comparison. One routine, one parameter, and the two ends of the parameter are the two algorithms being weighed against each other.

That matters more than it sounds. The usual presentation gives 2D and 2.5D as separate algorithms with separate analyses, and a reader comparing two published word counts is comparing two people’s accounting conventions as much as two algorithms. Here the flat count and the layered count come out of the same instrumented routine on the same matrices with the same block sizes, so the ratio in the table is a ratio of two measurements rather than of two models.

The check that the two really are one routine is short: at c = 1 the grid is √p, the round count is exactly the number of sweep steps, and there is no replication round and no final reduction. All three are asserted.

The fifth instance of one sentence

The breadth phase’s organising finding was that a statement about a limit is not a statement about a computation, and it collected four instances in areas sharing no mathematics: Szegő’s limit reached to 52% by an 8×8 section, circulant preconditioning taking 109 steps against an unpreconditioned 66, blocking buying a constant rather than an exponent, and the Picard crossing arriving four to eleven indices late.

This is the fifth, and it is the cleanest of them, because the gap between the limit and the measurement is a single number that can be watched moving: 0.88, 1.10, 1.25, 1.44, against a law that says 2 at every row.

What makes the instance worth adding rather than merely counting is where it comes from. The √c is not a bound that happens to be loose — it is exactly right about the phase it describes and silent about two phases that are lower-order in an asymptotic sense and are, at 64 processors, larger than the thing they are lower-order than.

κ of the ρ = 0.8 Toeplitz family, against the limit it never reachesThe condition number of the n×n section of the Kac–Murdock–Szegő matrix ρ^|i−j| at ρ = 0.8, plotted against the size on logarithmic axes, with Szegő's asymptotic value ((1+ρ)/(1−ρ))² = 81 drawn as a horizontal line. The measured curve climbs towards it from below and reaches 98.9% of it at n = 128.10¹10²10²size ncondition numberlimit 81measureda limit, as a fraction of itselfreached at n = 1280.99still to go0.011κ at n = 8, as a fraction0.52every point is below the line and none of them is on itthe limit is not a value
Fig. 4 The first instance, from the structure field: a limit of 81.000 that an 8×8 section reaches 52% of and a 128×128 reaches 98.9% of, with the approach getting slower as the limit gets larger. The figure in this essay is the same shape with a machine size on the axis.

What the simulation actually does

Worth being concrete about, because “counted rather than modelled” is a claim about code.

The routine holds A and B as ordinary matrices and cuts them into g×g blocks, with g = √(p/c). It then walks the algorithm: for each summation index k assigned to a layer, it charges one round of 2g(g − 1) messages of (n/g)² words to the network, and multiplies the corresponding block of A by the corresponding block of B into the accumulating C — the real arithmetic, in the real order, with the blocks the layout would actually hold.

At the end it charges the replication and the reduction, and returns both the product and the network’s summary.

So the traffic figure and the answer come from the same walk. That is the property that makes the table trustworthy in a way a spreadsheet of asymptotic volumes is not: if the loop bounds were wrong, the product would be wrong, and the product is checked against a direct multiplication at every layer count and every machine size.

It is also the property that bounds what the measurement can say. The simulation charges every broadcast at full price to every destination; it assumes the blocks divide evenly; and it counts a collective as the sum of its point-to-point messages. Those are modelling choices inside a measurement, and each of them is stated where the code makes it.

What is being left out

Three things, and stating them is what keeps the measurement from claiming more than it is.

The word count is whole-machine rather than per processor. The classic statement is per processor, and dividing by p changes none of the ratios above — the crossing, the trend and the shortfall against the law are the same numbers either way.

Latency is counted separately and is not in the table. The layered layout takes one more round than the flat one at 256 processors, and a reader whose machine is latency-bound rather than bandwidth-bound should read the rounds column of the communication field’s own figures instead.

And the arithmetic is unchanged. Both layouts perform exactly n³ multiply-adds distributed differently, which is worth stating because it is what separates this trade from the reduction tree’s: that one buys synchronisations with 22% more flops, and this one buys traffic with memory and nothing else.

The other half of the deferral

This essay and doing it twice are the two halves of one line the synthesis phase wrote down — CholeskyQR2 and the 2.5D communication-avoiding factorisations — and they turn out to be about different things.

The first is about accuracy: a method with the fewest possible communication rounds pays for them with κ², and one extra round buys the square back. Nothing about the machine enters; the trade is arithmetic for arithmetic.

The second is about resources: a method spends memory to move fewer words, and whether that is worth doing depends on a crossing that is a property of the machine. Nothing about accuracy enters; the product is identical to the last bit at every layer count.

Grouping them under one heading is the literature’s doing rather than the subject’s, and the grouping is defensible — both are communication-avoiding in the sense of trading something for traffic. What the measurements show is that the two trades have nothing else in common: one has a threshold in κ and no dependence on p, the other has a crossing in p and no dependence on κ.

Where the crossing would move

The measurement is one problem shape on one cost model, and three things would move the crossing if they were different.

A cheaper broadcast. The count here charges every broadcast to g − 1 destinations at full price, which is what a naive implementation costs and what a network with hardware multicast does not. Halve the replication’s price and the crossing moves down by roughly the same factor.

A larger c. Four layers is what the grids in this figure divide into; nine or sixteen would move the sweep’s saving up like √c and the fixed costs up like c, so the crossing moves up with c — a bigger replication factor needs a bigger machine to pay for itself, which is the opposite of the way the law reads.

And a rectangular problem. Everything here is n×n by n×n. A tall-skinny product has a different balance between the sweep and the replication, and the communication field’s own tall-skinny factorisations are the case where the reduction tree wins outright — so the shape of the operands is not a detail of this trade, it is one of its parameters.

None of those changes the sentence the essay is about. They move the crossing; they do not make the fixed costs scale with the machine, and that is the whole reason the crossing exists.

The same arithmetic, twice, with M = 196 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 2.67 apart. The factorisations they produce are identical to the last bit.10²10³10⁴10⁵matrix size ncountoperations, bothwords, unblockedwords, blocked (b = 8)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. 5 Three counters for one factorisation, from the field this essay sits in. The layered layout moves fewer words and takes one more round, which is the same disagreement in a different algorithm.
κ of the 0.8 kernel on m×m grids, against its two-dimensional limitCondition number against the grid side on a logarithmic vertical axis, with the asymptotic value ((1+ρ)/(1−ρ))⁴ = 6561 drawn as a horizontal line. The measured values are 581, 1196, 1794, 2337, reaching 35.6% of the limit on the largest grid — where the one-dimensional section of the same length reaches far more.4681010³10⁴grid side mκlimit 6561measured κthe symbol multipliesthe limit, from the symbol6561κ at 10×102337share of the limit reached0.36the limit is the square of the one-dimensional oneand it is further away
Fig. 6 A second limit that a real size does not reach, from the structure field. The pattern is the same: an asymptotic statement, correctly derived, contradicted at every size anybody runs.

What a reader should take from the table

Three sentences, in the order the numbers support them.

The direction of the trade is right. At every machine size above the crossing, four layers move fewer words than one, and the advantage grows with the machine. Nothing here says the idea is wrong.

The size of it is not what the law says, and the shortfall is not a small correction: 1.44 against 2 at 576 processors, and negative at 64. A capacity plan built on √c is over-optimistic by 39% at the largest size drawn here and by more below it.

And the memory is spent in full, immediately. Four times the data is four times the data whatever the machine’s size, so a trade that is marginal in traffic is unambiguous in memory — which makes the decision easier than the table suggests, in the direction of not making it unless the machine is large.

The figure has no slider, and that is the finding

Every other figure in this field carries a crank. This one was drafted with one — the size of the matrix, from 48 to 192 — and a note saying that a larger matrix moves every point on the curve up together without moving the crossing.

The build refused it. The figure machinery renders every stop of a declared range and compares the frames, and all four were the same picture; the message was that either the generator ignores the parameter or the range is too narrow to change anything. Neither was true, and the truth was worse for the note: on a ratio axis a larger matrix moves nothing at all, not every point up.

The reason is the one already given above. The sweep moves 2n²(g − 1) words, the replication 2n²(c −

  1. and the reduction about n²c, where the grid g depends on p and c and not on n. Every term carries the same n², so the ratio of two layouts is a rational number with n² cancelled out of it — and cancelled exactly, because the model counts whole blocks and a block is (n/g)² words. The four saving factors at n = 48, 96, 144 and 192 are not close to each other. They are the same double: 0.878431, 1.101530, 1.250814, 1.437812, at 64, 144, 256 and 576 processors, to every digit a comparison can see.

So the assertion that replaced the slider states it as an equality rather than a tolerance, and it is paired with a second one that the word counts themselves are not equal — they grow like n² to twelve digits — so what is being reported is cancellation and not a model that quietly ignores its matrix size. The claim fed to the refusal is the drag note’s own: that a larger matrix makes replication pay better at the same processor count.

A reader who has been told that 2.5D algorithms are for large problems has been told the wrong axis. They are for large machines, and the strongest form of that statement is not a curve that shifts under a slider but a number that refuses to move.

Named objects

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

All reduceAsymptotic analysisBlock transferBroadcastCommunication avoidingLatencyMatrix multiplicationMemory hierarchyReplicationSynchronisation