If an array appearing in a overall construct has ghost regions, the subscripts of the array may be shifted by some amount without violating the restriction that all array element accesses are local. In ad++ this can be expressed by an idiom like
Array1<float> b(x), c(x) ; Index i(x) ; OVERALL(i) { b(i) = c(i + 1) + c(i - 1) ; } ALLOVER(i) ;
This assumes that the array c has ghost regions of extent one or more on both sides of its ``physical'' segments. The particular usage illustrated here is very useful in ``stencil'' computations. The addition and subtraction operators must be overloaded on the Location class to support this usage.
For definiteness, the translation scheme in figure 7.15 uses the blocksIndex-based style of translation, but the same techniques can be carried over directly to the recursive style.
A subtle point to note in the definition of the overloaded + and - operators is that the shift amount is measured relative to the underlying template range. This is slightly inconvenient if the array range has a non-trivial alignment stride. Because this is assumed to be unusual in typical stencil updates, and because alternatives that automatically take account of the alignment stride add complexity, the current definition of the shift was adopted as a pragmatic compromise. The problem can be overcome by using the str inquiry, if necessary. If x (ie, c.rng()) may have a non-unit alignment stride, the assignment in the fragment above should be replaced by
b(i) = c(i + x.str()) + c(i - x.str()) ;
Figure 7.15: Translation of (constant) shifted offset
computation.