Amdahl's Law
When you speed up part of a job, the part you didn't touch still takes just as long, so it caps the overall gain. Speed up a fraction of the time by a factor and the whole job gets times faster, never more than , however big gets.
What the symbols mean
- Overall speedup
Old total time divided by new total time.
- Fraction improved
The fraction of the ORIGINAL running time spent in the part you speed up.
- Local speedup
How many times faster that part becomes.
Explanation
Amdahl's law is simply a formula for how much faster a whole program gets when you speed up only one part of it. It says our overall speedup is , and the bottom of that fraction is the new running time: (the part we didn't speed up, which takes exactly as long as before) plus (the part we did, shrunk by ). One over the new time is the speedup. It's named after Gene Amdahl, the engineer who pointed it out in 1967, and it's really just bookkeeping about time; bear with the fractions.
Deriving it. Measure the old running time as 1 (one whole run). A fraction of it is spent in the part we're about to improve, and is spent everywhere else. Now make that part times faster:
- the untouched part still takes ;
- the improved part took and now takes .
The new time is , so the speedup, old time over new time, is
The ceiling. Say of a program's time is in a matrix routine and we make it 4 times faster: . Make it 100 times faster: . Make it infinitely fast and , leaving
Think about why. Even if the matrix routine took no time at all, the other of the run would still be there, and a job that takes of its old time is exactly 5 times faster. The part you didn't speed up becomes the whole story. There's a graph further down that shows the speedup curve flattening against this ceiling.
Diminishing returns. Each doubling of buys less than the one before. With : gives , gives , gives , gives , crawling toward 10. Past a point, the smart move is to stop polishing the fast part and go after the .
Working backwards. Often you know the speedup you need and must find the (or the ) that gets you there. Flip both sides of the formula:
If the bottom is zero or negative, that is, if , no can do it.
A common mistake. It's tempting to think "half the program, made 10 times faster, gives a 5 times speedup." It doesn't: . The other slip is using the wrong . It has to be the fraction of the original running time, not the fraction of the code's lines, and not a fraction measured after the improvement (once a part is faster it's a smaller share of the new time).
Amdahl's law is the same weighted bookkeeping as average CPI: speeding up loads 5 times when they're of the cycles is , . In the next lesson, becomes the number of processor cores.
See it
Worked examples
of a program's running time is in one routine. You make that routine times faster. What is the overall speedup, and what's the most you could ever get by speeding up that routine?
- 1
Identify the pieces: (the fraction of the original time we're improving) and (how much faster it gets).
For the same program (), how much faster must the routine become for the whole program to run times faster?
- 1
Write Amdahl's law with the target filled in: . The unknown is .
Practice
Type your answer and check it. Solve them all to complete the lesson.
of a program's time is spent in code that you make times faster. What is the overall speedup?
of a program's time can be sped up. What is the largest overall speedup possible?
A video encoder spends of its time on motion search. A new hardware accelerator does motion search times faster. By what factor does the whole encoder speed up? Give 3 decimal places.
of a program's time is in one loop. How many times faster must the loop become for the program to run times faster?
A coprocessor runs part of a program times faster. What percent of the original running time must that part be for the whole program to run twice as fast?
A manager wants a times speedup by optimizing code that takes of the running time. What should you tell them?
A workload's mix is ALU (CPI ), loads (CPI ), stores (CPI ) and branches (CPI ), for CPI . A new cache makes loads times faster (CPI ). Use Amdahl's law to find the speedup. Give 3 decimal places.
The hardest one here. Get it, and you've got this lesson.
A physics simulation spends of its time on collision checks, on force calculations and on everything else. One team can make collision checks times faster; another can make force calculations times faster. If both changes go in, what is the overall speedup? (Each part shrinks by its own factor.) Give 3 decimal places.
Where it's used
Amdahl's law is the first sanity check before any optimization project. Profilers report where the time goes, and tells you the best case before anyone writes a line of code. It's why GPU offload, special accelerators for video or AI and faster storage are sold with "up to" speedups: the parts of the job they don't touch, like reading input or moving data back and forth, set a ceiling no accelerator can lift.