Back

Activity 3.10: Sequential, Parallel, and Distributed

divider

Session 64: Arithmetic, Not Vocabulary

This session has real calculations in it, and they are the kind the exam asks you to do. Three definitions, one formula, and one situation where the formula does not apply.

Do them on paper. There is a C# program at the end you may use to check yourself, but the exam gives you a table and a pencil.

divider

Activity 3.10

Sequential, Parallel, and Distributed

Key Concepts

Three Computational Models

The Formula, and Its Assumption

Speedup, and Why It Stops

Three Models

Definitions
SEQUENTIAL operations performed in order, one at a time
PARALLEL the program broken into smaller sequential
operations, SOME performed simultaneously
one computer, multiple processors
DISTRIBUTED multiple DEVICES used to run a program

Parallel: one computer, several processors. Distributed: several devices.

The Distinction Most Likely to Be Asked

Parallel — multiple processors in one machine, sharing its memory.

Distributed — multiple machines.

So distributed computing can solve problems that would not fit on one computer: too slow to finish there, or too big to store.

Your Program Is Sequential

Every program you have written this year runs one statement at a time, in order. That is sequential computing.

A sequential solution takes as long as the sum of all its steps.

4 + 1 + 6 + 2 + 3 = 16 seconds. That is the whole rule.

Parallel Has a Formula

CSN-2.A.6
A PARALLEL SOLUTION TAKES AS LONG AS
its sequential tasks
PLUS
the longest of its parallel tasks
That is the exam's formula. It assumes
every parallel task gets its own processor.

And an Assumption

Count the processors
BUT WHAT IF THERE ARE ONLY TWO PROCESSORS?
Three tasks: 30s, 40s, 50s. Two processors.
The formula says: longest parallel task = 50.
Try it:
P1: 50 P2: 30 + 40 = 70 -> 70
P1: 50 + 30 = 80 P2: 40 -> 80
P1: 50 + 40 = 90 P2: 30 -> 90
The best you can do is 70, not 50.

70, not 50. The formula assumed three processors and you have two.

So Read the Question

How many processors? If the question says, that number matters.

Enough for every task → use the formula.

Fewer than tasks → you have to hand the work out yourself.

Handing the Work Out

Four steps
WHEN THERE ARE FEWER PROCESSORS THAN TASKS
1 hand the tasks out among the processors
2 add up each processor's total
3 the time is the BIGGEST of those totals
4 try other arrangements: you want the
smallest possible biggest total
The formula is the special case where every
task gets a processor to itself.

You are looking for the smallest possible biggest total.

Speedup

One division
SPEEDUP
time taken sequentially
------------------------------------
time taken in parallel
120 seconds sequential, 70 in parallel
120 / 70 = 1.71

Sequential divided by parallel. Not the other way round.

A Sanity Check

Speedup should be greater than 1.

If you get 0.58, you divided the wrong way round.

If you get 47 with two processors, something is wrong. Two processors can at most halve the time.

Why Parallel Is Worth It

Big problems split into pieces that do not depend on each other.

Weather forecasting. Rendering the frames of a film. Searching a huge dataset.

And parallel solutions scale better than sequential ones.

But It Runs Out

CSN-2.B.5
WHY MORE PROCESSORS STOP HELPING
"the efficiency of the solution is still limited
by the sequential portion. This means that at
some point, adding parallel portions will no
longer meaningfully increase efficiency."
If 50 seconds of the job cannot be split,
then 50 seconds is your floor. Forever.

Which Is a Familiar Shape

Adding processors stops helping once the sequential part dominates.

At 2.18, collecting more data did not remove bias.

More of the thing you have is not always the answer.

Today's Objectives

  • Defining sequential, parallel and distributed computing
  • Calculating the time taken by a sequential solution
  • Calculating a parallel solution's time, with and without a processor limit
  • Calculating speedup
  • Explaining why adding parallelism eventually stops helping

Key Terms

Sequential computing
Operations performed in order, one at a time. Takes as long as the sum of all its steps.
Parallel computing
The program broken into smaller sequential operations, some performed simultaneously.
Distributed computing
Multiple devices used to run a program.
Speedup
Sequential run time divided by parallel run time.

'F' → Fullscreen

divider

Today's Work

Both tasks on paper. The program after them is optional, and it is a checker, not a shortcut.


Task 1: Count the Processors

Three sets of independent tasks. Each processor runs one task at a time. Give speedup to two decimal places.

Part A: as many processors as tasks.

SetTask times (seconds)SequentialParallelSpeedup
A30, 40, 50
B20, 30, 40, 50
C10, 20, 90

Part B: the same three sets, only TWO processors.

SetTask timesBest splitParallelSpeedup
A30, 40, 50
B20, 30, 40, 50
C10, 20, 90
  • Show the split you chose, not just the answer.
  • Which set is unchanged from Part A, and why?
  • For set B, now try three processors. What happens, and why is that number familiar?

Set B with two processors and then three is the most important pair of calculations on this page.


Task 2: A Part That Cannot Be Split

A job has a 50-second part that cannot be split, then three independent tasks of 50s, 40s and 40s.

  1. How long does the whole job take sequentially?
  2. With unlimited processors for the parallel part?
  3. With two processors for the parallel part?
  4. With a hundred processors?
  5. What is the floor? Explain what number the job can never go below, no matter how many processors you buy.
  6. A weather model needs more memory than any single computer has. Which of the three models could run it, and why can the other two not?

Optional: Check Yourself
  • Run this and confirm it agrees with your Part B answer for set B.
  • Then change the assignment array to find a worse split.
  • Can you find a different split that ties with your best?
Checker
int[] tasks = { 20, 30, 40, 50 };
int processors = 2;
// Which processor runs each task: tasks 0 and 3 on
// processor 0, tasks 1 and 2 on processor 1.
int[] assignment = { 0, 1, 1, 0 };
double sequential = 0;
for (int i = 0; i < tasks.Length; i++)
{
sequential = sequential + tasks[i];
}
int[] loads = new int[processors];
for (int i = 0; i < tasks.Length; i++)
{
int p = assignment[i];
loads[p] = loads[p] + tasks[i];
}
int parallel = 0;
for (int p = 0; p < processors; p++)
{
Console.WriteLine($"processor {p}: {loads[p]}s");
if (loads[p] > parallel)
{
parallel = loads[p];
}
}
double speedup = sequential / parallel;
Console.WriteLine($"sequential: {sequential}s");
Console.WriteLine($"parallel: {parallel}s");
Console.WriteLine($"speedup: {speedup:F2}");
Output
processor 0: 70s
processor 1: 70s
sequential: 140s
parallel: 70s
speedup: 2.00

This is a checker, not a method. The exam gives you a table and a pencil, so the pencil version is the one that matters.

divider

Checkpoint

  • How long does a sequential solution take?
  • State the parallel formula, and the assumption it makes.
  • Write the speedup formula. Which number goes on top?
  • What is the difference between parallel and distributed computing?
  • Why does adding processors eventually stop helping?
divider

Reflection

Answer these before submitting your work.

  1. In Part B, set B took 70 seconds on two processors and 50 on three. Explain why the third processor helped and a fourth would not.
  2. Speedup with two processors is never more than 2. Explain why, and say what would have to be true for it to be exactly 2.
  3. More data does not remove bias, and more processors eventually stop helping. Describe what those two statements have in common.
divider

Submit

Both tables with your splits shown, Task 2, and your reflection.

Activity Complete