ArticleslgStudy

computer science

Cannon's algorithm

Cannon's algorithm 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 Cannon's algorithm rather than just read about it. In short: In computer science, Cannon's algorithm is a distributed algorithm for matrix multiplication for two-dimensional meshes first described in 1969 by Lynn Elliot Cannon. It is especially suitable for computers laid out in an N × N mesh.

Key takeaways

  • Cannon's algorithm 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 Cannon's algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Cannon's algorithm from memory before moving on to harder problems.

Reference excerpt

In computer science, Cannon's algorithm is a distributed algorithm for matrix multiplication for two-dimensional meshes first described in 1969 by Lynn Elliot Cannon. It is especially suitable for computers laid out in an N × N mesh. While Cannon's algorithm works well in homogeneous 2D grids, extending it to heterogeneous 2D grids has been shown to be difficult. The main advantage of the algorithm is that its storage requirements remain constant and are independent of the number of processors. The Scalable Universal Matrix Multiplication Algorithm (SUMMA) is a more practical algorithm that requires less workspace and overcomes the need for a square 2D grid. It is used by the ScaLAPACK, PLAPACK, and Elemental libraries.

Algorithm overview When multiplying two n×n matrices A and B, we need n×n processing nodes p arranged in a 2D grid.

// PE(i , j) k := (i + j) mod N; a := a[i][k]; b := b[k][j]; c[i][j] := 0; for (l := 0; l < N; l++) { c[i][j] := c[i][j] + a * b; concurrently { send a to PE(i, (j + N − 1) mod N); send b to PE((i + N − 1) mod N, j); } with { receive a' from PE(i, (j + 1) mod N); receive b' from PE((i + 1) mod N, j ); } a := a'; b := b'; }

We need to select k in every iteration for every Processor Element (PE) so that processors don't access the same data for computing aik∗bkj. Therefore processors in the same row / column must begin summation with different indexes. If for example PE(0,0) calculates a00∗b00 in the first step, PE(0,1) chooses a01∗b11 first. The selection of k := (i + j) mod n for PE(i,j) satisfies this constraint for the first step. In the first step we distribute the input matrices between the processors based on the previous rule. In the next iterations we choose a new k' := (k + 1) mod n for every processor. This way every processor will continue accessing different values of the matrices. The needed data is then always at the neighbour processors. A PE(i,j) needs then the a from PE(i,(j + 1) mod n) and the b from PE((i + 1) mod n,j) for the next step. This means that a has to be passed cyclically to the left and also b cyclically upwards. The results of the multiplications are summed up as usual. After n steps, each processor has calculated all aik∗bkj once and its sum is thus the searched cij. After the initial distribution of each processor, only the data for the next step has to be stored. These are the intermediate result of the previous sum, a aik and a bkj. This means that all three matrices only need to be stored in memory once evenly distributed across the processors.

Generalisation In practice we have much fewer processors than the matrix elements. We can replace the matrix elements with submatrices, so that every processor processes more values. The scalar multiplication and addition become sequential matrix multiplication and addition. The width and height of the submatrices will be N=n/p. The runtime of the algorithm is T(𝓃,𝓅)=Tcoll(n/N,p)+N∗Tseq(n/N)+2(N−1)(Tstart+Tbyte(n/N)2) , where Tcoll is the time of the initial distribution of the matrices in the first step, Tseq is the calculation of the intermediate results and Tstart and Tbyte stands for the time it takes to establish a connection and transmission of byte respectively. A disadvantage of the algorithm is that there are many connection setups, with small message sizes. It would be better to be able to transmit more data in each message.

See also Systolic array

References

External links

Worked examples

Example 1 — a first encounter with Cannon's algorithm

Start with the simplest possible case. Write down what Cannon's algorithm 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 Cannon's algorithm 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 Cannon's algorithm 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 Cannon's algorithm

In research
Cannon's algorithm 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 Cannon's algorithm 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
Cannon's algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Distributed algorithms, Matrix multiplication algorithms, Mesh networking, so understanding it makes those chapters shorter.
In everyday life
Look for Cannon's algorithm 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 “Cannon's algorithm” →

How to study Cannon's algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Cannon's algorithm 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 Cannon's algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Cannon's algorithm in simple terms?

In computer science, Cannon's algorithm is a distributed algorithm for matrix multiplication for two-dimensional meshes first described in 1969 by Lynn Elliot Cannon. It is especially suitable for computers laid out in an N × N mesh.

Why does Cannon's algorithm 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 Cannon's algorithm?

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 Cannon's algorithm.

Tags

  • Distributed algorithms
  • Matrix multiplication algorithms
  • Mesh networking

Keep exploring