Unit 4: Algorithms · Parallel and distributed computing

Article

Distributed computing

7 min read

Scientists want to study how proteins in the human body fold into their shapes. The calculations are so big that one computer would need thousands of years. So they ask thousands of ordinary people to lend their computers' spare time. Each computer solves one small piece, and a central computer puts the pieces together. This is distributed computing.

Many devices, one problem

In distributed computing, multiple devices (computers, phones, servers) are connected by a network, and together they run one program. The problem is split into parts. Each device works on a part, and sends its result back.

A distributed system

CoordinatorNetworkDevice 1Device 2Device 3Device 4
The coordinator hands out the parts. The devices can be in the same room or on different continents.

How does it differ from the other two models?

ModelHow the work is doneExample
SequentialOne processor, one step at a timeA simple program on an old calculator
ParallelSeveral processors, usually inside one computer, some tasks at the same timeFiltering a photo on a 4-core laptop
DistributedMany separate devices linked by a network, each doing a partThousands of volunteers' computers working on one science project

Check your understanding

Which statement describes distributed computing?

Why use many devices?

Some problems are too big for one computer. There are two ways in which a problem can be too big:

  • Too much work. One computer would need years. A thousand computers each doing a thousandth of the work could finish in days.
  • Too much data. The data does not fit on one computer's storage. A search engine stores copies of billions of web pages. No single disk could hold them, so the pages are spread over very many machines. A search is sent to all of them, and each one searches its own pages.

Distributed solutions can scale. If the problem grows, you add more devices. They can also keep going if one device breaks, because the others carry on.

What it costs

Distributed computing is not free.

  • Communication. Parts and results travel across the network. That is much slower than passing data around inside one computer, and it takes time that a single computer would not need.
  • Coordination. Someone must split the job, send the parts, collect the results and combine them. A device that is slow, or that fails or goes offline, must be noticed, and its part given to someone else.
  • Trust and privacy. If strangers' computers help, a result may be wrong by accident or on purpose. Data sent to other devices may need protecting.
  • Some parts still run alone. Splitting the job and combining the results happen in one place, so the sequential part limit from the last article still applies.

One round of a distributed job

  1. 1

    Coordinator → Device 1

    part 1 of the data

  2. 2

    Coordinator → Device 2

    part 2 of the data

  3. Both devices work at the same time.
  4. 3

    Device 1 → Coordinator

    result 1

  5. 4

    Device 2 → Coordinator

    result 2

  6. The coordinator combines the results.
The four network messages are time that a single computer would not spend.

Check your understanding

Which is a cost of distributed computing that a single computer does not have?

Worked example: counting words

A company must count the words in 1,000,000 documents. One computer needs 1,000 seconds. With n devices, each does 1/n of the documents. Assume that sending out the parts and collecting the results costs 10 seconds in total, whatever the number of devices.

DevicesWork per deviceCommunicationTotal timeSpeedup
1 computer1,000 snone1,000 s1
10100 s10 s110 sabout 9.1
10010 s10 s20 s50
1,0001 s10 s11 sabout 90.9

Ten times more devices (from 100 to 1,000) made the job only 9 seconds faster. By then, almost all the time is communication. The more devices, the more the costs matter. More devices usually help, with diminishing returns, as with parallel computing.

Common mistakes

  • "Distributed and parallel mean the same." Parallel computing uses several processors, usually in one machine. Distributed computing uses several separate devices connected by a network.
  • "Distributed is always faster." Not for small jobs, or when communication takes longer than the work saved.
  • "The devices do not need to talk." They do. They receive their parts and send back their results.
  • "Every device runs the whole program." Each device handles a part of the problem.
  • "It only works for volunteers." Big companies run distributed systems in their own data centres, such as the machines behind a search engine.
  • "If one device fails, everything fails." A well-designed system carries on, and the failed device's part is given to another.

On the exam

You may be asked to compare sequential, parallel and distributed solutions, or to say why a problem needs a distributed solution: the processing time or the storage it needs is too much for one computer. You may also be asked about the costs, such as communication time. Remember the definition: multiple devices are used to run a program.

Key words

Distributed computing: using multiple devices, connected by a network, to run a program.

Coordinator: the device that splits the job, sends out the parts and combines the results.

Communication cost: the time taken to send data between devices over a network.

Scale: to cope with a bigger problem, here by adding more devices.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, this site. All lessons and questions here are written by JrCodex.