From Code to Performance

Exercise 7: Implement Amdahl's Law Experiment

Objective: Quantitatively explore theoretical vs. real speedup.

Tasks:

  1. Write a program that has a controlled sequential and parallel portion:
  2. // 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);
  1. Time both parts separately.
  1. Vary the proportion of sequential code (e.g., 10%, 30%, 50%) and measure total runtime.
  1. Calculate theoretical speedup using S=1(1-P)+PNS=(1-P)+NP1 and compare with your actual measured speedup.
  1. Plot results (N = number of threads, P = parallel fraction).

Learning Goal: See how serial bottlenecks limit scalability in practice.