Sequential, Parallel and Distributed Computing
Scalability
Large data sets are difficult to process using a single computer and may require parallel or distributed systems. Scalability of systems is an important consideration when working with data sets, because the computational capacity of a system affects how data sets can be processed and stored.Scalability is the ability of a system to handle a bigger load by adding resources to the system.
Three computational models
Sequential computing is a computational model in which operations are performed in order, one at a time.Parallel computing is a computational model where the program is broken into multiple smaller sequential computing operations, some of which are performed simultaneously. Parallel computing consists of a parallel portion and a sequential portion. The parallel portion holds the operations that run at the same time. The sequential portion holds the ones that still run one after another.
Distributed computing is a computational model in which multiple devices are used to run a program.
These three are models, ways of organizing the work. Only the definition of distributed computing says anything about hardware: it needs more than one device. Parallel computing is often done on one computer with several processors, but its definition asks only that some of the operations run at the same time.
| Model | What happens | A common setting |
|---|---|---|
| Sequential | Operations are performed in order, one at a time | One processor |
| Parallel | The program is broken into smaller sequential operations, some performed at the same time | Often one computer with several processors |
| Distributed | Multiple devices are used to run one program | Many separate computers, each running part of the program |
How long does it take?
Comparing the efficiency of solutions can be done by comparing the time each one takes to perform the same task.A sequential solution takes as long as the sum of all of its steps.
A parallel computing solution takes as long as its sequential tasks plus the longest of its parallel tasks. The sequential tasks are the parts that cannot be split up, so they still have to run start to finish before or after everything else. The parallel tasks run at the same time as each other, so the group of them is finished when its slowest member is finished. In the example below, the setup step is the sequential portion and the five tasks are the parallel portion.
Speedup
The speedup of a parallel solution is measured in the time it took to complete the task sequentially divided by the time it took to complete the task when done in parallel.For the program above that is 100 divided by 40, a speedup of 2.5. The parallel version is 2.5 times as fast as the sequential one.
Note the order. Sequential time goes on top. Dividing the other way round gives 0.4, which would be a slowdown, and would be the answer to a question nobody asked.
The program below has a setup step and five tasks, each on a processor of its own. It works out both times and the speedup. Run it, then make each change below and run it again. Press Reset before each change, so that each one starts from the original program.
• Add a sixth task of 26 seconds to the list. The program still gives every task a processor of its own.
• Change
sequential / parallel to parallel / sequential.• Add
print("Shared out:", sequential / 5) as the last line. It is the tempting wrong method: the whole time shared out over five processors.setup = 10
tasks = [38, 12, 55, 25, 42]
total = 0
longest = tasks[0]
for seconds in tasks:
total = total + seconds
if seconds > longest:
longest = seconds
sequential = setup + total
parallel = setup + longest
print("Sequential time:", sequential, "seconds")
print("Parallel time:", parallel, "seconds")
print("Speedup:", sequential / parallel)
Output
Press Run to see what this program prints.
Note: This IDE is for experimenting with the code in this lesson. Your changes are not saved, and refreshing the page puts back the original lesson code.
Fewer processors than tasks
The example gave every task a processor of its own. When there are fewer processors than tasks, a processor that finishes one task starts another, so each processor works through its share one task after another. A task is never split between processors here. The parallel portion then lasts as long as the busiest processor's share. The shortest time comes from dividing the tasks so that the busiest share is as small as it can be.With three processors, the 32-second task gets a processor to itself. The 25-second and 6-second tasks share a second one (31 seconds), and the 19-second and 10-second tasks share the third (29 seconds). The busiest share is 32 seconds, so the program still takes 8 plus 32, which is 40 seconds: two fewer processors, and no time lost.
With two processors, the best division puts 32, 10 and 6 on one (48 seconds) and 25 and 19 on the other (44 seconds). The program takes 8 plus 48, which is 56 seconds.
The program below runs the same five tasks on three processors. Each task is a tuple of its time in seconds and the processor that runs it, and
shares holds each processor's total. Run it, then make each change below and run it again. Press Reset before each change, so that each one starts from the original program.• Put the 12-second task on processor 2, by changing
(12, 1) to (12, 2). This is the best division of these tasks among three processors.• Put every task on processor 1.
• Add a fourth 0 to
shares, and put the 25-second task on processor 4.setup = 10
# each task is (seconds, the processor that runs it)
tasks = [(38, 3), (12, 1), (55, 1), (25, 3), (42, 2)]
shares = [0, 0, 0]
for seconds, processor in tasks:
# processor 1's share is at index 0
shares[processor - 1] = shares[processor - 1] + seconds
print("Shares:", shares)
busiest = shares[0]
for share in shares:
if share > busiest:
busiest = share
print("Busiest share:", busiest, "seconds")
print("Program time:", setup + busiest, "seconds")
Output
Press Run to see what this program prints.
Note: This IDE is for experimenting with the code in this lesson. Your changes are not saved, and refreshing the page puts back the original lesson code.
Scaling and distributed computing
Solutions that use parallel computing can scale more effectively than solutions that use sequential computing. Suppose five more tasks joined the running example, each no longer than 32 seconds. One after another, the program could take up to 8 plus 92 plus 160, which is 260 seconds. With ten processors, one task each, it still takes 8 plus 32, which is 40 seconds.When a solution uses more parallel computing, its efficiency is still limited by the sequential portion. At some point, adding parallel portions no longer meaningfully increases efficiency. Suppose the five tasks in the running example could be cut into pieces small enough to finish almost at once. The 8-second setup would remain, so the program could never take less than 8 seconds. Its speedup could never pass 100 divided by 8, which is 12.5.
Distributed computing allows problems to be solved that could not be solved on a single computer because of either the processing time or the storage needs involved. Some data sets do not fit on one machine, and some jobs would still be running years from now. Distributed computing allows much larger problems to be solved quicker than they could be solved using a single computer.
