Exercise 7: Implement Amdahl's Law Experiment
Objective: Quantitatively explore theoretical vs. real speedup.
Tasks:
- Write a program that has a controlled sequential and parallel portion:
// sequential section
for (i = 0; 1 < bigN; i++) seq += sqrt(i);
// parallel section
#pragma omp parallel for reduction(+:par)
for (i = 0; i < bigN; i++) sum += sin(i);
- Time both parts separately.
- Vary the proportion of sequential code (e.g., 10%, 30%, 50%) and measure total runtime.
- Calculate theoretical speedup using S=1(1-P)+PNS=(1-P)+NP1 and compare with your actual measured speedup.
- Plot results (N = number of threads, P = parallel fraction).
Learning Goal: See how serial bottlenecks limit scalability in practice.