'Understanding Spatial Locality and Temporal Locality

In this exercise, we look at memory locality properties of matrix computation. The following code is written in C, where elements within the same row are stored contiguously. Assume each word is a 32-bit integer.

int i,j,temp;
for (i=0; i<length; i++)
{
    for ( j = 0; j < length - i - 1; j++)
    {
        if (a[ j + 1 ] < a[j])
        {
            temp = a[j];
            a[j] = a [j + 1];
            a[j+1] = temp;
        }
    }
}

}

References to which variables exhibit temporal locality? References to which variables exhibit spatial locality?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source