Calculate the Speedup
Intermediate · Write the code · from Parallel and Distributed Computing: Speedup and Its Limits
From the lesson: How long do sequential and parallel solutions take?
A sequential solution takes as long as the sum of all of its steps. A parallel solution has two kinds of work. A parallel solution always consists of a parallel portion, the tasks that can run at the same time, and a sequential portion, the tasks that cannot. A photo-editing app shows both.
Read this part of the lessonWrite speedup(sequential_tasks, parallel_tasks). Doing every task one after another gives the sequential time; running the parallel tasks at the same time, each on its own processor, gives the parallel time. Return the sequential time divided by the parallel time, rounded to 2 decimal places. parallel_tasks always has at least one task.
speedup([10], [30, 30, 30]) -> 2.5 (100 / 40)What Check runs
Your code runs first, then each of these lines, and 1 more that stay hidden. The output must match exactly.
| Runs | Expected output |
|---|---|
| print(speedup([10], [30, 30, 30])) | 2.5 |
| print(speedup([], [20, 20, 20, 20])) | 4.0 |
| print(speedup([5, 5], [40])) | 1.0 |
More Parallel Computing exercises
- Parallel Running TimeBeginner
- The Best Split for Two ProcessorsAdvanced