Download - Fortress ovo je fortress
-
7/27/2019 Fortress ovo je fortress
1/41
The Fortress Programming
LanguagePresented by Nimrod PartushBased on various presentations by the Fortress team
-
7/27/2019 Fortress ovo je fortress
2/41
Agenda
Goal & Context
Fortress motivation
Main ideas and features Focusing on parallelism
State of the art
-
7/27/2019 Fortress ovo je fortress
3/41
-
7/27/2019 Fortress ovo je fortress
4/41
The Goal of Fortress
To boldly go where no programming
language has gone before! No.
To seek out great programming language
design ideas and make them our own And let it grow
-
7/27/2019 Fortress ovo je fortress
5/41
Motivation: To Do for FortranWhat JavaTM Did for C
Catch stupid mistakes array bounds errors garbage collection
Scientific-centered computationExtensive libraries (e.g., for network environment)
Security model (including type safety)
Dynamic compilationPlatform independence
Parallelism
-
7/27/2019 Fortress ovo je fortress
6/41
Growing A Language
Wherever possible, consider whether a
proposed language feature can be
provided by a library rather than having it
wired into the compiler
-
7/27/2019 Fortress ovo je fortress
7/41
Main Ideas
Contracts
OOP
Mathematical Syntax
Parallelism Generators & Reducers
Transactional Memory
-
7/27/2019 Fortress ovo je fortress
8/41
-
7/27/2019 Fortress ovo je fortress
9/41
OOP: Objects and Traits
Multiple vs. single inheritance Single inheritance is limiting. Multiple inheritance is complicated.
Java works around this by having single
inheritance augmented by interfaces.
In Fortress: Traits and Objects.
Parametric polymorphism exists (not in this
talk)
-
7/27/2019 Fortress ovo je fortress
10/41
OOP: Objects and TraitsTraits
Like Java s interfaces
Multiple inheritance tree
Only methodsMay suggest a concrete implementation
Otherwise abstract
Objects Like Java s classes
Fields and methodsC tor arguments are implicit fields
Must implement inherited abstract methods
Leafs in the inheritance tree
In-language support for singletons
trait Moving extends {Tangible, Object} position() : 3 velocity() : 3
end
trait Fast extends Moving velocity() = [0,0,9999999]
end
object Particle( position: 3 , velocity: 3) extends Movingmass = 0 gram
end
object Sun extends {Moving, Stellar}temperature= 5800 Kalvin position() = [0,0,0] velocity() = [0,0,0]
end
-
7/27/2019 Fortress ovo je fortress
11/41
Mathematical Notation
Math is old, concise, convenient, and widely
taught
Make the programming language closer to themathematical notation What you write on your whiteboard works
Juxtaposition parsing presents an interesting research question
Implicitlyparallel
computation
-
7/27/2019 Fortress ovo je fortress
12/41
Mathematical NotationThe NAS (NASA Advanced
Supercomputing ) Kernel CG
benchmark algorithm: A typical computation for irregular long distance
communication done in grid computing.
-
7/27/2019 Fortress ovo je fortress
13/41
-
7/27/2019 Fortress ovo je fortress
14/41
Parallelism in FortressThe creators of Fortress admit to hating parallelism
Parallel programming is difficult and error -prone. (This is not aproperty of machines, but of people .)
I would be much easier if we could just make sequential execution
faster, but we can t (the power wall)
Parallel programming is not a goal, but a pragmatic
compromise
The Fortress language encourages you to be parallel andefficient
Fortress tries to protect you from errors Can t always succeed.
-
7/27/2019 Fortress ovo je fortress
15/41
Explicit Parallelism
Explicitly creating a thread to do some
computation is easy:
This is not advised.
spawn do factorial(42) end
-
7/27/2019 Fortress ovo je fortress
16/41
Implicit Parallelism
Implicitly parallel statements in Fortress: tuples
also do
for loops
Parallelismachieved bygenerator
-
7/27/2019 Fortress ovo je fortress
17/41
Implementation - Work StealingQueues
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.
Built on top of Doug Lea's jsr166y forkjoin
library.
-
7/27/2019 Fortress ovo je fortress
18/41
Generators drive parallelismGenerators (defined by libraries) manage parallelism and thedivision of tasks to threads
Examples:
AggregatesLists 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
-
7/27/2019 Fortress ovo je fortress
19/41
What s that about generators?When we execute this:
The library generator # takes over: Creates an array of indexes 1..1000 Gives each loop iteration an index for it work on Divides execution between threads
Distributed among threads work queues
-
7/27/2019 Fortress ovo je fortress
20/41
Implicit Parallelism
Work-stealing
-
7/27/2019 Fortress ovo je fortress
21/41
What About Locality?
The arrays may be spread in any manor
across the architecture:
-
7/27/2019 Fortress ovo je fortress
22/41
-
7/27/2019 Fortress ovo je fortress
23/41
-
7/27/2019 Fortress ovo je fortress
24/41
DistributionsDescribe how to map a data structure onto a region
Built-in or user-definable!
Override region() method
Some built-in distributions include: blocked(n) = Blocked, block size multiple of n ruler = Hierarchical division at powers of 2 etc.
-
7/27/2019 Fortress ovo je fortress
25/41
Smarter Parallelism with Regions
Parallel is not enough, we also want local!
Say we want to run:
What s the best way to do this? Remember, you have multiple execution units
with different memory locations
-
7/27/2019 Fortress ovo je fortress
26/41
Smarter Parallelism with RegionsWrite special allocation (Distribution) and iterations (Generator)
functions for the arrays
Co-allocate chunks
Co-locate iterations of the loop
d is the object implementing allocation (andextends Distribution)
implements iteration (andextends Generator)
-
7/27/2019 Fortress ovo je fortress
27/41
Clever Parallel Computation withReducers
Up to now we just considered sporadic
computations
What if we want: This is a reduction over an expression
For true parallelism we need to cleverly collect
the result
i 1#1000a [i] + b [i]
-
7/27/2019 Fortress ovo je fortress
28/41
Reducers
Reduction operators are managed using an
abstract collection
This translates into an actual reducer By suggesting actual operations and unit. For
example: is defined by (+,id,0)
Binary operator
Leaf operator (unit)
Optional empty collection (zero)
-
7/27/2019 Fortress ovo je fortress
29/41
Reducers
Summing up a blocked-array A:
Distribution
Generator
Imagine thepossibilities
-
7/27/2019 Fortress ovo je fortress
30/41
Example: Blocked array generator
-
7/27/2019 Fortress ovo je fortress
31/41
Transactional Memory
Programming with locks is hard, often
inefficient, and error prone.
Transactions are simple and easy to
reason about.
-
7/27/2019 Fortress ovo je fortress
32/41
Transactional Memory
The atomic keyword defines a transaction Visibility: all or nothing.
Can be aborted in mid-execution.
-
7/27/2019 Fortress ovo je fortress
33/41
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.
Built on top of Java s DSTM2 library for
transactional memory.
-
7/27/2019 Fortress ovo je fortress
34/41
Transactional MemoryAll mutable values are represented by Reference Cells
and may be a part of a transaction
Status update via compare and set
Rollback
Collision detection
Invalidate
-
7/27/2019 Fortress ovo je fortress
35/41
Example: R/W Collision
After these two threads run, the values of (z,w) are
either (z,w) or (z+3,w+3)
Thread 1
x := 0
atomic dox := 3
end
Thread 2
atomic doz += x
w += x
end
-
7/27/2019 Fortress ovo je fortress
36/41
Example: R/W CollisionThread 1
x := 0
atomic dox := 3
end
Thread 2
atomic doz += x
w += x
end
Transaction 2
Transaction 1, Status = Active
Value = 3
Old Value = 0
z = z
w = w + 3
Transaction 1, Status = Done
Need to abort atthis point!
Otherwise
Old Value = 3
-
7/27/2019 Fortress ovo je fortress
37/41
Transactions: Read Sets
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.
Validating the reads before a commit may take a
long time; we can't block other threads for that
long
-
7/27/2019 Fortress ovo je fortress
38/41
Example: W/W Collision
-
7/27/2019 Fortress ovo je fortress
39/41
Transactions: ContentionAborting a transaction:
Revert all written variables
backoff via spin and retry
All of the aborted transactions are placed in a
contention manager Transaction created by the lowest numbered thread wins.
One transaction always makes progress.
-
7/27/2019 Fortress ovo je fortress
40/41
State of the art
Not selected for HPCS part 3 (2006)
The Fortress Language Specification Version 1.0
was released (2008)
Working (partial) core implementation on top of
JVM exists With partial correctness & soundness proofs Last stable release (end of 2010)
Programmer community probably small
-
7/27/2019 Fortress ovo je fortress
41/41
Questions?