This preview shows page 1-2-3-4-25-26-27-52-53-54-55 out of 55 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 55 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

FortressThis PresentationThe History of FortressBackground and StatusPhilosophyGeneral Language FeaturesReadabilityOperatorsIdentifiersMathematical SyntaxAggregate ExpressionsDimension and UnitsSome Whitespace SensitivityExample Code (Fortress)Example Code (Typeset Fortress)Object OrientedTraitsExamplesMultiple InheritanceFunctional ProgrammingFunctional ProgrammingOperator OverloadingDefining Operators(Pre/in/post)-fix OperatorsStatic ParametersStatic ParametersStatic ParametersProgramming by ContractEnsuring InvariantsProperties and TestsAPIs and ComponentsAPIs and ComponentsParallelism featuresReduction VariablesThreadsImplicit ThreadsImplicit ThreadsExplicit (spawned) ThreadsFortress’ Parallelism “Stack”RegionsArrays, Vectors, Matricesatomic ExpressionAbortable atomicObject SharednessPublishing local objectsDistributionsat ExpressionGeneratorsGeneratorsGenerated ExpressionsThe for loopDEMOsTask ParallelismTask ParallelismData ParallelismFortressKannan GoundanStephen KouFernando PereiraThis Presentation• The history of Fortress• General language features• Parallel processing features• DemonstrationTHE HISTORY OF FORTRESSPart 1Background and Status• Developed by Sun Microsystems for the DARPA high-performance computing initiative. – Didn’t make it to Phase III• Spec is at version “1.0 beta”• Still being developed as an open source project. Mailing list is active.• Implementation is weak.– Still only an unoptimized interpreter.– No static checking (undefined variables, type checking) – Many of the parallel features aren’t implemented.Philosophy• “Do for Fortran what Java did for C”• Guy Steele is one of the designers– Co-creator of Scheme, worked on Java spec– “Growing a Language” (talk at OOPSLA ’98)• Initially targeting scientific computing, but meant to be usable for anything.• Designed from scratch.GENERAL LANGUAGE FEATURESPart twoReadability• You can use tons of Unicode symbols. – Each has an ASCII equivalent.• Mathematical syntax. What you write on the blackboard works.• Minimize clutter– Don’t specify types that can be inferred.– Get rid of noisy punctuation (semicolons).• Two input modes (Unicode vs ASCII). An additional typeset output mode.Operators• The “popular” operators:• Abbreviated operators:• Short names in all caps:• Named:+ - / = < > | { }[\ \] =/= >= -> => |-> <| |> ≠ ≥ → OPLUS DOT TIMES SQCAP AND OR IN  × Identifiers• Regular:• Formatted:• Greek Letters:• Unicode Names: HEBREW_ALEF א• Blackboard Font:a zip trickOrTreat foobara zip trickOrTreat foobara3 _a a_ a_vec _a_hat a_max foo_bara3a a a â amaxfooalpha beta GAMMA DELTAαβΓ ΔMathematical Syntax"What if we tried really hard to make the mathematical parts of program look like mathematics?” - Guy L. Steele• Multiplication and exponentiation.– x2+ 3y2= 0• Operator chains: 0 ≤ i < j < 100• Reduction syntax–factorial(n)= ∏i←1…n ifactorial(n) = ∏[i←1:n] ilx^2 + 3 y^2 = 0Aggregate Expressions• Set, array, maps, lists:• Set, array, maps, lists:• Matricies:[1 00 A]1 00 A{2, 3, 5, 7}[“France” →“Paris”, “Italy”→“Rome”]〈0, 1, 1, 2, 3, 5, 8, 13〉{x2| x ← primes}[x2→ x3| x ← fibs, x < 1000]〈x(x+1)/2 | x ← 1#100 〉Dimension and Units• Numeric types can be annotated with units• Common dimensions and units are provided in fortress standard library, e.g: kg, m, s• Static safety checks• Ex.:m_ kg_ s_ micro_s_ MW_ ns_m kg s μs MW nskineticEnergy(m:R kg_, v:R m_/s_):R kg_ m_^2/s_2= (m v^2) / 2Some Whitespace Sensitivity• Whitespace must agree with precedence– Error: a+b/ c+d• Parentheses are sometimes required: A+B∨C– “+” and “∨” have no relative precedence.• Fractions: 1/2 * 1/2• Subscripting (a[m n]) vs vector multiplication: (a [m n])Example Code (Fortress)ASCII:docgit_max = 25z: Vec = 0r: Vec = xp: Vec = rrho: Elt = r^T rfor j <- seq(1:cgit_max) doq = A palpha = rho / p^T qz := z + alpha pr := r - alpha qrho0 = rhorho := r^T rbeta = rho / rho0p := r + beta pend(z, ||x – A z||)endUnicodedocgit_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)endExample Code (Typeset Fortress)enddoseqforprprrqrrzzqppAqcgitjrrEltrVecpxVecrVeczTTTβρρβρρραραραρ+====−=+===←====::::):1(:::0:00max()end/doprprrqrrpzzqppAqirprrxrzTTTβρρβραρραραρ+===−==+========00/25,10Object Oriented• Classes (declared with object)• Fields• Virtual methods• Multiple inheritance with “traits”. Like Java interfaces.Traits• Similar to Java interfaces, but…• May contain method declarations…• In addition to method definitions, but…• Do not contain fields.• Can be multiplyinherited.TCircle=hashareascaleBy…centerradiusprovidedmethodsRequired methodsExamplestrait Locgetter position() : (R, R)displace(nx:R, ny:R) : ()endtrait Geomarea() : Rdensity(unitWeight:R) = unitWeight area()endobject Circle(x:R, y:R, r:R) extends {Loc,Geom}position() = (x, y)displace(nx:R, ny:R) = do x += nx; y += ny endarea() = rr3.1416endMultiple Inheritance• Multiple inheritanceis tricky… Ex.:• Traits have the flattening property:– the semantics of a method is the same if it is implemented in a trait or in the class that extends that trait.– ambiguous calls are explicitly resolved.ObjectPersonCompanyFreeLancer+ hash()+ hash()+ hash()Functional Programming• Everything is an expression• Immutable by default– “:= ” for mutable variables• Closures– Standard library uses higher-order functions pervasivelyapplyN(add1, 4, 3)(composeN(add1, 4))(3)add1(n: Z): Z = n + 1applyN(f: Z→Z, n: N, x: Z): Z = dov: Z = xremaining: N = nwhile remaining > 0 dov := f(v)remaining -= 1endvendcomposeN(f: Z→Z, n: N): Z→Z =if (n = 0) thenfn(x: Z) ⇒ xelsebase = composeN(f, n-1)fn(x: Z) ⇒ f(base(x))endFunctional Programming• Tagged unions• Pattern matching • List comprehensionsx = 〈 2, 4, 6, 8, 10 〉x = 〈 x | x ← 1:10, iseven(x) 〉iseven(x: Z): Bool =x MOD 2 = 0trait List comprises { Cons, Nil }endobject Cons(h: Z, t: List) extendsListhead: Z = htail: List = tendobject Nil extends Listendsum(l: List) =


View Full Document

UCLA COMSCI 239 - Fortress

Download Fortress
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Fortress and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Fortress 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?