6.1.3Parallelism & Multicore

Amdahl's Law and Gustafson's Law

2,880 words13 min readdifficulty · medium6 backlinks

Core Concepts

Why These Laws Matter

Performance scaling is the central challenge of modern computing. We can't make single cores much faster (heat, power limits), so we add more cores. But does 8 cores give you 8× performance? These laws answer when and why not.

The Setup:

  • You have some computation taking time TT
  • A fraction ff of it is inherently serial (cannot be parallelized)
  • The rest (1f)(1-f) is perfectly parallelizable
  • You have nn processors

Amdahl's Law: Fixed Workload Perspective

Derivation from First Principles:

Let's start with the total execution time T1T_1 on one processor.

Step 1: Break down the work

  • Serial portion takes: Tserial=fT1T_{\text{serial}} = f \cdot T_1
  • Parallel portion takes: Tparallel=(1f)T1T_{\text{parallel}} = (1-f) \cdot T_1

Why this step? We're partitioning the total work into two categories based on whether it can be parallelized. The serial fraction ff is a proportion, so fT1f \cdot T_1 gives us the actual time.

Step 2: Time on nn processors

With nn processors:

  • Serial part still takes fT1f \cdot T_1 (cannot be split!)
  • Parallel part now takes (1f)T1n\frac{(1-f) \cdot T_1}{n} (perfect division)

Why this step? The serial work is fundamentally sequential—throwing more processors at it doesn't help. The parallel work divides evenly (ideal assumption).

Tn=fT1+(1f)T1nT_n = f \cdot T_1 + \frac{(1-f) \cdot T_1}{n}

Step 3: Define speedup

Speedup is the ratio of single-processor time to multi-processor time:

S(n)=T1Tn=T1fT1+(1f)T1nS(n) = \frac{T_1}{T_n} = \frac{T_1}{f \cdot T_1 + \frac{(1-f) \cdot T_1}{n}}

Why this step? Speedup measures "how much faster." If S(n)=4S(n) = 4, you're 4× faster.

Step 4: Simplify

Factor out T1T_1:

S(n)=1f+1fnS(n) = \frac{1}{f + \frac{1-f}{n}}

Why this step? The original time cancels out—speedup depends only on the fraction ff, not absolute time.

What this means: If even 10% of your code is serial (f=0.1f = 0.1), the best speedup you can ever achieve is 1/0.1=10×1/0.1 = 10×, even with a million cores!

Figure — Amdahl's Law and Gustafson's Law

Gustafson's Law: Scaled Workload Perspective

Derivation from First Principles:

The conceptual flip: instead of asking "how fast can I run the same task," ask "how much more work can I do in the same time?"

Step 1: Time on nn processors (our reference)

With nn processors, we complete some workload in time TnT_n:

  • Serial part: Tserial=fTnT_{\text{serial}} = f \cdot T_n
  • Parallel part: Tparallel=(1f)TnT_{\text{parallel}} = (1-f) \cdot T_n

Why this step? We're measuring in terms of the parallel runtime, not the hypothetical single-core time.

Step 2: Equivalent work on 1 processor

If we ran this same amount of work on 1 processor:

  • Serial part: still fTnf \cdot T_n (unchanged)
  • Parallel part: n(1f)Tnn \cdot (1-f) \cdot T_n (we did nn times as much parallel work!)

Why this step? The parallel work was distributed across nn cores. To do it serially would take nn times longer.

T1=fTn+n(1f)Tn=Tn[f+n(1f)]T_1 = f \cdot T_n + n(1-f) \cdot T_n = T_n[f + n(1-f)]

Step 3: Calculate speedup

S(n)=T1Tn=Tn[f+n(1f)]Tn=f+n(1f)S(n) = \frac{T_1}{T_n} = \frac{T_n[f + n(1-f)]}{T_n} = f + n(1-f)

Rearrange:

S(n)=f+nnf=nf(n1)S(n) = f + n - nf = n - f(n-1)

Key Differences: When to Use Which Law

Aspect Amdahl's Law Gustafson's Law
Workload Fixed-size problem Scaled problem
Question "How fast can I finish?" "How much can I do?"
Assumption Problem size constant Problem grows with resources
Typical result Pessimistic (limited speedup) Optimistic (near-linear)
Use case Batch jobs, legacy code Scientific computing, ML

Connections to Other Topics

  • Parallel Architectures: These laws inform why multicore CPUs exist and their limits
  • GPU Computing: GPUs exploit Gustafson—scale problem size to thousands of cores
  • Load Balancing: Minimizing ff by distributing serial work cleverly
  • Cache Coherence: Coherence protocols add overhead that increases effective ff
  • Thread Synchronization: Locks and barriers are the primary sources of serial bottleneck
  • Scalability Analysis: Strong scaling (Amdahl) vs weak scaling (Gustafson)
  • Performance Metrics: Speedup, efficiency, and how to measure them
Recall Explain to a 12-Year-Old

Imagine you and your friends are building a huge LEGO castle. Some parts you can all work on at the same time—one person does the towers, another the walls, another the gate. That's the parallel work. But some parts only one person can do—like reading the instructions out loud or placing the final flag on top. That's the serial work.

Amdahl's Law says: if you're building the exact same castle, adding more friends helps, but only so much. If reading instructions takes 10 minutes and can't be split, then even with 100 friends, you still need those 10 minutes. You can't get infinitely fast!

Gustafson's Law says: if you get more friends, you don't build the same castle faster—you build a BIGGER castle in the same time! With 10 friends, you build a castle 10× more awesome. The instruction-reading still takes 10 minutes, but now you're reading instructions for a mega-castle, so it's worth it.

The lesson: parallelism works best when you grow the problem, not just rush the same small task.

Practice Problems (Active Recall)

#flashcards/hardware

What is Amdahl's Law used for?
Predicting maximum speedup for a fixed-size problem when parallelized across nn processors, accounting for the serial fraction ff.
What is the Amdahl's Law speedup formula?
S(n)=1f+(1f)nS(n) = \frac{1}{f + \frac{(1-f)}{n}} where ff is the serial fraction and nn is the number of processors.
What is the maximum speedup in Amdahl's Law as nn \to \infty?
Smax=1fS_{\max} = \frac{1}{f} — the serial fraction becomes absolute bottleneck.
If 5% of a program is serial, what is the maximum possible speedup?
10.05=20×\frac{1}{0.05} = 20× speedup, no matter how many processors you add.
What is Gustafson's Law used for?
Predicting speedup when the problem size scales with the number of processors (weak scaling), rather than keeping the problem fixed.
What is Gustafson's Law speedup formula?
S(n)=nf(n1)S(n) = n - f(n-1) or equivalently n+(1n)fn + (1-n)f, where ff is the serial fraction.
How does Gustafson's Law differ from Amdahl's Law?
Amdahl assumes fixed workload (strong scaling); Gustafson assumes scaled workload (weak scaling). Gustafson is more optimistic for large nn.
A program has f=0.02f=0.02 serial fraction. What is speedup on 50 cores (Amdahl)?
S(50)=10.02+0.98/50=10.02+0.0196=10.039625.3×S(50) = \frac{1}{0.02 + 0.98/50} = \frac{1}{0.02 + 0.0196} = \frac{1}{0.0396} \approx 25.3×
Same program (f=0.02f=0.02), speedup with 50 cores (Gustafson)?
S(50)=500.02(49)=500.98=49.02×S(50) = 50 - 0.02(49) = 50 - 0.98 = 49.02× — near-linear because workload scaled.
Why is the serial fraction ff measured in execution time, not lines of code?
Because a single line (like a lock) can dominate runtime if it causes threads to wait. Time spent, not code volume, determines the bottleneck.
What real-world factors increase the effective serial fraction?
Communication overhead, synchronization (locks, barriers), cache coherence traffic, load imbalance, and non-uniform memory access (NUMA) effects.
Give an example where Amdahl's Law applies.
Compiling the same codebase on multiple cores—problem size is fixed, you want it done faster.
Give an example where Gustafson's Law applies.
Climate simulation on a supercomputer—you increase grid resolution and timesteps to use all cores, keeping runtime constant.
If you have 16 cores and achieve 10× speedup, what is the implied serial fraction (Amdahl)?
Solve 10=1f+1f1610 = \frac{1}{f + \frac{1-f}{16}}: f+1f16=0.1f + \frac{1-f}{16} = 0.1, so 16f+1f=1.616f + 1 - f = 1.6, giving 15f=0.615f = 0.6, thus f=0.04f = 0.04 or 4%.
What does "strong scaling" mean?
Keeping problem size fixed and adding more processors to reduce time—governed by Amdahl's Law.
What does "weak scaling" mean?
Increasing problem size proportionally with the number of processors to keep time constant—governed by Gustafson's Law.
Why does Amdahl's Law seem pessimistic?
Because it reveals that even tiny serial fractions (e.g., 1%) can cap speedup at 100×, making infinite parallelism impractical.
What is the efficiency E(n)E(n) in parallel computing?
E(n)=S(n)nE(n) = \frac{S(n)}{n} — the fraction of ideal speedup achieved. E(n)=1E(n) = 1 means perfect linear scaling.
If S(8)=6S(8) = 6, what is the efficiency?
E(8)=6/8=0.75E(8) = 6/8 = 0.75 or 75% — you're getting 75% of the ideal 8× speedup.
How can you reduce the serial fraction in practice?
Minimize locks (use lock-free data structures), pipeline serial stages, reduce synchronization points, optimize I/O, and eliminate sequential algorithms.

Concept Map

split into

split into

stays fixed

divides by n

ratio T1 over Tn

formula

n to infinity

assumes

assumes

enables

contrasts with

motivates

Total time T1

Serial fraction f

Parallel fraction 1-f

Time on n processors

Speedup S of n

Amdahl's Law

Max speedup = 1 over f

Fixed workload

Gustafson's Law

Workload grows with n

Near-linear scaling

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, yahan sabse important baat samajhne wali ye hai ki jab aap ek kaam ko multiple processors ya cores mein baant te ho, toh unlimited speedup nahi milta. Amdahl's Law bolta hai ki agar aapke program ka kuch hissa serial hai — matlab jo parallel nahi ho sakta, jaise file padhna ya lock lena — toh wahi part aapka bottleneck ban jaata hai. Formula simple hai: S(n) = 1/(f + (1-f)/n), jahan f serial fraction hai. Aur sabse chaunkane wali baat ye hai ki agar sirf 10% code serial hai, toh chahe aap million cores laga do, maximum speedup sirf 10x hi milega, kyun ki S_max = 1/f. Yaani serial part hamesha aapko rok deta hai.

Ab why-it-matters wali baat: aaj kal single core ko zyada fast banana mushkil hai — heat aur power ki dikkat aati hai — isliye industry more cores add karti hai. Lekin more cores ka matlab automatically zyada performance nahi hota. Jaise humara image processing example mein, 95% kaam parallel hone ke baad bhi 10 cores se sirf 6.9x speedup mila, 10x nahi. Isse ek bahut zaroori lesson milta hai: kabhi kabhi serial part ko optimize karna (jaise faster parsing ya better locking) zyada faydemand hota hai bajaye aur cores daalne ke.

Isi wajah se Gustafson's Law ka perspective interesting hai — ye Amdahl ko ulta karke sochta hai. Gustafson kehta hai ki agar aap apne resources badhne ke saath problem ka size bhi badha do (jaise bada dataset ya higher resolution), toh parallelism bohot acche se scale karta hai. Real world mein aksar aisa hi hota hai — jab aapke paas zyada computing power hoti hai, toh aap bade problems solve karne lagte ho. Toh dono laws ek saath aapko decision lene mein madad karte hain ki kab cores badhana worth hai aur kab nahi.

Go deeper — visual, from zero

Test yourself — Parallelism & Multicore

Connections