Parallel operations in UC are restricted to regular data structures like arrays and are specified using the par statement. This section is a brief description of the most commonly used forms of the par statement of UC. Interested readers are referred to [Bag] for a complete description. Any HPF FORALL construct can be expressed as an equivalent UC par statement; however the latter is more general as it allows nested statements that may contain loops, conditional statements or other C and UC statements. In this chapter we restrict ourselves to the subset of UC that is semantically similar to the FORALL construct of HPF. Figure 2.1 shows a sample par statement and an equivalent HPF fragment using the FORALL construct.
Figure 2.1: Sample UC code and equivalent FORALL construct
In addition to the standard variable declarations, the fragment declares identifier I to be of type range. A range is a set of integers with constant lower and upper bounds on values of its members; the bounds are specified at the point of declaration of the range as in the preceding fragment. The declaration specifies I to be a range whose members lie in the closed interval [0, N-1], and i to be a dummy variable that is used to refer to an arbitrary element of the range.
The par statement specifies parallel execution of statements s1 followed by parallel execution of s2 where the execution is synchronized at the expression level: for each assignment statement, first evaluate the RHS for all elements of set I in arbitrary order, and then assign to the LHS for all elements of I again in arbitrary order. An optional boolean expression may be used in a par statement as a mask to exclude specific elements from the declared range, as shown in Figure 2.2.
Figure 2.2: UC code with conditional
The fragment will execute statement s1, in parallel, for even elements in range I and s2 for the others. Execution of statements s1 and s2 can be interleaved in arbitrary order; in other words, if some variable is referenced in s1 and modified in s2 (or vice versa), the result will be non-deterministic. Both the mask and the others clause are optional.
Par statements can be nested with the obvious semantics. In the
fragment shown in Figure 2.3, statement s1 is executed
for the N elements in range I and s2 is executed for
elements,
such that vector a is replicated along the columns of matrix d.
Masks may be used in either statements to restrict the range.
Figure 2.3: Nested par statements
UC also provides a set of parallel data combination operators and data distribution directives. These have been omitted for the sake of brevity.