Editor

Parallel Running Time

Beginner · 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 lesson

Write parallel_time(sequential_tasks, parallel_tasks). Both arguments are lists of task times in seconds. The sequential tasks run one after another, and every parallel task has its own processor. Return the total time for the whole solution. Either list may be empty.

parallel_time([10, 5], [30, 20, 25])  ->  45   (10 + 5 + 30)
def parallel_time(sequential_tasks, parallel_tasks):
# Sequential tasks add up; parallel tasks take as long as the longest
pass

What Check runs

Your code runs first, then each of these lines, and 1 more that stay hidden. The output must match exactly.

RunsExpected output
print(parallel_time([10, 5], [30, 20, 25]))45
print(parallel_time([4, 6], [9, 9, 9]))19
print(parallel_time([], [12, 7]))12

More Parallel Computing exercises

All Python exercises · 50 practice problems