Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Working Hard to Keep it Simple Martin Odersky Typesafe
The Challenge <ul><li>The world of mainstream software is changing: </li></ul><ul><ul><li>Moore’s law now achieved  by inc...
Concurrency and Parallelism <ul><li>Parallel  programming   Execute programs faster on   parallel hardware.  </li></ul><ul...
The Root of The Problem <ul><li>Non-determinism  caused by  concurrent threads  accessing  shared mutable  state. </li></u...
Space vs Time Time (imperative/concurrent) Space (functional/parallel)
Scala is a Unifier Agile, with lightweight syntax  Object-Oriented  Scala  Functional Safe and performant, with strong sta...
Scala is a Unifier Agile, with lightweight syntax  Parallel Object-Oriented  Scala  Functional Sequential Safe and perform...
<ul><li>Some adoption vectors: </li></ul><ul><ul><li>Web platforms </li></ul></ul><ul><ul><li>Trading platforms </li></ul>...
Scala’s Toolbox
Different Tools for Different Purposes <ul><li>Parallelism : </li></ul><ul><li>Parallel Collections </li></ul><ul><li>Coll...
<ul><li>Let’s see an example: </li></ul>
A class ... <ul><li>public   class  Person { </li></ul><ul><li>public final  String  name ; </li></ul><ul><li>public final...
... and its usage <ul><li>import  java.util.ArrayList; </li></ul><ul><li>... </li></ul><ul><li>Person[]  people ; </li></u...
Going Parallel <ul><li>? </li></ul>... in Java: ... in Scala: val  people:  Array [Person] val   (minors, adults) = people...
Actors for Concurrent Programming <ul><li>Simple message-oriented programming model for multi-threading </li></ul><ul><li>...
Going further: Parallel DSLs <ul><li>But how do we keep a bunch of Fermi’s happy? </li></ul><ul><ul><li>How to find and de...
EPFL / Stanford Research Applications Domain Specific Languages Heterogeneous Hardware DSL Infrastructure OOO Cores SIMD C...
Example: Liszt - A DSL for Physics Simulation <ul><li>Mesh-based </li></ul><ul><li>Numeric Simulation </li></ul><ul><li>Hu...
Liszt as Virtualized Scala <ul><li>val // calculating scalar convection (Liszt) </li></ul><ul><li>val Flux = new Field[Cel...
Follow us on twitter: @typesafe <ul><li>scala-lang.org </li></ul>typesafe.com
Upcoming SlideShare
Loading in …5
×

Oscon keynote: Working hard to keep it simple

44,851 views

Published on

The slides of my OSCON Java keynote, July 25, 2011

Published in: Technology

Oscon keynote: Working hard to keep it simple

  1. 1. Working Hard to Keep it Simple Martin Odersky Typesafe
  2. 2. The Challenge <ul><li>The world of mainstream software is changing: </li></ul><ul><ul><li>Moore’s law now achieved by increasing # of cores not clock cycles </li></ul></ul><ul><ul><li>Huge volume workloads that require horizontal scaling </li></ul></ul><ul><ul><li>“ PPP” Grand Challenge </li></ul></ul>Data from Kunle Olukotun, Lance Hammond, Herb Sutter, Burton Smith, Chris Batten, and Krste Asanovic
  3. 3. Concurrency and Parallelism <ul><li>Parallel programming Execute programs faster on parallel hardware. </li></ul><ul><li>Concurrent programming Manage concurrent execution threads explicitly. </li></ul><ul><li>Both are too hard! </li></ul>
  4. 4. The Root of The Problem <ul><li>Non-determinism caused by concurrent threads accessing shared mutable state. </li></ul><ul><li>It helps to encapsulate state in actors or transactions, but the fundamental problem stays the same. </li></ul><ul><li>So, non-determinism = parallel processing + mutable state </li></ul><ul><li>To get deterministic processing, avoid the mutable state! </li></ul><ul><li>Avoiding mutable state means programming functionally . </li></ul>var x = 0 async { x = x + 1 } async { x = x * 2 } // can give 0, 1, 2
  5. 5. Space vs Time Time (imperative/concurrent) Space (functional/parallel)
  6. 6. Scala is a Unifier Agile, with lightweight syntax Object-Oriented Scala Functional Safe and performant, with strong static tpying
  7. 7. Scala is a Unifier Agile, with lightweight syntax Parallel Object-Oriented Scala Functional Sequential Safe and performant, with strong static tpying
  8. 8.
  9. 9. <ul><li>Some adoption vectors: </li></ul><ul><ul><li>Web platforms </li></ul></ul><ul><ul><li>Trading platforms </li></ul></ul><ul><ul><li>Financial modeling </li></ul></ul><ul><ul><li>Simulation </li></ul></ul><ul><ul><li>Fast to first product, scalable afterwards </li></ul></ul>
  10. 10. Scala’s Toolbox
  11. 11. Different Tools for Different Purposes <ul><li>Parallelism : </li></ul><ul><li>Parallel Collections </li></ul><ul><li>Collections </li></ul><ul><li>Distributed Collections </li></ul><ul><li>Parallel DSLs </li></ul><ul><li>Concurrency : </li></ul><ul><li>Actors </li></ul><ul><li>Software transactional memory Akka </li></ul><ul><li>Futures </li></ul>
  12. 12. <ul><li>Let’s see an example: </li></ul>
  13. 13. A class ... <ul><li>public class Person { </li></ul><ul><li>public final String name ; </li></ul><ul><li>public final int age ; </li></ul><ul><li>Person(String name, int age) { </li></ul><ul><li>this . name = name; </li></ul><ul><li>this . age = age; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>class Person( val name: String, val age: Int ) ... in Java: ... in Scala:
  14. 14. ... and its usage <ul><li>import java.util.ArrayList; </li></ul><ul><li>... </li></ul><ul><li>Person[] people ; </li></ul><ul><li>Person[] minors ; </li></ul><ul><li>Person[] adults ; </li></ul><ul><li>{ ArrayList<Person> minorsList = new ArrayList<Person>(); </li></ul><ul><li>ArrayList<Person> adultsList = new ArrayList<Person>(); </li></ul><ul><li>for ( int i = 0; i < people . length ; i++) </li></ul><ul><li>( people [i]. age < 18 ? minorsList : adultsList) </li></ul><ul><li> .add( people [i]); </li></ul><ul><li>minors = minorsList.toArray( people ); </li></ul><ul><li>adults = adultsList.toArray( people ); </li></ul><ul><li>} </li></ul>... in Java: ... in Scala: val people: Array [Person] val (minors, adults) = people partition (_.age < 18) A simple pattern match An infix method call A function value
  15. 15. Going Parallel <ul><li>? </li></ul>... in Java: ... in Scala: val people: Array [Person] val (minors, adults) = people .par partition (_.age < 18)
  16. 16. Actors for Concurrent Programming <ul><li>Simple message-oriented programming model for multi-threading </li></ul><ul><li>Serializes access to shared resources using queues and function passing. </li></ul><ul><li>Easier for programmers to create reliable concurrent processing </li></ul><ul><li>Many sources of contention, races, locking and dead-locks removed </li></ul>
  17. 17. Going further: Parallel DSLs <ul><li>But how do we keep a bunch of Fermi’s happy? </li></ul><ul><ul><li>How to find and deal with 10000+ threads in an application? </li></ul></ul><ul><ul><li>Parallel collections and actors are necessary but not sufficient for this. </li></ul></ul><ul><li>Our bet for the mid term future: parallel embedded DSLs. </li></ul><ul><ul><li>Find parallelism in domains: physics simulation, machine learning, statistics, ... </li></ul></ul><ul><li>Joint work with Kunle Olukuton, Pat Hanrahan @ Stanford. </li></ul><ul><li>EPFL side funded by ERC. </li></ul>
  18. 18. EPFL / Stanford Research Applications Domain Specific Languages Heterogeneous Hardware DSL Infrastructure OOO Cores SIMD Cores Threaded Cores Specialized Cores Programmable Hierarchies Scalable Coherence Isolation & Atomicity On-chip Networks Pervasive Monitoring Domain Embedding Language ( Scala ) Virtual Worlds Personal Robotics Data informatics Scientific Engineering Physics ( Liszt ) Scripting Probabilistic (RandomT) Machine Learning ( OptiML ) Rendering Parallel Runtime ( Delite, Sequoia, GRAMPS ) Dynamic Domain Spec. Opt. Locality Aware Scheduling Staging Polymorphic Embedding Task & Data Parallelism Hardware Architecture Static Domain Specific Opt.
  19. 19. Example: Liszt - A DSL for Physics Simulation <ul><li>Mesh-based </li></ul><ul><li>Numeric Simulation </li></ul><ul><li>Huge domains </li></ul><ul><ul><li>millions of cells </li></ul></ul><ul><li>Example: Unstructured Reynolds-averaged Navier Stokes (RANS) solver </li></ul>Fuel injection Transition Thermal Turbulence Turbulence Combustion
  20. 20. Liszt as Virtualized Scala <ul><li>val // calculating scalar convection (Liszt) </li></ul><ul><li>val Flux = new Field[Cell,Float] </li></ul><ul><li>val Phi = new Field[Cell,Float] </li></ul><ul><li>val cell_volume = new Field[Cell,Float] </li></ul><ul><li>val deltat = .001 </li></ul><ul><li>... </li></ul><ul><li>untilconverged { </li></ul><ul><li>for(f <- interior_faces) { </li></ul><ul><li>val flux = calc_flux(f) </li></ul><ul><li>Flux(inside(f)) -= flux </li></ul><ul><li>Flux(outside(f)) += flux </li></ul><ul><li>} </li></ul><ul><li>for(f <- inlet_faces) { </li></ul><ul><li>Flux(outside(f)) += calc_boundary_flux(f) </li></ul><ul><li>} </li></ul><ul><li>for(c <- cells(mesh)) { </li></ul><ul><li>Phi(c) += deltat * Flux(c) /cell_volume(c) </li></ul><ul><li>} </li></ul><ul><li>for(f <- faces(mesh)) </li></ul><ul><li>Flux(f) = 0.f </li></ul><ul><li>} </li></ul>AST Hardware DSL Library Optimisers Generators … … Schedulers GPU, Multi-Core, etc
  21. 21. Follow us on twitter: @typesafe <ul><li>scala-lang.org </li></ul>typesafe.com

×