Unit 1 · Introduction to Parallel Computing¶
1. Setting the scene¶
Scenario: Six hours is too slow
The SensorGrid daily report is a Python script that reads yesterday's \(3.5 \times 10^{8}\) readings, computes averages per sensor and district, and flags anomalies. It starts at midnight and finishes at 6 a.m. on a good day. When a storm doubles the traffic, the report arrives after the office has opened.
The server has 16 cores. The script uses one. A colleague suggests: "Let's just buy a faster CPU."
Guiding questions
- Why can't we simply buy a CPU that is twice as fast?
- If we split the work across 16 cores, will the report take \(6/16\) hours?
- What gets in the way: the work, the communication, or the balance between workers?
2. Intended learning outcomes¶
| # | Outcome | Bloom | CLO |
|---|---|---|---|
| ILO 1.1 | Define a parallel computer and parallel computing. | REMEMBER | 1 |
| ILO 1.2 | Compute speedup and efficiency, and estimate the limit set by Amdahl's law. | APPLY | 1 |
| ILO 1.3 | Explain how communication, load imbalance and synchronisation limit speedup. | UNDERSTAND | 1 |
| ILO 1.4 | Distinguish data parallelism from task parallelism with examples. | UNDERSTAND | 3 |
| ILO 1.5 | Explain why single core performance stopped improving (ILP and clock frequency). | UNDERSTAND | 1 |
3. What is parallel computing?¶
Definition
A parallel computer is a collection of processing elements that cooperate to solve problems quickly.
flowchart TB
P["One shared problem"] --> P1["P1"] & P2["P2"] & P3["P3"] & P4["P4"]
P1 & P2 & P3 & P4 --> R["One result"]
Two words in this definition matter: cooperate (the processors must coordinate) and quickly (we care about performance, but also about efficiency, the performance we get per unit of hardware).
4. Learning by playing: three classroom demos¶
The first lecture turns students into processors. Each demo exposes one enemy of parallel performance.
Demo 1: two students add the numbers 1 to 32¶
sequenceDiagram
participant S1 as Student 1
participant S2 as Student 2
Note over S1,S2: split the input: 1 to 16 and 17 to 32
par compute in parallel
S1->>S1: sum(1..16) = 136
and
S2->>S2: sum(17..32) = 392
end
S2->>S1: send partial sum 392
S1->>S1: 136 + 392 = 528
Note over S1: final answer 528
Speedup measures how much faster the parallel version runs:
Efficiency measures how well the \(P\) processors are used:
Worked example
A program takes \(T(1) = 120\) s on one processor and \(T(4) = 40\) s on four.
The program runs 3 times faster, but a quarter of the hardware time is lost, here to communication.
Observation. Communication (telling each other the partial sums) limited the speedup. Sitting closer together or speaking louder reduced the communication cost and improved the speedup. Parallelism is not only about dividing work; it is also about coordinating it efficiently.
Demo 2: four students, unequal work¶
Student 1 and 2 receive small groups of numbers, student 3 a medium group, student 4 a large group.
gantt
title Bad distribution: P4 decides the finishing time
dateFormat X
axisFormat %s
section P1
work :a1, 0, 2
idle :crit, 2, 8
section P2
work :0, 2
idle :crit, 2, 8
section P3
work :0, 4
idle :crit, 4, 8
section P4
work :0, 8
gantt
title Balanced distribution: everyone finishes together
dateFormat X
axisFormat %s
section P1
work :0, 4
section P2
work :0, 4
section P3
work :0, 4
section P4
work :0, 4
Total work is 16 units in both cases. With a bad distribution, \(T(4) = 8\) and \(S = 16/8 = 2\); balanced, \(T(4) = 4\) and \(S = 4\). Load imbalance leaves processors idle.
Demo 3: many students, constant chatter¶
Every student holds one value and must repeatedly exchange values with neighbours. Each computation is tiny, but communication happens again and again.
pie showData
title Where did the class spend its time?
"Computation" : 20
"Communication and synchronisation" : 80
When communication dominates, adding processors can make a program slower. A simple model makes this concrete: if the computation \(W\) is split across \(P\) processors but each processor adds a communication cost \(c \cdot P\),
Beyond \(P^{*}\) the time grows again.
5. How far can we go? Amdahl's law¶
Suppose a fraction \(f\) of the program can be parallelised and the rest \((1-f)\) is strictly sequential (reading the input file, writing the report). With \(P\) processors:
Worked example: the SensorGrid report
Profiling shows that 90 % of the six hours is the per sensor computation (\(f = 0.9\)); 10 % is reading and writing files.
Even with infinitely many cores, \(S \le 1/0.1 = 10\): the report can never take less than 36 minutes unless the sequential part shrinks.
xychart-beta
title "Amdahl's law for f = 0.9"
x-axis "Processors P" [1, 2, 4, 8, 16, 32, 64, 128]
y-axis "Speedup S(P)" 0 --> 10
line [1, 1.82, 3.08, 4.71, 6.4, 7.8, 8.77, 9.34]
Gustafson's view. In practice, bigger machines are used for bigger problems. If the parallel part grows with \(P\) while the sequential part stays fixed, the scaled speedup is \(S(P) = (1-f) + f\,P\), which keeps growing. SensorGrid will exploit this: more cores let us analyse more sensors, not only the same sensors faster.
6. Two ways to divide work: grading 300 exams¶
Scenario: three teaching assistants
300 exams with 15 questions each must be graded quickly. Three teaching assistants (TAs) are available.
Each TA does the same type of work on different data: TA 1 grades exams 1 to 100 completely, TA 2 exams 101 to 200, TA 3 exams 201 to 300. They work independently.
flowchart LR
E["300 exams"] --> T1["TA 1<br/>exams 1 to 100<br/>all 15 questions"]
E --> T2["TA 2<br/>exams 101 to 200<br/>all 15 questions"]
E --> T3["TA 3<br/>exams 201 to 300<br/>all 15 questions"]
Each TA does a different type of work on the same data: TA 1 grades questions 1 to 5, TA 2 questions 6 to 10, TA 3 questions 11 to 15. Stacks of 100 exams rotate between them.
sequenceDiagram
participant T1 as TA 1 (Q1 to Q5)
participant T2 as TA 2 (Q6 to Q10)
participant T3 as TA 3 (Q11 to Q15)
Note over T1,T3: Round 1: each grades its questions on its own stack of 100
T1->>T2: pass stack A
T2->>T3: pass stack B
T3->>T1: pass stack C
Note over T1,T3: Round 2: grade again
T1->>T2: pass
T2->>T3: pass
T3->>T1: pass
Note over T1,T3: Round 3: all 300 exams complete
Either way, with \(t\) the time to grade one question:
Which could be faster in reality? Task parallelism means each TA remembers only 5 answers instead of 15 (a smaller "working set", like a cache), but it adds exchanges of paper (communication). Real questions also appear: are all TAs equally fast? Do they sit at the same table or grade at home? Where is the solution sheet? These are exactly the issues of heterogeneous processors, communication, and memory that the rest of the course addresses.
7. Why we need parallel computing¶
- Save time and money, and solve larger problems than one machine can.
- Some problems are too slow even on today's fastest supercomputers; artificial intelligence has become a major source of such problems.
- Simulation is the third pillar of science, next to theory and experiment, for questions that are too difficult (huge wind tunnels), too expensive (a throw away passenger jet), too slow (climate change) or too dangerous (drug design) to test physically.
- Big data analytics: data is only valuable once it is analysed.
Case: PageRank¶
A web page is important if important pages link to it:
\(\mathrm{In}(A)\): pages linking to \(A\); \(L(i)\): number of outgoing links of \(i\); \(d \approx 0.85\): damping factor. The update is iterated until the values converge.
flowchart LR
B["Page B"] --> A["Page A"]
C["Page C"] --> A
D["Page D"] --> A
C --> D
A --> C
Worked example: one PageRank update
Start with all ranks equal to 1. Page A has in links from B (\(L(B) = 1\)), C (\(L(C) = 2\)) and D (\(L(D) = 1\)):
With billions of pages, every iteration touches every link. The graph is split across many machines (Spark, Hadoop, Pregel); each computes local ranks and exchanges contributions. Parallelism makes PageRank possible, not just faster.
8. Three course themes¶
mindmap
root((Parallel<br/>thinking))
Programs that scale
Decompose work
Assign to processors
Communicate
Parallel hardware
Machines differ
Data movement matters
Power, area, cost
Efficiency
Fast is not efficient
Use the machine well
Save energy
Theme 3 in one question
Is a speedup of 2 on a computer with 10 processors a good result? \(E = 2/10 = 20\,\%\): fast, but 80 % of the machine is wasted.
9. Why did developers avoid parallelism for so long?¶
For decades, single thread performance roughly doubled every 18 months. Developers could wait for next year's CPU and get faster code for free, the so called free lunch. That improvement came from two sources:
| Source | Meaning | Example |
|---|---|---|
| Instruction level parallelism (ILP) | do more independent instructions in the same clock cycle | in a = x*x + y*y, the two products are independent |
| Clock frequency | run more clock cycles per second | 2 GHz → 3 GHz |
The execution time of a program is captured by the processor performance equation:
ILP lowers the \(CPI\) (more instructions per cycle), higher frequency raises \(f\). Around 2005 both engines stalled: ILP ran out of independent instructions, and higher frequencies produced too much heat (Unit 3). The only remaining lever is more cores and more lanes, and it only helps software that is written to use them.
flowchart TB
X["a = x*x + y*y"] --> M1["x * x"] & M2["y * y"]
M1 & M2 --> ADD["add results"] --> A["a"]
10. A first look at the processor¶
flowchart TB
FD["Fetch / Decode<br/>which instruction is next?"] --> ALU["Execution unit (ALU)<br/>arithmetic and logic"]
ALU <--> REG["Registers R0 R1 R2 R3<br/>execution context"]
From the programmer's view, a program has variables, loops and output. From the processor's view it is a list of instructions, executed one per clock cycle in the simplest model:
Four instructions take four cycles. Faster execution needs parallelism. Unit 3 opens this box.
11. Classwork¶
Parallel thinking without a computer (20 min, groups of four)
- Repeat Demo 2 with the number groups on your worksheet. Measure the time of each "processor" and draw the Gantt chart. Compute \(S\) and \(E\).
- Redistribute the numbers to balance the load. Recompute \(S\) and \(E\).
- A program is 95 % parallel. What is the maximum speedup? How many processors reach 80 % of it?
Solution to 3
\(S_{\max} = 1/0.05 = 20\). We need \(S(P) \ge 16\): \(\frac{1}{0.05 + 0.95/P} \ge 16 \Rightarrow 0.05 + 0.95/P \le 0.0625 \Rightarrow P \ge 76\).
12. Check your understanding¶
A program runs in 200 s on 1 core and 25 s on 16 cores. Compute S and E.
\(S = 200/25 = 8\), \(E = 8/16 = 50\,\%\).
Name the three enemies of speedup from the demos.
Communication cost (Demo 1), load imbalance (Demo 2), communication or synchronisation dominating computation (Demo 3).
Is the exam grading example with question splitting data or task parallelism?
Task parallelism: each TA performs a different task (different questions) on the same data.
13. Key takeaways¶
- A parallel computer is a set of processors that cooperate to solve a problem quickly.
- \(S = T(1)/T(P)\) and \(E = S/P\); the sequential fraction caps speedup at \(1/(1-f)\).
- Communication, imbalance and synchronisation are the enemies of speedup.
- The free lunch of rising clock speeds and ILP ended; performance now comes from parallelism.
14. Link to assessment¶
Every portfolio experiment must report \(T(1)\), \(T(P)\), \(S\) and \(E\) for several values of \(P\), and discuss the result against Amdahl's law.
Further reading¶
- K. Fatahalian, K. Olukotun, CS149 Parallel Computing, Stanford University (lecture 1).
- G. M. Amdahl (1967), Validity of the single processor approach to achieving large scale computing capabilities, AFIPS.
- J. L. Gustafson (1988), Reevaluating Amdahl's law, CACM 31(5).