---
title: Amdahl's and Gustafson's laws
heading: The limits of speeding up part of a job, scaled workloads, and sizing multicore chips
eyebrow: S4 · Lesson 2 · Amdahl's and Gustafson's laws
xp: 50
---

::: hook
Speed up part of a job and the rest becomes the bottleneck. That plain observation, made precise by Gene Amdahl in 1967, is the most-used equation in computer architecture. It says a program that's 90% parallel can never run more than 10 times faster, however many processors it gets. Gustafson's law answers back: people don't use bigger machines to run the same job faster, they run bigger jobs in the same time, and then the serial part shrinks in proportion. Between them they frame every decision about multicore chips, accelerators and where to spend design effort.
:::

::: play
- Speedup against the number of processors N, on a log scale, for a program whose parallel fraction is p.
- Solid: Amdahl's fixed-size speedup, $\frac{1}{(1 - p) + p/N}$, which flattens at $\frac{1}{1 - p}$. Dashed: Gustafson's scaled speedup, $N - (1 - p)(N - 1)$, which keeps growing because the problem grows with the machine.
- Slide p from 0.9 to 0.99: the Amdahl limit goes from 10 to 100. The last few percent of serial code decide everything.
:::
:::

```sim plot
view: graph
x: N = 1..4096 log
y: S = 1..4096 log
slider: p = 0.5..0.999 = 0.9
plot: 1/((1 - p) + p/N) | samples: 300 | label: Amdahl (fixed size)
plot: N - (1 - p)*(N - 1) | samples: 300 | dashed | color: ch2 | label: Gustafson (scaled size)
marker: y = 1/(1 - p) | label: Amdahl limit
readout: Amdahl speedup on 64 processors = 1/((1 - p) + p/64)
readout: limit = 1/(1 - p)
```

::: predict
## A program spends 90% of its time in code that parallelizes perfectly. How fast can it get on 1000 processors?

- [ ] 900 times
- [ ] 100 times
- [x] Just under 10 times
- [ ] 1000 times

::: reveal
9.9 times. The 10% serial part still takes its full time, so even if the parallel 90% took no time at all the speedup would be 1/0.1 = 10. On 16 processors it's already 6.4. To use 1000 processors well, the serial fraction has to be a small fraction of a percent, or the job has to grow with the machine.
:::
:::

::: nameit
## Amdahl's law

If an enhancement speeds up a fraction F of the execution time by a factor S, the overall speedup is

$$\text{speedup} = \frac{1}{(1 - F) + F/S} \le \frac{1}{1 - F}$$

Several enhancements on disjoint fractions: $\frac{1}{(1 - \sum F_i) + \sum F_i/S_i}$. The lesson for design: make the common case fast, and know what fraction of time it really is.

## Gustafson's law

If the parallel part grows with N while the serial time stays fixed, and p is the parallel fraction measured on the N-processor run, the scaled speedup is

$$S = N - (1 - p)(N - 1)$$

Weather models, simulations and training runs behave this way: a bigger machine buys a finer grid or a bigger model.

## Sizing multicore chips (Hill and Marty)

A chip has n units of area (base core equivalents). A core built from r units runs $\sqrt r$ times faster than a 1-unit core (a common rule of thumb, Pollack's rule). A symmetric chip of $n/r$ such cores runs the serial part on one core and the parallel part on all of them:

$$\text{speedup} = \frac{1}{\frac{1 - f}{\sqrt r} + \frac{fr}{\sqrt r\,n}}$$

Small cores lose on the serial part, big cores on the parallel part; the best r sits in between.
:::

::: example
## A program is 90% parallel. Find its speedup on 16 and 1000 processors, and the parallel fraction needed for a speedup of 10 on 16.

::: solution
1. **16 processors.**
   $$\begin{aligned} S &= \frac{1}{0.1 + 0.9/16} \\ &= 6.4 \end{aligned}$$
2. **1000 processors.**
   $$\begin{aligned} S &= \frac{1}{0.1 + 0.0009} \\ &= 9.9 \end{aligned}$$
3. **Fraction for a speedup of 10 on 16.** Solve $\frac{1}{(1 - F) + F/16} = 10$ for F:
   $$\begin{aligned} F &= \frac{1 - 1/10}{1 - 1/16} \\ &= 0.96 \end{aligned}$$
4. **Gustafson's view.** The same 16-processor run with p = 0.9 gives a scaled speedup of
   $$16 - 0.1 \times 15 = 14.5$$

**Answer:** a speedup of 6.4 on 16 processors and 9.9 on 1000; a speedup of 10 on 16 needs F = 0.96 (Gustafson's scaled speedup for the 16-processor run is 14.5).
:::
:::

::: example
## A chip has 256 base-core units and runs code that's 97.5% parallel. Compare symmetric designs with cores of 1, 4, 16 and 64 units.

::: solution
1. **r = 1 (256 small cores).**
   $$\begin{aligned} S &= \frac{1}{0.025 + 0.975/256} \\ &= 34.7 \end{aligned}$$
2. **Bigger cores.** With 64 cores each 2× faster (r = 4), 16 cores 4× faster (r = 16) and 4 cores 8× faster (r = 64):
   $$\begin{aligned} r = 4&:\ 49.7 \\ r = 16&:\ 46.5 \\ r = 64&:\ 29.8 \end{aligned}$$
3. **Best r.** Scanning every r, the best is r = 7, at 51.2.
4. **What tiny cores cost.** A chip of only tiny cores loses almost a third of the possible speedup to the 2.5% serial code.

**Answer:** speedups of 34.7, 49.7, 46.5 and 29.8 for r = 1, 4, 16 and 64; the best symmetric design is r = 7, at 51.2.
:::
:::

::: example
## Two enhancements speed up disjoint parts of a program: 30% of the time runs 10 times faster and 20% runs 3 times faster. What is the overall speedup?

::: solution
1. **Untouched fraction.** The two enhancements cover 30% + 20% = 50% of the time, leaving 0.5 untouched.
2. **Overall speedup.**
   $$\begin{aligned} S &= \frac{1}{0.5 + 0.3/10 + 0.2/3} \\ &= \frac{1}{0.5 + 0.03 + 0.067} \\ &= 1.68 \end{aligned}$$
3. **The cap.** The untouched half caps the speedup at 2 whatever the enhancements do, so the bigger win would come from touching more of the time.

**Answer:** the overall speedup is 1.68.
:::
:::

::: check
given: F = 0.4 | 0.7 | 0.95; S = 2 | 8 | 50
answer: 1/((1 - F) + F/S)
tolerance: 0.5%

## An enhancement speeds up {F} of a program's time by {S}×. What's the overall speedup?

::: right
Right. $\frac{1}{(1 - F) + F/S}$ = {answer}.
:::

::: misses
- [F*S + 1 - F] Combine the parts' times, then invert.
- [S] Only part of the program is enhanced.
- [any] Not yet. New time over old time, inverted.
:::
:::

::: check
given: F = 0.8 | 0.95 | 0.99 | 0.999
answer: 1/(1 - F)
tolerance: 0.5%

## A fraction {F} of a program can be sped up without limit. What's the most the whole program can speed up?

::: right
Right. $\frac{1}{1 - F}$ = {answer}.
:::

::: misses
- [1/F] The part that can't be sped up sets the limit.
- [any] Not yet. Only the remaining fraction's time is left.
:::
:::

::: check
given: T = 4 | 8 | 12; N = 16 | 64
answer: (1 - 1/T)/(1 - 1/N)
tolerance: 0.5%

## What parallel fraction does a program need to reach a speedup of {T} on {N} processors?

::: right
Right. $F = \frac{1 - 1/S}{1 - 1/N}$ = {answer}.
:::

::: misses
- [T/N] Solve Amdahl's law for F.
- [any] Not yet. Set Amdahl's speedup equal to the target and solve.
:::
:::

::: check
given: N = 16 | 128 | 1024; p = 0.8 | 0.95 | 0.99
answer: N - (1 - p)*(N - 1)
tolerance: 0.5%

## On {N} processors, a scaled run is {p} parallel. What's its Gustafson speedup?

::: right
Right. $N - (1 - p)(N - 1)$ = {answer}.
:::

::: misses
- [1/((1 - p) + p/N)] That's Amdahl's fixed-size speedup.
- [any] Not yet. The serial part costs (1 − p) of each extra processor.
:::
:::

::: check
given: f = 0.9 | 0.99; n = 64 | 256; r = 4 | 16
answer: 1/((1 - f)/sqrt(r) + f*r/(sqrt(r)*n))
tolerance: 0.5%

## A symmetric chip of {n} base units uses cores of {r} units each, with performance $\sqrt r$. What's its speedup on code that's {f} parallel?

::: right
Right. {answer}.
:::

::: misses
- [1/((1 - f) + f/n)] Account for the core size: the serial part runs $\sqrt r$ faster, and there are only n/r cores.
- [any] Not yet. Serial on one core of speed $\sqrt r$; parallel on n/r of them.
:::
:::

::: check
given: F = 0.3 | 0.4; S = 4 | 10; G = 0.2 | 0.25; T = 2 | 3
answer: 1/((1 - F - G) + F/S + G/T)
tolerance: 0.5%

## One enhancement speeds up {F} of the time by {S}×, another speeds up a separate {G} by {T}×. What's the overall speedup?

::: right
Right. $\frac{1}{(1 - F - G) + F/S + G/T}$ = {answer}.
:::

::: misses
- [1/((1 - F) + F/S)*1/((1 - G) + G/T)] The two speedups apply to fractions of the same original time: they don't multiply.
- [any] Not yet. Add up the new time of each part.
:::
:::

::: check
kind: parts
given: F = 0.5 | 0.8 | 0.95; S = 4 | 16 | 100; N = 16 | 64; p = 0.9 | 0.99

## An enhancement speeds up a fraction {F} of a program's time by {S}. Separately, a scaled workload runs on {N} processors with parallel fraction {p}.

::: part
answer: 1/((1 - F) + F/S)
tolerance: 0.5%

### What is the enhancement's overall speedup?

::: misses
- [S*F] Amdahl's law: the untouched part limits it.
- [any] $1/((1 - F) + F/S)$.
:::
:::

::: part
answer: 1/(1 - F)
tolerance: 0.5%

### What is its limit as S grows?

::: misses
- [any] $1/(1 - F)$.
:::
:::

::: part
answer: N - (1 - p)*(N - 1)
tolerance: 0.5%

### What scaled speedup does Gustafson's law give?

::: misses
- [1/((1 - p) + p/N)] That's Amdahl's fixed-size speedup.
- [any] $N - (1 - p)(N - 1)$.
:::
:::
:::

::: check
kind: derivation
vars: F = 0.1..0.99, S = 1.5..1000, T = 1.01..5

## A fraction F of a program's time can be sped up by S.

::: step
answer: 1/((1 - F) + F/S)

### What overall speedup results?
:::

::: step
answer: F/(1/T - (1 - F))

### What S would an overall speedup of T need (when T is below the limit)?
:::

::: step
answer: 1/(1 - F)

### What is the most any S can give?
:::

::: right
Right. Pushing toward the limit takes ever larger S: the serial fraction decides.
:::
:::

::: explain
## Why does Amdahl's law argue for building at least one big, fast core, even on a chip meant for parallel work?

::: model
Every parallel program has some serial part, and on a chip with many cores that part runs on one core while the rest wait. As the number of cores grows, the parallel part's time shrinks toward zero and the serial part's time, set by how fast a single core is, comes to dominate. A chip of only small, slow cores therefore caps its own speedup at a low level. Spending some of the area on a larger core speeds up exactly the part that limits everything else, at the cost of a few small cores whose loss barely matters once the parallel part is already fast. The best chips balance the two, or mix one big core with many small ones.
:::
:::

::: practice

::: check
given: F = 0.6 | 0.9; S = 3 | 20
answer: 1/((1 - F) + F/S)
tolerance: 0.5%

## Speedup when {F} is sped up {S}×?

::: misses
- [any] $1/((1 - F) + F/S)$.
:::
:::

::: check
given: N = 32 | 512; p = 0.9 | 0.98
answer: N - (1 - p)*(N - 1)
tolerance: 0.5%

## Gustafson speedup: {N} processors, {p} parallel?

::: misses
- [any] $N - (1 - p)(N - 1)$.
:::
:::

::: check
given: T = 5 | 20; N = 32 | 128
answer: (1 - 1/T)/(1 - 1/N)
tolerance: 0.5%

## Parallel fraction for a speedup of {T} on {N}?

::: misses
- [any] $(1 - 1/S)/(1 - 1/N)$.
:::
:::
:::
