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.
ModelWhat happensA common setting
SequentialOperations are performed in order, one at a timeOne processor
ParallelThe program is broken into smaller sequential operations, some performed at the same timeOften one computer with several processors
DistributedMultiple devices are used to run one programMany 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.
The same program, sequential and parallel. Time axis from 0 to 100 seconds. One processor: 100 seconds. Processor 1 runs the setup of 8 seconds, then tasks of 32, 25, 19, 10 and 6 seconds one after another. Five processors, one task each: 40 seconds. Processor 1 runs the 8-second setup and then the 32-second task. Processors 2 to 5 sit idle during the setup, then run the 25, 19, 10 and 6-second tasks, and sit idle again until the 32-second task ends. A line marks done at 40. Legend: setup, cannot be divided; independent task; processor idle, waiting. Speedup: 100 divided by 40 is 2.5.

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 array. The program still gives every task a processor of its own.
• Change sequential / parallel to parallel / sequential.
• Add console.log("Shared out:", sequential / 5); as the last line. It is the tempting wrong method: the whole time shared out over five processors.
let setup = 10;
let tasks = [38, 12, 55, 25, 42];

let total = 0;
let longest = tasks[0];
for (const seconds of tasks) {
  total = total + seconds;
  if (seconds > longest) {
    longest = seconds;
  }
}

let sequential = setup + total;
let parallel = setup + longest;
console.log("Sequential time:", sequential, "seconds");
console.log("Parallel time:", parallel, "seconds");
console.log("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.
Fewer processors than tasks. Time axis from 0 to 100 seconds. Three processors: 40 seconds. Processor 1 runs the 8-second setup, then the 32-second task. Processor 2 is idle during the setup, then runs the 25-second and 6-second tasks. Processor 3 is idle during the setup, then runs the 19-second and 10-second tasks. A line marks done at 40. Two processors: 56 seconds. Processor 1 runs the 8-second setup, then the 32, 10 and 6-second tasks. Processor 2 is idle during the setup, then runs the 25 and 19-second tasks, then waits. A line marks done at 56. Each processor runs its share one task after another. The program is done when the busiest processor is done.
The program below runs the first program's five tasks on three processors. Each task is a record 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 { seconds: 12, processor: 1 } to { seconds: 12, processor: 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.
let setup = 10;
// each task: its time in seconds, and the processor that runs it
let tasks = [
  { seconds: 38, processor: 3 },
  { seconds: 12, processor: 1 },
  { seconds: 55, processor: 1 },
  { seconds: 25, processor: 3 },
  { seconds: 42, processor: 2 },
];
let shares = [0, 0, 0];

for (const task of tasks) {
  // processor 1's share is at index 0
  shares[task.processor - 1] = shares[task.processor - 1] + task.seconds;
}
console.log("Shares:", shares);

let busiest = shares[0];
for (const share of shares) {
  if (share > busiest) {
    busiest = share;
  }
}
console.log("Busiest share:", busiest, "seconds");
console.log("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.
Two tall racks of servers in a dark room, their front panels covered in rows of small green and blue lights.
Racks of servers. A distributed system spreads one job across many machines like these. Photo: NOIRLab/NSF/AURA/T. Slovinský, CC BY 4.0, via Wikimedia Commons.