01 / 21

Parallel & Distributed
Computing

Explore how modern systems split tasks across processors and networked machines to solve problems faster.

AP Computer Science Principles

What Is Sequential Computing?

In a sequential computing model, a single processor executes one operation at a time. Each task must finish before the next one starts: the total time is the sum of all task times.

Task A 3 s Task B 5 s Task C 2 s = 10 s Sequential: one after another

What Is Parallel Computing?

Parallel computing breaks a program into tasks that run simultaneously on multiple processors within the same machine. Independent tasks overlap in time, reducing total execution time.

CPU Core 1 Core 2 Task A (3 s) Task B (5 s) Task C (2 s) = 7 s Parallel: independent tasks overlap

What Is Distributed Computing?

Distributed computing spreads work across multiple networked computers. Each machine processes a portion of the task, and results are combined. This enables computation at a scale impossible for a single machine.

Coordinator Machine A Machine B Machine C Machine D Distributed: multiple machines over a network

The Speedup Formula

Speedup measures how much faster a parallel solution is compared to a sequential one. It is the ratio of sequential time to parallel time:

\( T_{\text{sequential}} \)
Time to complete all tasks on one processor, summing every task duration.
\( T_{\text{parallel}} \)
Time when tasks run simultaneously. Limited by the longest path through dependent tasks.

Computing Parallel Time

When tasks run in parallel, the total time is determined by the longest-running task in each parallel group plus any sequential portions:

1
Identify independent tasks: tasks that don't depend on each other's output can run in parallel.
2
Group parallel tasks: take the maximum duration from each group, not the sum.
3
Add sequential portions: dependent tasks still execute one after another.

Parallel vs Distributed

Parallel Distributed
Hardware Multiple cores in one machine Multiple networked machines
Communication Shared memory (fast) Network messages (slower)
Scale Limited by core count Virtually unlimited
Example Multi-threaded video render Google Search across data centers
Failure Impact Entire process may crash One node fails, others continue

How to Solve Speedup Problems

1
List all tasks and their individual durations.
2
Find sequential time: add up every task duration: \( T_{\text{seq}} = t_1 + t_2 + \cdots + t_n \).
3
Identify dependencies: which tasks must wait for others to finish?
4
Compute parallel time: for each parallel group, take \(\max\). Add sequential portions.
5
Divide: \(\text{Speedup} = T_{\text{seq}} \div T_{\text{par}}\). Report as a ratio or decimal.

Example 1: Two Processors

A program has four tasks: X (4 s), Y (6 s), Z (3 s), W (5 s). X and Y are independent. Z depends on X. W depends on Y. You have 2 processors.

CPU 1 X: 4 s Z: 3 s CPU 2 Y: 6 s W: 5 s 0 s 4 s 7 s 11 s Parallel: 11 s Sequential: 18 s

Example 2: Three Parallel Tasks

A web server handles a request in 3 steps: Authenticate (2 s), then three independent database queries Q1 (4 s), Q2 (3 s), Q3 (6 s), then Render (1 s).

Auth: 2 s Q1: 4 s Q2: 3 s Q3: 6 s Render: 1 s Parallel group: max(4, 3, 6) = 6 s

Example 3: Limits of Parallelism

A program has 5 tasks. Task A (10 s) must run first. Then B (4 s), C (6 s), D (3 s) can run in parallel. Finally E (2 s) runs last. You have 4 processors.

Sequential
\(10+4+6+3+2 = 25\) s
Parallel
\(10+\max(4,6,3)+2 = 18\) s
Speedup
\(\frac{25}{18} \approx 1.39\)

Amdahl's Law: The Speedup Ceiling

No matter how many processors you add, the sequential portion of your program limits the maximum speedup. If a fraction \( s \) of work must be sequential, the maximum speedup with \( n \) processors is:

50% sequential
Max speedup with infinite processors: \(\frac{1}{0.5} = 2\times\)
10% sequential
Max speedup with infinite processors: \(\frac{1}{0.1} = 10\times\)

Many machines still wait for the serial stage

Many computing machines work together while one serial stage holds up completion.Work that must happen sequentially limits the benefit of adding processors. Parallel time depends on dependencies and the busiest processor’s assigned work.

The serial part sets a speedup ceiling

One-processor and eight-processor timelines retain the same 40-second serial stage and divide the remaining 60 seconds.Suppose a 100-second workload contains 40 serial seconds and 60 perfectly divisible parallel seconds. Eight ideal processors take 40 + 60/8 = 47.5 seconds, a speedup of about 2.11. The limiting speedup is 100/40 = 2.5.

Balance the processor loads

Two processor timelines show task pairs 5 and 3 seconds, and 6 and 2 seconds, both totaling 8 seconds.For independent tasks lasting 5, 3, 6 and 2 seconds on two processors, assign 5 + 3 to one and 6 + 2 to the other. Both finish at 8 seconds, reaching the 16/2 total-work lower bound.

Benefits and Challenges

✓ Speed
Tasks complete faster by overlapping work across processors or machines.
✓ Scalability
Distributed systems grow by adding more machines as demand increases.
✕ Overhead
Communication between processors or machines takes time and can reduce gains.
✕ Complexity
Coordinating tasks, handling failures, and avoiding conflicts is difficult to program.

Real-World Applications

Weather Forecasting
Supercomputers split the atmosphere into grid cells; each processor simulates its own cell in parallel.
Streaming Video
Netflix distributes content across data centers worldwide so users connect to the nearest one.
Cryptocurrency
Bitcoin mining distributes hash computations across thousands of machines racing to solve a puzzle.

Common Mistakes

✕ Summing Parallel Tasks
Students add task times that run simultaneously. For parallel tasks, use max(), not sum.
✕ Ignoring Dependencies
Assuming all tasks can run in parallel. Tasks that need another's output must run sequentially.
✕ Confusing Parallel and Distributed
Parallel = one machine, multiple cores. Distributed = multiple machines over a network.

Summary Comparison

Sequential Parallel Distributed
Processors 1 Multiple cores Multiple machines
Time Calc \(\sum t_i\) \(\sum t_{\text{seq}} + \max(t_{\text{par}})\) \(\sum t_{\text{seq}} + \max(t_{\text{par}})\) + network
Speedup Baseline (\(1\times\)) \(> 1\times\) (limited by serial) \(> 1\times\) (limited by network)
Best For Simple, dependent tasks CPU-heavy, splittable work Massive-scale problems

Question 1 of 5

Tasks P (3 s) and Q (5 s) run in parallel, followed by task R (4 s) running sequentially. What is the total parallel execution time?

Question 2 of 5

A program takes 20 seconds sequentially and 8 seconds with parallel processing. What is the speedup?

Question 3 of 5

Which best describes the difference between parallel and distributed computing?

Question 4 of 5

A program is 40% sequential and 60% parallelizable. With infinitely many processors, what is the maximum possible speedup?

Question 5 of 5

Tasks A (2 s), B (7 s), C (4 s), and D (1 s) all run in parallel on 4 processors. What is the total execution time for the parallel section?