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.

• A field with value type is assigned by copying, and thus has the sharedness of the containing object or closure.<br />

Publishing can be expensive, particularly if the structure being broadcast is large and heavily nested; this can cause an<br />

apparently short atomic expression (a single write, say) to run arbitrarily long. To avoid this, the library programmer<br />

can request that an object be published by calling the semantically transparent function shared :<br />

x := shared Cons(x,xs)<br />

shared(y)<br />

A local copy of an object can be obtained by calling copy , a method on trait Object:<br />

localVar := sharedVar.copy()<br />

Two additional methods are provided which permit different choices of program behavior based on the sharedness of<br />

objects:<br />

• <strong>The</strong> getter o.isShared returns true when o is shared, and false when it is local. This permits the program to<br />

take different actions based on sharedness.<br />

• Method o.localize() is equivalent to the following expression:<br />

if o.isShared then o.copy() else o end<br />

<strong>The</strong>se methods must be used with extreme caution. For example, localize should be used only when there is a unique<br />

reference to the object being localized. <strong>The</strong> localize method can have unexpected behavior if there is a reference to o<br />

from another local object p . Updates to o will be visible through p ; subsequent publication of p will publish o . By<br />

contrast, if o was already shared, and referred to by another shared object, the newly-localized copy will be entirely<br />

distinct; changes to the copy will not be visible through p , and publishing p will not affect the locality of the copy.<br />

32.5 Distributions<br />

Most of the heavy lifting in mapping threads and arrays to regions is performed by distributions. An instance of the<br />

trait Distribution describes the parallel structure of ranges and other numeric generators (such as the generators for<br />

the index space of an array), and provides for the allocation and distribution of arrays on the machine:<br />

trait Distribution extends Object<br />

distributeT extends ArrayIndex(RangeT) :RangeT<br />

distributeE, B extends ArrayIndex(a :ArrayE, B) :ArrayE, B =<br />

distributeFromToE, B(a, a.distribution,self)<br />

end<br />

Abstractly, a Distribution acts as a transducer for generators and arrays. <strong>The</strong> distribute method applied to a multidimensional<br />

Range organizes its indices into the leaves of a tree whose inner nodes correspond to potential levels<br />

of parallelism and locality in the underlying computation, producing a fresh Range whose behavior as a Generator<br />

may differ from that of the passed-in Range. <strong>The</strong> distribute method applied to an array creates a copy of that<br />

array distributed according to the given distribution. This is specified in terms of a call to the overloaded function<br />

distributeFromTo . This permits the definition of specialized versions of this function for particular pairs of distributions.<br />

<strong>The</strong> intention of distributions is to separate the task of data distribution and program correctness. That is, it should be<br />

possible to write and debug a perfectly acceptable parallel program using only the default data distribution provided<br />

by the system. Imposing a distribution on particular computations, or designing and implementing distributions from<br />

scratch, is a task best left for performance tuning, and one which should not affect the correctness of a working<br />

program.<br />

218

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

Saved successfully!

Ooh no, something went wrong!