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.

v = spawn at a.region(i) do<br />

a i<br />

end<br />

w = spawn at v.region() do<br />

v.val() · 17<br />

end<br />

Finally, note that it is possible to use an at expression within a block:<br />

do<br />

v := a i<br />

at a.region(j) do<br />

w := a j<br />

end<br />

x = v + w<br />

end<br />

We can think of this as the degenerate case of also do : a thread group is created with a single implicit thread running<br />

the contents of the at expression in the given region; when this thread completes control returns to the original<br />

location.<br />

Note that the regions given in an at expression are non-binding: the <strong>Fortress</strong> implementation may choose to run the<br />

computations elsewhere—for example, thread migration might not be possible within an atomic expression, or load<br />

balancing might cause code to be executed in a different region. In general, however, implementations should attempt<br />

to respect thread placement annotations when they are given.<br />

32.8 Use and Definition of Generators<br />

Several expressions in <strong>Fortress</strong> make use of generator lists (given by the nonterminal GeneratorList in the <strong>Fortress</strong><br />

grammar defined in Appendix G) to express parallel iteration (see Section 13.17). A generator list binds a series of<br />

variables to the values produced by a series of objects with the Generator trait. A generator list is simply syntactic<br />

sugar for a nested series of invocations of methods on these objects. All the parallelism provided by a particular<br />

generator is specified by its definitions for the methods of the Generator trait. In general, the library code for a<br />

generator dictates the parallel structure of computations involving that generator.<br />

<strong>The</strong> definition of trait Generator has very simple functionality at its core:<br />

trait Generator E <br />

size : Z64<br />

generate R extends Monoid R, ⊕ ,opr ⊕ (body : E → R) : R<br />

join N (other : Generator N ) : Generator (E, N) =<br />

SimplePairGenerator E, N (self,other)<br />

end<br />

<strong>The</strong> mechanics of object generation are embedded entirely in the generate method. This method takes one argument,<br />

the body function. <strong>The</strong> generate method invokes body once for each object which is to be generated, passing the<br />

generated object as an argument. Note that body returns a value in some Monoid R; the results of the calls to body<br />

are combined using the monoid operator ⊕ . This reduction may include any number of occurrences of the identity<br />

of the monoid—in particular, a generator may generate no elements, in which case it will never invoke body and will<br />

simply the identity.<br />

A simple definition of a Generator need only define the size field and the generate method:<br />

221

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

Saved successfully!

Ooh no, something went wrong!