Aarhus-Fortress-Parallelism-2006public

Parallel Programmingand Parallel Abstractionsin **Fortress**Guy SteeleSun Microsystems LaboratoriesOctober 2006

Parallel Programming and Parallel Abstractions in **Fortress**Copyright © 2006 Sun Microsystems, Inc. ("Sun"). All rights are reserved by Sun except as expressly stated as follows.Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted, provided thatcopies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citationon the first page. To copy otherwise, or republish, to post on servers, or to redistribute to lists, requires prior specificwritten permission of Sun.© 2006 Sun Microsystems, Inc. All rights reserved.2

Parallel Programming and Parallel Abstractions in **Fortress****Fortress**: “To Do for FortranWhat Java TM Did for C”• Catch “stupid mistakes” (like array bounds errors)• Extensive libraries (e.g., for network environment)• Security model (including type safety)• Dynamic compilation• Platform independence• Multithreading• Make programmers more productive© 2006 Sun Microsystems, Inc. All rights reserved.3

Parallel Programming and Parallel Abstractions in **Fortress**The Context of the Research• Improving programmer productivityfor scientific and engineering applications• Research funded in part by the US DARPA IPTO(Defense Advanced Research Projects AgencyInformation Processing Technology Office) throughtheir High Productivity Computing Systems program• Goal is economically viable technologies for bothgovernment and industrial applications by the year2010 and beyond• Targeted to a range of hardware, from petaflopsupercomputers to single/multiple multicore chips© 2006 Sun Microsystems, Inc. All rights reserved.4

Parallel Programming and Parallel Abstractions in **Fortress**Key Ideas• Don't build the language—grow it• Make programming notation closer to math• Ease use of parallelism© 2006 Sun Microsystems, Inc. All rights reserved.5

Parallel Programming and Parallel Abstractions in **Fortress**Growing a Language• Languages have gotten much bigger• You can’t build one all at once• Therefore it must grow over time• What happens if you design it to grow?• How does the need to grow affect the design?• Need to grow a user community, tooSee Steele, “Growing a Language” keynote talk, OOPSLA 1998;Higher-Order and Symbolic Computation 12, 221–236 (1999)© 2006 Sun Microsystems, Inc. All rights reserved.6

Parallel Programming and Parallel Abstractions in **Fortress**Interesting Language Design StrategyWherever possible,consider whether a proposed language featurecan be provided by a libraryrather than having it built into the compiler.To make this work, library designers needsubstantial control over syntax and semantics—not just the ability to code new functions or methodsinvoked by a single method call syntax foo(a,b,c).© 2006 Sun Microsystems, Inc. All rights reserved.7

Parallel Programming and Parallel Abstractions in **Fortress**Minimalist Approach• As few primitive types as possible (cf. Bacon’s Kava)> Objects with methods and fields> Binary words of many different sizes> Linear sequences (fixed length known at compile time)> Heap sequences (fixed length known at allocation time)• User-defined parameterized types• User-defined polymorphic (overloaded) operators• Aggressive type inference to reduce clutter> Many variables require no type declarations• Aggressive static and dynamic optimization© 2006 Sun Microsystems, Inc. All rights reserved.8

Parallel Programming and Parallel Abstractions in **Fortress**Types Defined by Libraries• Lists, vectors, sets, multisets, and maps> Like C Standard Template Library, but better notation〈1,2,4,3,4〉 A∪{1,2,3,4}[3 4 5]×[1 0 0]• Matrices and multidimensional arrays• Integers, floats, rationals, with physical unitsm: R Mass = 3.7 kgv: R 3 Velocity = [3.5 0 1] m/sp: R 3 Momentum = m v• Data structures may be local or distributed© 2006 Sun Microsystems, Inc. All rights reserved.9

Parallel Programming and Parallel Abstractions in **Fortress**ASCII (“Wiki-like markup”) Notation• Lists, vectors, sets, multisets, and maps> Like C Standard Template Library, but better notation A UNION {1,2,3,4}[3 4 5] CROSS [1 0 0]• Matrices and multidimensional arrays• Integers, floats, rationals, with physical unitsm: RR Mass = 3.7 kg__v: RR^3 Velocity = [3.5 0 1] m_/s__p: RR^3 Momentum = m _v• Data structures may be local or distributed© 2006 Sun Microsystems, Inc. All rights reserved.10

Parallel Programming and Parallel Abstractions in **Fortress**A Growable, Open Language• Old language design model:> Study applications> Add language features to improve application coding• Our new model:> Study applications> Study how a library can improve application coding> Add language features to improve library coding• Conjectures:> Better leverage, leading to more rapid improvement> Enables experimentation with open-source strategies© 2006 Sun Microsystems, Inc. All rights reserved.11

Parallel Programming and Parallel Abstractions in **Fortress**Replaceable Components• Avoid a monolithic “Standard Library”• Replaceable components with version control• Encourage alternate implementations> Performance choices> Test them against each other• Encourage experimentation> Framework for alternate language designs© 2006 Sun Microsystems, Inc. All rights reserved.12

Parallel Programming and Parallel Abstractions in **Fortress**Making Abstraction Efficient• We assume implementation technology thatmakes aggressive use of runtime performancemeasurement and optimization> Frequently more efficient that static optimization• Repeat the success of the Java TM Virtual Machine• Goal: programmers (especially library writers)need never fear subroutines, functions, methods,and interfaces for performance reasons• This may take years, but we’re talking 2010© 2006 Sun Microsystems, Inc. All rights reserved.13

Parallel Programming and Parallel Abstractions in **Fortress**Type System: Objects and Traits• Traits: like interfaces, but may contain code> Based on work by Schärli, Ducasse, Nierstrasz, Black, et al.• Multiple inheritance of code (but not fields)> Objects with fields are the leaves of the hierarchy• Multiple inheritance of contracts and tests> Automated unit testing• Traits and methods may be parameterized> Parameters may be types or compile-time constants• Primitive types are first-class> Booleans, integers, floats, characters are all objects© 2006 Sun Microsystems, Inc. All rights reserved.14

Parallel Programming and Parallel Abstractions in **Fortress**Sample Code: Algebraic Constraints© 2006 Sun Microsystems, Inc. All rights reserved.(This is actual **Fortress** library code.)15

Parallel Programming and Parallel Abstractions in **Fortress**Data and Control Models• Data model: shared global address space• Control model: multithreaded> Basic primitive is “spawn”> We hope application code seldom uses it• Declared distribution of data and threads> Managing aggregates integrated into type system> Policies programmed as libraries, not wired in• Transactional access to shared variables> Atomic blocks (implicit or explicit retry)> Lock-free (no blocking, no deadlock)© 2006 Sun Microsystems, Inc. All rights reserved.16

Parallel Programming and Parallel Abstractions in **Fortress**Conventional Mathematical Notation• The language of mathematics is centuries old,concise, convenient, and widely taught• Early programming languages were constrained bykeyboards and printers• Experiments in the 1960s were not portable• Now we have bitmap displays and Unicode• Still, parsing mathematical notation is a challenge> Subtle reliance on whitespace: { |x| | x ← S, 3 | x }> Semantic conventions: y = 3 x sin x cos 2 x log log x• Programming language tradition has contributions> Type theory, block structure, variable scope© 2006 Sun Microsystems, Inc. All rights reserved.17

Parallel Programming and Parallel Abstractions in **Fortress**What Syntax is Actually Wired In?• Parentheses ( ) for grouping• Comma , to separate expressions in tuples• Semicolon ; to separate statements on a line• Dot . for field and method selection• Conservative, traditional rules of precedence> A dag, not always transitive (examples: A+B>C is okay;so is B>C∨D>E; but A+B∨C needs parentheses)• Juxtaposition is a binary operator• Any other operator can be infix, prefix, and/or postfix• Many sets of brackets© 2006 Sun Microsystems, Inc. All rights reserved.18

Parallel Programming and Parallel Abstractions in **Fortress**Libraries Define . . .• Which operators have infix, prefix, postfix definitions,and what types they apply toopr -(m:Z,n:Z) = m.subtract(n)opr -(m:Z) = m.negate()opr (n:N)! = if n=0 then 1 else n·(n-1)! end• Whether a juxtaposition is meaningfulopr juxtaposition(m:Z,n:Z) = m.times(n)• What bracketing operators actually meanopr x:R = ceiling(x)opr |x:R| = if x

Parallel Programming and Parallel Abstractions in **Fortress**But Wasn’t Operator Overloadinga Disaster in C++ ?• Yes, it was> Not enough operators to go around> Failure to stick to traditional meanings• We have also been tempted and had to resist• We believe Unicode + discipline can avert disaster• We see benefits in using notations for programmingthat are also used for specification© 2006 Sun Microsystems, Inc. All rights reserved.20

Parallel Programming and Parallel Abstractions in **Fortress**Simple Example: NAS CG Kernel (ASCII)conjGrad(A: Matrix[/Float/], x: Vector[/Float/]):(Vector[/Float/], Float)cgit_max = 25z: Vector[/Float/] := 0r: Vector[/Float/] := xp: Vector[/Float/] := rrho: Float := r^T rfor j

Parallel Programming and Parallel Abstractions in **Fortress**Simple Example: NAS CG Kernel (ASCII)conjGrad[/Elt extends Number, nat N,Mat extends Matrix[/Elt,N BY N/],Vec extends Vector[/Elt,N/]/](A: Mat, x: Vec): (Vec, Elt)cgit_max = 25z: Vec := 0r: Vec := xp: Vec := rrho: Elt := r^T rfor j

Parallel Programming and Parallel Abstractions in **Fortress**Simple Example: NAS CG Kernel (Unicode)conjGrad[[Elt extends Number, nat N,Mat extends Matrix[[Elt,NN]],Vec extends Vector]](A: Mat, x: Vec): (Vec, Elt)cgit_max = 25z: Vec := 0r: Vec := xp: Vec := rρ: Elt := r^T rfor j ← seq(1:cgit_max) doq = A pα = ρ / p^T qz := z + α pr := r - α qρ₀ = ρρ := r^T rβ = ρ / ρ₀p := r + β pend(z, ‖x - A z‖)This would be considered entirelyequivalent to the previous version.You might think of this as an abbreviatedform of the ASCII version, oryou might think of the ASCII versionas a way to conveniently enter thisversion on a standard keyboard.© 2006 Sun Microsystems, Inc. All rights reserved.23

Parallel Programming and Parallel Abstractions in **Fortress**Simple Example: NAS CG KernelconjGrad 〚Elt extends Number, nat N, 〛Mat extends Matrix〚Elt, N ×N 〛 ,Vec extends Vector 〚Elt, N〛〚 〛 A :Mat, x : Vec:Vec, Eltcgit max = 25z : Vec := 0r : Vec := xp : Vec := r:Elt := r T rfor j seq1:cgit max doq = A p =p T qz := z pr := r− q 0= := r T r = 0p := r pend z , ∥x− A z∥© 2006 Sun Microsystems, Inc. All rights reserved.It's not new or surprising that codewritten in a programming languagemight be displayed in a conventionalmath-like format. The point of thisexample is how similar the code is tothe math notation: the gap betweenthe two syntaxes is relatively small.We want to see what will happen ifa principal goal of a new languagedesign is to minimize this gap.24

Parallel Programming and Parallel Abstractions in **Fortress**Comparison: NAS NPB 1 Specificationz = 0r = x = r T rp = rDO i= 1,25q = A p = / p T qz = z p 0 = r = r−q = r T r = / 0p = r pENDDOcompute residual norm explicitly: ∥r∥=∥x−A z∥z : Vec := 0r : Vec := xp : Vec := r:Elt := r T rfor j seq1:cgit max doq = A p =p T qz := z pr := r−q 0= := r T r = 0p := r pendz , ∥x−A z∥© 2006 Sun Microsystems, Inc. All rights reserved.25

Parallel Programming and Parallel Abstractions in **Fortress**Comparison: NAS NPB 2.3 Serial Codedo j=1,naa+1do j=1,lastcol-firstcol+1q(j) = 0.0d0w(j) = 0.0d0z(j) = 0.0d0enddor(j) = x(j)sum = 0.0d0p(j) = r(j)do j=1,lastcol-firstcol+1w(j) = 0.0d0sum = sum + p(j)*q(j)enddoenddosum = 0.0d0d = sumdo j=1,lastcol-firstcol+1alpha = rho / dsum = sum + r(j)*r(j)rho0 = rhoenddodo j=1,lastcol-firstcol+1rho = sumz(j) = z(j) + alpha*p(j)do cgit = 1,cgitmaxr(j) = r(j) - alpha*q(j)do j=1,lastrow-firstrow+1enddosum = 0.d0sum = 0.0d0do k=rowstr(j),rowstr(j+1)-1 do j=1,lastcol-firstcol+1sum = sum + a(k)*p(colidx(k)) sum = sum + r(j)*r(j)enddoenddow(j) = sumrho = sumenddobeta = rho / rho0do j=1,lastcol-firstcol+1do j=1,lastcol-firstcol+1q(j) = w(j)p(j) = r(j) + beta*p(j)enddoenddoenddodo j=1,lastrow-firstrow+1sum = 0.d0do k=rowstr(j),rowstr(j+1)-1sum = sum + a(k)*z(colidx(k))enddow(j) = sumenddodo j=1,lastcol-firstcol+1r(j) = w(j)enddosum = 0.0d0do j=1,lastcol-firstcol+1d = x(j) - r(j)sum = sum + d*denddod = sumrnorm = sqrt( d )© 2006 Sun Microsystems, Inc. All rights reserved.26

Parallel Programming and Parallel Abstractions in **Fortress****Parallelism** Is Not a Feature!• Parallel programming is not a goal,but a pragmatic compromise.• It would be a lot easier to program a singleprocessor chip running at 1 PHz than a millionprocessors running at 20 GHz.> We don't know how to build a 1 Phz processor.> Even if we did, someone would still want to strapa bunch of them together!• Parallel programming is difficult and error-prone.© 2006 Sun Microsystems, Inc. All rights reserved.27

Parallel Programming and Parallel Abstractions in **Fortress**QuestionsCan we encapsulate parallelism in libraries?Will this separation be effective?© 2006 Sun Microsystems, Inc. All rights reserved.28

Parallel Programming and Parallel Abstractions in **Fortress**Should **Parallelism** Be the Default?• “Loop” can be a misleading term> A set of executions of a parameterized block of code> Whether to order or parallelize those executionsshould be a separate question• **Fortress** “loops” are parallel by default> This is actually a library convention about generators> You get sequential execution by asking for it specifically© 2006 Sun Microsystems, Inc. All rights reserved.29

Parallel Programming and Parallel Abstractions in **Fortress**In **Fortress**, **Parallelism** Is the Defaultfor i←1:m, j←1:n doa[i,j] := b[i] c[j]endfor i←seq(1:m) dofor j←seq(1:n) doprint a[i,j]endendfor i←1:m, j←i:n doa[i,j] := b[i] c[j]end© 2006 Sun Microsystems, Inc. All rights reserved.1:n is a generatorseq(1:n) is a sequential generatora.indices is a generator forthe indices of the array aa.indices.rowMajor isa sequential generator of indicesfor (i,j)←a.indices do a[i,j] := b[i] c[j] endfor (i,j)←a.indices.rowMajor do print a[i,j] end• Generators (defined by libraries) manage parallelismand the assignment of threads to processors30

Parallel Programming and Parallel Abstractions in **Fortress**Generators and Reducersy = ∑[k

Parallel Programming and Parallel Abstractions in **Fortress**Kinds of Generators• Aggregates> Lists 1,2,4,3,4 and vectors [1 2 4 3 4]> Sets {1,2,3,4} and multisets {|1,2,3,4,4|}> Arrays (including multidimensional)• Ranges 1:10 and 1:99:2 and 5#20• Index sets a.indices and a.indices.rowMajor• Index-value sets of maps ht.keyValuePairs© 2006 Sun Microsystems, Inc. All rights reserved.32

Parallel Programming and Parallel Abstractions in **Fortress**Loops, Reducers, Comprehensionsfor k 1: n do print k endy= ∑ a k x kk 1:nw=∑ Sv= ∩k Sprime kz= MAX j ,k a.indicesarrayOfSets k∣a j ,k −b j ,k ∣(* same as ∑x SB={ f x , y∣ x S , y A , x≠ y}l triangle = 〈x x12 ∣ x 1:100 〉x *)© 2006 Sun Microsystems, Inc. All rights reserved.33

Parallel Programming and Parallel Abstractions in **Fortress**Loops, Reducers, Comprehensionsfor k←1:n do print i endy = ∑[k←1:n] a[k] x^kw = ∑S (* same as ∑[x←S] x *)v = ∩[k←S, prime k] arrayOfSets[k]z = MAX[(j,k)←a.indices] |a[j,k]-b[j,k]|B = { f(x,y) | x←S, y←A, x≠y }l_triangle = x(x+1)/2 | x←1:100 © 2006 Sun Microsystems, Inc. All rights reserved.34

Parallel Programming and Parallel Abstractions in **Fortress**Abstract CollectionsAggregateRangeIndex setGeneratorprotocolAbstractcollectionReductionprotocolResultAggregateRangeIndex setOptimized generator-reductionResult© 2006 Sun Microsystems, Inc. All rights reserved.35

Parallel Programming and Parallel Abstractions in **Fortress**Representation of Abstract CollectionsBinary operator ◊Leaf operator (“unit”) □Optional empty collection (“zero”) εthat is the identity for ◊◊1 ε◊◊◊4◊1 ◊◊42323© 2006 Sun Microsystems, Inc. All rights reserved.36

Parallel Programming and Parallel Abstractions in **Fortress**Algebraic Properties of ◊Associative Commutative Idempotentno no no binary treesno no yes weirdno yes no mobilesno yes yes weirdyes no no listsyes no yes weirdyes yes no multisetsyes yes yes setsThe “Boom hierarchy”© 2006 Sun Microsystems, Inc. All rights reserved.37

Parallel Programming and Parallel Abstractions in **Fortress**Associativity12◊◊◊◊ε34◊◊21◊314◊2◊3◊41These are all consideredto be equivalent.1◊◊2◊2 3◊◊34◊◊4ε© 2006 Sun Microsystems, Inc. All rights reserved.38

Parallel Programming and Parallel Abstractions in **Fortress**Catamorphism: SummationReplace ◊ □ ε with + identity 0ε◊◊1◊2◊340++1+2+3410© 2006 Sun Microsystems, Inc. All rights reserved.39

Parallel Programming and Parallel Abstractions in **Fortress**Catamorphism: ListsReplace ◊ □ ε with append – ◊append◊◊appendappend12 3 412 3 41,2,3,4© 2006 Sun Microsystems, Inc. All rights reserved.40

Parallel Programming and Parallel Abstractions in **Fortress**Catamorphism: Splicing Linked ListsReplace ◊ □ ε with conc unitList nilunitList:xx(At the end, use the left-handpointer of the final pair.)conc:a . . . d e f . . .ha . . . d e f . . .h© 2006 Sun Microsystems, Inc. All rights reserved.41

Parallel Programming and Parallel Abstractions in **Fortress**Catamorphism: LoopsReplace ◊ □ ε with seq identity () or par identity ()where seq: (),() → () and par: (),() → ()seqseqseq print 4seq print 3print 2parpar parprint 1 print 2 print 3 print 4()print 1© 2006 Sun Microsystems, Inc. All rights reserved.42

Parallel Programming and Parallel Abstractions in **Fortress**Desugaring∑[i←a,j←b,p,k←c] e becomes ∑(f) e | i←a,j←b,p,k←c becomes List(f)for i←a,j←b,p,k←c do e end becomes For(f)where f =(fn (r)=>(a).generate(r, fn (i)=>(b).generate(r, fn (j)=>(p).generate(r, fn ()=>(c).generate(r, fn (k)=>r.unit(e))))))© 2006 Sun Microsystems, Inc. All rights reserved.Note: generate method can be overloaded!43

Parallel Programming and Parallel Abstractions in **Fortress**Implementationopr ∑[\T\](f: Catamorphism[\T,T\]→T): Twhere { T extends Monoid[\T,+\] } =f(Catamorphism(fn(x,y)=> x+y, identity, 0))List[\T\](f: Catamorphism[\T,List[\T\]\]→List[\T\]): List[\T\] =f(Catamorphism(append, fn(x)=> x, ))List[\T\](f: Catamorphism[\T,List[\T\]\]→List[\T\]): List[\T\] =f(Catamorphism(conc, unitList, nil)).firstFor(f: Catamorphism[\(),()]→()): () =f(Catamorphism(par, identity, ()))© 2006 Sun Microsystems, Inc. All rights reserved.44

Parallel Programming and Parallel Abstractions in **Fortress**Regions• Hierarchical data structure describes CPU andmemory resources and their properties> Allocation heaps> **Parallelism**Cluster> Memory coherence• A running thread can Node Node Nodefind out its resources• Threads may beChip Chipexplicitly spawnedin specified regionsCoreCoreChipNode© 2006 Sun Microsystems, Inc. All rights reserved.45

Parallel Programming and Parallel Abstractions in **Fortress**Distributions• Describe how to map a data structure onto a region> Block, cyclic, block-cyclic, Morton order ...> Map an array into a chip? Use a local heap.> Map an array onto a cluster? Break it up.1234 75 86 9101112• Defined entirely by libraries!> User-extensible© 2006 Sun Microsystems, Inc. All rights reserved.46

Parallel Programming and Parallel Abstractions in **Fortress**Generators Drive **Parallelism**1234 75 86 9101112parparparWhen a data structure(or its index set) isused as a generator,the parallelism of thegenerator reflectsthe distribution ofthe data structure.seq seq seq seqseq 3 seq 6 seq 9 seq 12seq 2 seq 5 seq 8 seq 11ε1ε4ε7ε10© 2006 Sun Microsystems, Inc. All rights reserved.47

Parallel Programming and Parallel Abstractions in **Fortress**Generators Modify Reducers:**Parallelism**123A4 75 86 9101112 +par∑A+par+parThis works because integeraddition is associative.The generator knows thisbecause the trait Zextends the traitAssociative[[Z,+]]. 0+seq+seq1+seq230+seq+seq4+seq560+seq+seq7+seq890+seq+seq+seq101112© 2006 Sun Microsystems, Inc. All rights reserved.48

Parallel Programming and Parallel Abstractions in **Fortress**Generators Modify Reducers:DistributionA1234 75 86 9Generators and reducers mayagree to use a specializedprotocol that, for example,communicates array shapesand distribution information.101112[ x(x+1)/2 | x←A ]136101521283645556678© 2006 Sun Microsystems, Inc. All rights reserved.49

Parallel Programming and Parallel Abstractions in **Fortress**More Desugaring[ e | i←a,j←b,p,k←c ][d] becomes Array(f,d)[ e | i←a,j←b,p,k←c ]^C becomes C(f)[ e | i←a,j←b,p,k←c ]^C[d] becomes C(f,d)This lets us specify a distribution explicitly as a subscript,and/or a type constructor/catamorphism as a superscript.[ x x1/2∣ x ←1:n ] blockCyclic4[ x ∣ x0 ] Maybe© 2006 Sun Microsystems, Inc. All rights reserved.50

Parallel Programming and Parallel Abstractions in **Fortress**Example: Lexicographic Comparison• Assume a binary CMP operator that returns one ofLess, Equal, or Greater• Now consider the binary operator LEXICO:LEXICO Less Equal GreaterLess Less Less LessEqual Less Equal GreaterGreater Greater Greater Greater> Associative (but not commutative)> Equal is the identity> Less and Greater are left zeroes© 2006 Sun Microsystems, Inc. All rights reserved.51

Parallel Programming and Parallel Abstractions in **Fortress**Algebraic Properties of LEXICOtrait Comparison extends {}...IdentityEquality[[Comparison]],Associative[[Comparison,LEXICO]],HasRightIdentity[[Comparison,LEXICO,Equal]],HasLeftZeroes[[Comparison,LEXICO]]test { Less, Equal, Greater }endA generator that detects the LEXICO catamorphism (rather, thefact that it has left zeros) can choose to generate special code.© 2006 Sun Microsystems, Inc. All rights reserved.52

Parallel Programming and Parallel Abstractions in **Fortress**Zeroes Can Stop Iteration EarlyDONE!×××7×0×34LEXICODONE!LEXICO LessLEXICO EqualLEXICO GreaterLEXICO Equal1 2EqualEqual© 2006 Sun Microsystems, Inc. All rights reserved.53

Parallel Programming and Parallel Abstractions in **Fortress**Code for Lexicographic Comparisontrait LexOrder[[T,E]]extends { TotalOrder[[T,≤,CMP]],Indexable[[LexOrder[[T,E]],E]] }where { T extends LexOrder[[T,E]],E extends TotalOrder[[T,≤,CMP]] }endopr =(self,other:T):Boolean =|self| = |other| AND:AND[i←self.indices] self[i]=other[i]opr CMP(self,other:T):Comparison = doprefix = self.indices ∩ other.indices(LEXICO[i←prefix] self[i] CMP other[i]) &LEXICO (|self| CMP |other|)endopr ≤(self,other:T):Boolean =(self CMP other) ≠ Greater© 2006 Sun Microsystems, Inc. All rights reserved.54

Parallel Programming and Parallel Abstractions in **Fortress**String Comparisontrait Stringextends { LexOrder[[String,Character]], ... }...test { “foo”, “foobar”, “quux”, “” }property “” < “foo” < “foobar”end© 2006 Sun Microsystems, Inc. All rights reserved.55

Parallel Programming and Parallel Abstractions in **Fortress**Summary: **Parallelism** in **Fortress**• Regions describe machine resources.• Distributions map aggregates onto regions.• Aggregates used as generators drive parallelism.• Algebraic properties drive implementation strategies.• Algebraic properties are described by traits.• Properties are verified by automated unit testing.• Traits allow sharing of code, properties, and test data.• Reducers and generators negotiate throughoverloaded method dispatch keyed by traitsto achieve mix-and-match code selection.© 2006 Sun Microsystems, Inc. All rights reserved.56

guy.steele@sun.comhttp://research.sun.com/projects/plrgCarl Eastlund, Guy Steele, Jan-Willem Maessen, Yossi Lev, Eric Allen,Joe Hallett, Sukyoung Ryu, Sam Tobin-Hochstadt, David Chase, João Dias