19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>The</strong> body of each iteration is run in its own implicit thread. <strong>The</strong> expressions in the generator list can each be considered<br />

to run in a separate implicit thread. Together these implicit threads form a thread group.<br />

Some common Generators include:<br />

l : u<br />

Any range expression<br />

a.indices <strong>The</strong> index set of an array a<br />

{0, 1, 2, 3} <strong>The</strong> elements of an aggregate expression<br />

sequential(g) A sequential version of generator g<br />

<strong>The</strong> generator sequential(g) forces the iterations using distinct values from g to be performed in order. Every<br />

generator has an associated natural order which is the order obtained by sequential . For example, a sequential for<br />

loop starting at 1 and going to n can be written as follows:<br />

for i ← sequential(1 :n) do<br />

· · ·<br />

end<br />

Given a multidimensional array, the indices generator returns a tuple of values, which can be bound by a tuple of<br />

variables to the left of the arrow:<br />

(i, j) ← my2DArray.indices<br />

<strong>The</strong> parallelism of a loop on this generator follows the spatial distribution (discussed in Section 32.5) of my2DArray<br />

as closely as possible.<br />

<strong>The</strong> order of nesting of generators need not imply anything about the relative order of nesting of iterations. In most<br />

cases, multiple generators can be considered equivalent to multiple nested loops. However, the compiler will make an<br />

effort to choose the best possible iteration order it can for a multiple-generator loop; there may be no such guarantee for<br />

nested loops. Thus loops with multiple generators are preferable in general. Note that the early termination behavior<br />

of nested looping is subtly different from a single multi-generator loop; see Section 32.6.<br />

13.18 Summations and Other Reduction Expressions<br />

Syntax:<br />

Flow ::= Accumulator<br />

∑ ∏<br />

[[ GeneratorList ]] Expr<br />

Accumulator ::= | | BIG Op<br />

A reduction expression begins with a big operator such as ∑ or ∏ followed by an optional generator list (described<br />

in Section 13.17), followed by a subexpression. A complete list of these operators are described in Section 16.8.1.<br />

When a generator list is provided, generators produce values and bind the values to the identifiers that are used in the<br />

subexpression. Most generators, unlike the sequential generator, may execute each evaluation of the subexpression<br />

in a separate implicit thread. <strong>The</strong> value of a reduction expression is the result of the operation over the values of the<br />

subexpressions. <strong>The</strong> type of a reduction expression is the return type of the big operator used.<br />

A reduction expression with a generator list:<br />

∑ [v1 ← g 1 , v 2 ← g 2 , . . .]e<br />

is equivalent to the following code:<br />

do<br />

result = 0<br />

for v 1 ← g 1 ,v 2 ← g 2 , . . . do<br />

result += e<br />

end<br />

103

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!