Cache-Oblivious Matrix Transposition

Divide a transpose into cache-fitting rectangles without choosing a hardware-specific tile size.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. The naive traversal gives one matrix unfavorable strides
  2. Recursion contains subproblems at many sizes

The naive traversal gives one matrix unfavorable strides

For row-major matrices, transposing by reading one whole source row writes successive elements into different output rows. A large leading dimension can put each store in another block. Traversing both matrices through rectangles keeps nearby rows and columns in the same active region. An explicit tiled implementation can pick a tile size for one level of a hierarchy.

Recursion contains subproblems at many sizes

Recursively split the longer dimension of the source rectangle, transposing each part to its corresponding destination rectangle. At a scale where source and destination subrectangles fit in cache, consecutive rows consume blocks at close to scan efficiency under the usual tall-cache assumption \(M=\Omega(B^2)\) for square dense inputs. Smaller recursive calls inherit reuse without requiring the algorithm to know that scale. This analysis uses the external-memory model. The choice of base case and copying order still affects real cache behavior beyond the idealized transfer bound.[1]

References

  1. Matteo Frigo et al., Cache-Oblivious Algorithms ↩