Академический Документы
Профессиональный Документы
Культура Документы
Agenda
Context
Improving programmer productivity for scientific and engineering applications Research funded in part by DARPA through their
Scientific-centered computation Extensive libraries (e.g., for network environment) Security model (including type safety)
Dynamic compilation
Platform independence Parallelism
Growing A Language
Main Ideas
Contracts OOP
Mathematical Syntax
Parallelism
Generators & Reducers
Transactional Memory
Contracts
Part of the function declaration Better documentation for clients Exception thrown on violation
factorial(var n:32)
requires { n 0 }
ensures { result 0, result 2 provided n 2 } invariant { n } = if n = 0 then 1 else n factorial(n-1) end
Java works around this by having single inheritance augmented by interfaces. In Fortress: Traits and Objects. Parametric polymorphism exists (not in this talk)
Traits
Like Javas interfaces Multiple inheritance tree Only methods
May suggest a concrete implementation Otherwise abstract
trait Moving extends {Tangible, Object} position() : 3 velocity() : 3 end trait Fast extends Moving velocity() = [0,0,9999999] end
Objects
Like Javas classes
object Sun extends {Moving, Stellar} temperature = 5800 Kalvin position() = [0,0,0] velocity() = [0,0,0] end
Mathematical Notation
Mathematical Notation
Kernel CG
benchmark algorithm:
A typical computation for irregular long distance
communication done in grid computing.
Mathematical Notation
do j=1,naa+1 q(j) = 0.0d0 z(j) = 0.0d0 r(j) = x(j) p(j) = r(j) w(j) = 0.0d0 enddo sum = 0.0d0 do j=1,lastcol-firstcol+1 sum = sum + r(j)*r(j) enddo rho = sum do cgit = 1,cgitmax do j=1,lastrow-firstrow+1
enddo
sum = 0.0d0 do j=1,lastcol-firstcol+1 sum = sum + r(j)*r(j) enddo rho = sum
sum = 0.d0
do k=rowstr(j),rowstr(j+1)-1 sum = sum + a(k)*p(colidx(k)) enddo w(j) = sum enddo
do j=1,lastcol-firstcol+1
q(j) = w(j) endd
Parallelism in Fortress
Parallel programming is not a goal, but a pragmatic compromise The Fortress language encourages you to be parallel and efficient Fortress tries to protect you from errors
Cant always succeed.
Explicit Parallelism
Implicit Parallelism
also do
Parallelism achieved by generator
for loops
Implicit parallel works are divided among the runtime thread pool Work is pushed onto a per thread queue.
Idle threads may steal work from the top of another thread's queue.
Generators (defined by libraries) manage parallelism and the division of tasks to threads Examples:
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 0#50 Index sets a.indices Index-value sets ht.keyValuePair
Implicit Parallelism
Work-stealing
Regions
Hierarchical data structure describes CPU and memory resources and their
properties
Allocation heaps
Parallelism
Memory coherence
All objects & threads has an interface for checking and manipulating the memory
Distributions
Write special allocation (Distribution) and iterations (Generator) functions for the arrays
Co-allocate chunks
d is the object implementing allocation (and extends Distribution)
What if we want:
the result
Reducers
Reducers
Summing up a blocked-array A:
Imagine the possibilities
Distribution
Generator
Transactional Memory
Transactional Memory
Transactional Memory
Fortress provides:
Software Transactional Memory
may have multiple threads cooperating in a single transaction.
Nested Transactions
Mixing atomic and non-atomic accesses to the same
data.
transactional memory.
Transactional Memory
All mutable values are represented by Reference Cells and may be a part of a transaction
Rollback
Collision detection
Invalidate
After these two threads run, the values of (z,w) are either (z,w) or (z+3,w+3)
Why not have per transaction read sets instead of per object read sets?
A transaction would keep track of every value it read and then prior to committing updates it would validate that the read values haven't changed.
long
Transactions: Contention
Aborting a transaction:
Revert all written variables backoff via spin and retry
Not selected for HPCS part 3 (2006) The Fortress Language Specification Version 1.0 was released (2008)
Questions?