ArticleslgStudy

computer science

Collective operation

Collective operation is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Collective operation rather than just read about it. In short: Collective operations are building blocks for interaction patterns, that are often used in SPMD algorithms in the parallel programming context. Hence, there is an interest in efficient realizations of these operations.

Collective operation — main illustration
Collective operation — illustration

Key takeaways

  • Collective operation belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Collective operation to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Collective operation from memory before moving on to harder problems.

Reference excerpt

Collective operations are building blocks for interaction patterns, that are often used in SPMD algorithms in the parallel programming context. Hence, there is an interest in efficient realizations of these operations. A realization of the collective operations is provided by the Message Passing Interface (MPI).

Definitions In all asymptotic runtime functions, we denote the latency α (or startup time per message, independent of message size), the communication cost per word β, the number of processing units p and the input size per node n. In cases where we have initial messages on more than one node we assume that all local messages are of the same size. To address individual processing units we use pi∈{p0,p1,…,pp−1}. If we do not have an equal distribution, i.e. node pi has a message of size ni, we get an upper bound for the runtime by setting n=max⁡(n0,n1,…,np−1). A distributed memory model is assumed. The concepts are similar for the shared memory model. However, shared memory systems can provide hardware support for some operations like broadcast (§ Broadcast) for example, which allows convenient concurrent read. Thus, new algorithmic possibilities can become available.

Broadcast

The broadcast pattern is used to distribute data from one processing unit to all processing units, which is often needed in SPMD parallel programs to dispense input or global values. Broadcast can be interpreted as an inverse version of the reduce pattern (§ Reduce). Initially only root r with id 0 stores message m. During broadcast m is sent to the remaining processing units, so that eventually m is available to all processing units. Since an implementation by means of a sequential for-loop with p−1 iterations becomes a bottleneck, divide-and-conquer approaches are common. One possibility is to utilize a binomial tree structure with the requirement that p has to be a power of two. When a processing unit is responsible for sending m to processing units i..j, it sends m to processing unit ⌈(i+j)/2⌉ and delegates responsibility for the processing units ⌈(i+j)/2⌉..j to it, while its own responsibility is cut down to i..⌈(i+j)/2⌉−1. Binomial trees have a problem with long messages m. The receiving unit of m can only propagate the message to other units, after it received the whole message. In the meantime, the communication network is not utilized. Therefore pipelining on binary trees is used, where m is split into an array of k packets of size ⌈n/k⌉. The packets are then broadcast one after another, so that data is distributed fast in the communication network. Pipelined broadcast on balanced binary tree is possible in 𝒪(αlog⁡p+βn), whereas for the non-pipelined case it takes 𝒪((α+βn)log⁡p) cost.

Reduce

The reduce pattern is used to collect data or partial results from different processing units and to combine them into a global result by a chosen operator. Given p processing units, message mi is on processing unit pi initially. All mi are aggregated by ⊗ and the result is eventually stored on p0. The reduction operator ⊗ must be associative at least. Some algorithms require a commutative operator with a neutral element. Operators like sum, min, max are common. Implementation considerations are similar to broadcast (§ Broadcast). For pipelining on binary trees the message must be representable as a vector of smaller object for component-wise reduction. Pipelined reduce on a balanced binary tree is possible in 𝒪(αlog⁡p+βn).

All-Reduce

The all-reduce pattern (also called allreduce) is used if the result of a reduce operation (§ Reduce) must be distributed to all processing units. Given p processing units, message mi is on processing unit pi initially. All mi are aggregated by an operator ⊗ and the result is eventually stored on all pi. Analog to the reduce operation, the operator ⊗ must be at least associative. All-reduce can be interpreted as a reduce operation with a subsequent broadcast (§ Broadcast). For long messages a corresponding implementation is suitable, whereas for short messages, the latency can be reduced by using a hypercube (Hypercube (communication pattern) § All-Gather/ All-Reduce) topology, if p is a power of two. All-reduce can also be implemented with a butterfly algorithm and achieve optimal latency and bandwidth. All-reduce is possible in 𝒪(αlog⁡p+βn), since reduce and broadcast are possible in 𝒪(αlog⁡p+βn) with pipelining on balanced binary trees. All-reduce implemented with a butterfly algorithm achieves the same asymptotic runtime.

Prefix-Sum/Scan

The prefix-sum or scan operation is used to collect data or partial results from different processing units and to compute intermediate results by an operator, which are stored on those processing units. It can be seen as a generalization of the reduce operation (§ Reduce). Given p processing units, message mi is on processing unit pi. The operator ⊗ must be at least associative, whereas some algorithms require also a commutative operator and a neutral element. Common operators are sum, min and max. Eventually processing unit pi stores the prefix sum ⊗i′<=imi′. In the case of the so-called exclusive prefix sum, processing unit pi stores the prefix sum ⊗i′<imi′. Some algorithms require to store the overall sum at each processing unit in addition to the prefix sums. For short messages, this can be achieved with a hypercube topology if p is a power of two. For long messages, the hypercube (Hypercube (communication pattern) § Prefix sum, Prefix sum § Distributed memory: Hypercube algorithm) topology is not suitable, since all processing units are active in every step and therefore pipelining can't be used. A binary tree topology is better suited for arbitrary p and long messages (Prefix sum § Large Message Sizes: Pipelined Binary Tree). Prefix-sum on a binary tree can be implemented with an upward and downward phase. In the upward phase reduction is performed, while the downward phase is similar to broadcast, where the prefix sums are computed by sending different data to the left and right children. With this approach pipelining is possible, because the operations are equal to reduction (§ Reduce) and broadcast (§ Broadcast). Pipelined prefix sum on a binary tree is possible in 𝒪(αlog⁡p+βn).

Barrier

… excerpt ends here. Continue reading the full article.

Illustrations

Collective operation: Information flow of Reduce operation performed on three nodes. f is the associative operator and α is the result of the reduction.
Information flow of Reduce operation performed on three nodes. f is the associative operator and α is the result of the reduction.
Collective operation: Information flow of All-Reduce operation performed on three nodes. f is the associative operator and α is the result of the reduction.
Information flow of All-Reduce operation performed on three nodes. f is the associative operator and α is the result of the reduction.
Collective operation: Information flow of Prefix-Sum/Scan operation performed on three nodes. The operator + can be any associative operator.
Information flow of Prefix-Sum/Scan operation performed on three nodes. The operator + can be any associative operator.
Collective operation: Information flow of Gather operation performed on three nodes.
Information flow of Gather operation performed on three nodes.
Collective operation: Information flow of All-Gather operation performed on three nodes.
Information flow of All-Gather operation performed on three nodes.

Worked examples

Example 1 — a first encounter with Collective operation

Start with the simplest possible case. Write down what Collective operation claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Collective operation before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Collective operation ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Collective operation

In research
Collective operation appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Collective operation in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Collective operation is common in secondary-school and first-year university syllabi. It links to neighbouring topics Algorithms, Distributed computing, Parallel computing, so understanding it makes those chapters shorter.
In everyday life
Look for Collective operation outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Collective operation” →

How to study Collective operation in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Collective operation means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Collective operation out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Collective operation in simple terms?

Collective operations are building blocks for interaction patterns, that are often used in SPMD algorithms in the parallel programming context. Hence, there is an interest in efficient realizations of these operations.

Why does Collective operation matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Collective operation?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Collective operation.

Tags

  • Algorithms
  • Distributed computing
  • Parallel computing

Keep exploring