5.2. Arrays

Mathematically, an array maps domain indices to values. Usually, the domain consists of a one-dimensional integral interval or it may be a multidimensional domain. POOMA's Array container class implements this idea. Given an index, i.e., a position in an Array's Domain, it returns the associated value, either by returning a stored value or by computing it. The indices are usually integral tuples but need not be zero-based or even consist of all possible integral tuples in a multidimensional range. Using indices permits constant-time access to values although computing a particular value may require significant time.

POOMA Arrays are first-class objects so they can be used more easily than built-in C++ arrays. For example, Arrays can be used as operands and in assignment statements. The statement a = a + b; adds corresponding values of Arrays a and b, assigning the sums to the Array a. The statement treats each array as an object, rather than requiring the use of one or more loops to access individual values. Data-parallel statements such as this are further discussed in Chapter 7. Arrays also handle their own memory allocation and deallocation. For example, the Array declaration Array<2, double, Brick> a(vertDomain) creates an Array a, allocating whatever memory it needs. When a goes out of scope, it and its memory are automatically deallocated. Automatic memory allocation and deallocation also eases copying.

Individual Array values can be accessed using parentheses, not square brackets, as for C++ arrays. For example, a(3,4) yields the value at position (3,4) of a's two-dimensional domain.