Proofs: Cannon's algorithm
These are the human proofs of Cannon's algorithm, at full length.
Cannon's schedule computes AB, and its BSP cost full
This proof shows: correctness, termination.
Let be a semiring (addition associative and commutative with a zero, multiplication associative and distributive on both sides); commutativity of the multiplication and subtraction are not used. Let . The matrix is split into blocks of size , and into blocks of size , after padding with zeros so that divides each side. All indices of blocks and processors are taken modulo , in .
Padding
Let and be and with zero rows and columns added at the bottom and right. Then the top-left block of of the size of equals , because each added row of or column of is zero, and each added column of meets an added row of , so it contributes only products with a zero factor. So it is enough to prove that the schedule computes ; from now on and denote the padded matrices.
The skew
Line L2 sends the block of to . For fixed the map is a bijection of , so each processor receives exactly one block, from , namely . In the same way line L2 sends the block of to , a bijection of the column for fixed , so receives . So after line L2, processor holds and with .
The loop
Invariant. At the start of the pass with index of line L3, for , processor holds and with , and
Initialization. For the sum is empty, which matches line L1, and the blocks are those of the skew.
Maintenance. Line L4 adds to , which extends the sum to . If , line L5 sends the block of every to and the block to . These are bijections, so receives the block of , which is , and the block of , which is . So the invariant holds at the start of pass .
End. After pass , . As runs over , runs over every residue exactly once, so, since addition is commutative and associative,
which is block of by block multiplication. In each product the block is on the left.
Termination
The loop of line L3 has passes, each local product at line L4 is a finite sequential computation, and each exchange moves a finite number of blocks. So the schedule ends after the skew and passes.
The BSP cost
Let divide the sides and , , .
- Supersteps. The skew is one superstep, and each of the passes is one (the work of L4, then the exchange of L5 if ). So .
- Work. In each pass every processor does one product of an and an block, multiplications and as many additions. Over passes this is multiplications per processor, the same on every processor.
- Communication. In the skew, each processor sends at most one block and one block and, by the bijections above, receives at most one of each. So the skew is an -relation with , with equality when , because processor then sends both of its blocks to other processors. Each exchange at line L5 with moves every block to a different processor, so . There are such exchanges. So
which is for square matrices. For nothing moves and .
The BSP cost is for matrices and processors, counting both multiplications and additions in .