Arranging program statements for locality on the basis of neighbourhood preferences

Abstract The gradual property of computer programs, that their successive operations preferably access data from the same memory block, is called locality. The paper deals with locality optimization, more specifically with the sequencing aspect that N operations are to be brought into sequence such that locality is maximized. We assume to be given a matrix D = [Dij] of neighbourhood preferences, where entry Dij is the smaller the higher the expected gain in locality when arranging operations oi and oj closely. The gain is supposed to have been estimated from so far accumulated but still incomplete knowledge of an overall locality optimization process. Our task consists in finding a sequencing function T : {o 1 … o N } → [l … N] ⊆ R that assigns to each operation a real time at which it will be approximately carried out. The motivation for T mapping into reals instead of integers is to transfer more knowledge on the certainty of operation ordering decisions into the next step of the overall locality optimization process. The goal for T consists in minimizing an objective function that was empirically designed to approximately quantify the intuitive meaning of the degree of locality. In addition, T has to spread the values T(oi) quite evenly over the interval [l … N]. We suggest a heuristic algorithm that approximately solves the problem, and report on experiments with the algorithm and several variants of it. Briefly, the algorithm starts with a random sequencing that is iteratively improved, by alternatingly moving each T(oi) in the direction of the value that minimizes the objective function for fixed T(oj)(j ≠ i), and spreading the T(oi) over [l … N]. Experimental results indicate that our algorithm is efficient and reasonably accurate.