Article
Working out the speedup
A phone company says: "Our 4-processor phone runs this app 4 times faster." Is that really true? You can check it yourself with two numbers and one division.
On the exam, assume that all processors are equally fast, that a task cannot be split further, and that passing results between processors takes no time.
Two times
Sequential time is the time when one processor does all the tasks, one after another. It is the sum of all the task times.
Parallel time is the time until the last processor finishes. Each processor does its own tasks one after another, so a processor's time is the sum of its tasks. The parallel time is the time of the busiest processor. If some part must run alone (a step that comes first or last), add its time too.
Here are six tasks, shared between 2 processors.
| Task | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| Time (seconds) | 8 | 6 | 5 | 4 | 3 | 2 |
- Sequential time: 8 + 6 + 5 + 4 + 3 + 2 = 28 seconds.
- Plan: Processor 1 does A and B (8 + 6 = 14). Processor 2 does C, D, E and F (5 + 4 + 3 + 2 = 14).
- Parallel time: the busiest processor takes 14 seconds.
Finding the best split
You may be asked for the shortest possible parallel time. Two facts help:
- The time cannot be less than total ÷ number of processors. If the work was shared perfectly, everyone would finish together.
- The time cannot be less than the longest single task, because one processor must do it.
The answer is at least the bigger of these two numbers. Then try to reach it. Do not split the list in the order it is written. Share the time fairly.
Tasks of 9, 3, 3 and 2 seconds on 2 processors
Processor 1
A (9 s)Processor 2
B (3 s)C (3 s)D (2 s)
Processor 2 finishes after 3 + 3 + 2 = 8 seconds and then waits. The busiest processor, Processor 1, takes 9 seconds.
Check your understanding
Four independent tasks take 7, 5, 4 and 2 seconds. They run on 2 processors, and each task is given to one processor. What is the shortest possible parallel time?
Speedup
Speedup tells you how many times faster the parallel solution is:
speedup = sequential time ÷ parallel time
In the first example, 28 ÷ 14 = 2. The parallel solution is twice as fast. In the second, 17 ÷ 9 is about 1.89, which is less than 2, because the long task A held things back. Always put the sequential time on top. If your answer is below 1, you turned the fraction upside down.
Check your understanding
A job takes 30 seconds sequentially and 12 seconds in parallel. What is the speedup?
The part that must run alone
Many programs have a first step and a last step that cannot run in parallel. Suppose a job has a 3-second setup, then four tasks (6, 6, 5 and 5 seconds), then a 2-second final step that needs all four results. On 2 processors:
Setup, four tasks, final step on 2 processors
Processor 1
Setup (3 s)6 s5 sFinal (2 s)Processor 2
waits (3 s)6 s5 swaits (2 s)
- Sequential: 3 + 6 + 6 + 5 + 5 + 2 = 27 seconds.
- Parallel: 3 + 11 + 2 = 16 seconds.
- Speedup: 27 ÷ 16 = about 1.69.
With 4 processors the middle part takes only 6 seconds, so the time is 3 + 6 + 2 = 11 seconds and the speedup is 27 ÷ 11, about 2.45. That is much less than 4.
More processors: smaller and smaller gains
Look at a job with a 4-second setup, eight tasks of 3 seconds each, and a 2-second final step. Sequentially it takes 4 + 24 + 2 = 30 seconds.
| Processors | Parallel time | Speedup |
|---|---|---|
| 1 | 30 s | 1 |
| 2 | 4 + 12 + 2 = 18 s | about 1.67 |
| 4 | 4 + 6 + 2 = 12 s | 2.5 |
| 8 | 4 + 3 + 2 = 9 s | about 3.33 |
Going from 1 to 2 processors saves 12 seconds. Going from 4 to 8 saves only 3. These are diminishing returns. The 6 seconds of setup and final step never get shorter, and with only 8 tasks, a ninth processor has nothing to do. The sequential part sets a limit that no number of processors can beat.
Common mistakes
- "Parallel time = sequential time ÷ number of processors." Only if the work is shared perfectly and nothing must run alone.
- Adding the processors' times together. The processors work at the same time. Take the largest time, not the sum.
- Forgetting the part that runs alone. Add the first and last steps to the busiest processor's time.
- Dividing the wrong way round. Speedup is sequential ÷ parallel. For a real speedup, the answer is 1 or more.
- "Twice as many processors always means twice the speed." Because of the sequential part and the longest task, the gain gets smaller each time.
On the exam
You will see a table of tasks and times, and be asked for the shortest time on 2 or 3 processors, the speedup, or which plan is best. Find the total, divide by the processors, check the longest task, then try to build a plan that reaches that number. You may also be asked for the reason a solution does not reach the ideal: tasks that depend on each other, or one long task.
Key words
Sequential time: the time to do all tasks on one processor. It is the sum of the task times.
Parallel time: the time until the last processor finishes, including any part that must run alone.
Speedup: sequential time ÷ parallel time.
Diminishing returns: each extra processor gives a smaller gain than the one before.