Cache-oblivious algorithms

Matteo Frigo, Charles E. Leiserson, Harald Prokop, Sridhar Ramachandran

2003 · 807 citations · 31 references

Concepts

TL;DR

This paper presents asymptotically optimal algorithms for rectangular matrix transpose, FFT, and sorting on computers with multiple levels of caching. The authors develop cache‑oblivious algorithms that require no hardware‑dependent tuning, achieve optimal work, and move data optimally across multiple cache levels, using an ideal‑cache model that can be efficiently simulated by LRU replacement. The algorithms attain optimal cache‑miss bounds—Θ(1+mn/L) for matrix transpose and Θ(1+(n/L)(1+log_Z n)) for FFT and sorting—and the authors prove that optimality for two‑level memory extends to multiple levels, with preliminary empirical evidence supporting practical effectiveness.

Abstract

This paper presents asymptotically optimal algorithms for rectangular matrix transpose, FFT, and sorting on computers with multiple levels of caching. Unlike previous optimal algorithms, these algorithms are cache oblivious: no variables dependent on hardware parameters, such as cache size and cache-line length, need to be tuned to achieve optimality. Nevertheless, these algorithms use an optimal amount of work and move data optimally among multiple levels of cache. For a cache with size Z and cache-line length L where Z=/spl Omega/(L/sup 2/) the number of cache misses for an m/spl times/n matrix transpose is /spl Theta/(1+mn/L). The number of cache misses for either an n-point FFT or the sorting of n numbers is /spl Theta/(1+(n/L)(1+log/sub Z/n)). We also give an /spl Theta/(mnp)-work algorithm to multiply an m/spl times/n matrix by an n/spl times/p matrix that incurs /spl Theta/(1+(mn+np+mp)/L+mnp/L/spl radic/Z) cache faults. We introduce an "ideal-cache" model to analyze our algorithms. We prove that an optimal cache-oblivious algorithm designed for two levels of memory is also optimal for multiple levels and that the assumption of optimal replacement in the ideal-cache model. Can be simulated efficiently by LRU replacement. We also provide preliminary empirical results on the effectiveness of cache-oblivious algorithms in practice.

References

31