Published on

Slides of Martin Odersky's talk at DEVOXX '11, Antwerp, Belgium, 17 Nov 2011.

Published in: Technology
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • This leads to our vision, applications driven by a set of interoperable DSLs. We are developing DSLs to provide evidence as to their effectiveness in extracting parallel performance. But we are also very interested in empowering other to easily build such DSLs, so we are investing heavily in developing frameworks and runtimes to make parallel DSL development easier. And the goal is to run single source programs on a variety of very different hardware targets.
  • Liszt is another language we have implemented. It is designed to support the creation of solvers for mesh-based partial differential equations. Problems in this domain typically simulate complex physical systems such as fluid flow or mechanics by breaking up space into discrete cells. A typical mesh may contain hundreds of millions of these cells (here we are visualizing a scram-jet designed to work at hypersonic speeds). Liszt is an ideal candidate for a DSL because while the problems are large and highly parallel, the mesh introduces many data-dependencies that are difficult to reason about, making writing solvers tedious.
  • Devoxx

    1. 1. What’s in Store for Scala? Martin Odersky DEVOXX 2011
    2. 2. What’s in Store for Scala? Martin Odersky Typesafe and EPFL
    3. 3. Scala Today
    4. 4. <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>
    5. 5. Scala 2.9: <ul><ul><li>Parallel and concurrent computing libraries </li></ul></ul><ul><ul><li>DelayedInit and App </li></ul></ul><ul><ul><li>Faster REPL </li></ul></ul><ul><ul><li>Progress on IDEs: Eclipse, IntelliJ, Neatbeans, ENSIME </li></ul></ul><ul><ul><li>Better docs </li></ul></ul>
    6. 6. Play Framework 2.0 <ul><li>Play Framework is an open source web application framework, heavily inspired by Ruby on Rails, for Java and Scala </li></ul><ul><li>Play Framework 2.0 retains full Java support while moving to a Scala core and builds on key pieces of the Typesafe Stack, including Akka middleware and SBT </li></ul><ul><li>Play will be integrated in TypeSafe stack 2.0 </li></ul><ul><li>Typesafe will contribute to development and provide commercial support and maintenance. </li></ul>
    7. 7. Scala Eclipse IDE 2.0 <ul><li>The Scala Eclipse IDE has been completely reworked. </li></ul><ul><li>First Release Candidate for IDE 2.0 is available now. </li></ul><ul><li>Goals: </li></ul><ul><li>reliable (no crashes/lock ups) </li></ul><ul><li>responsive (never wait when typing) </li></ul><ul><li>work with large projects/files </li></ul>
    8. 8. Scala 2.10: <ul><li>New reflection framework </li></ul><ul><li>Reification </li></ul><ul><li>type Dynamic </li></ul><ul><li>More IDE improvements: find-references, debugger, worksheet. </li></ul><ul><li>Faster builds </li></ul><ul><li>SIPs: string interpolation, simpler implicits. </li></ul><ul><li>ETA: Early 2012. </li></ul>
    9. 9. “ Scala” comes from “Scalable” <ul><li>Scalability: Powerful concepts that hold up from small to large </li></ul><ul><li>At JavaOne - Scala in the small: </li></ul><ul><ul><li>Winner of the Script Bowl </li></ul></ul><ul><ul><li>(Thank you, Dick!) </li></ul></ul><ul><li>This talk - Scala in the large: </li></ul><ul><ul><li>Scale to many cores </li></ul></ul><ul><ul><li>Scale to large systems </li></ul></ul>
    10. 10. Scaling to Many Cores <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 “ The free lunch is over”
    11. 11. 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>
    12. 12. 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
    13. 13. Space vs Time Time (imperative/concurrent) Space (functional/parallel)
    14. 14. Scala is a Unifier Agile, with lightweight syntax Object-Oriented Scala Functional Safe and performant, with strong static tpying
    15. 15. Scala is a Unifier Agile, with lightweight syntax Parallel Object-Oriented Scala Functional Sequential Safe and performant, with strong static tpying
    16. 16. Scala’s Toolbox
    17. 17. 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>
    18. 18. <ul><li>Let’s see an example: </li></ul>
    19. 19. 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:
    20. 20. ... 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
    21. 21. Going Parallel <ul><li>? (for now) </li></ul>... in Java: ... in Scala: val people: Array [Person] val (minors, adults) = people .par partition (_.age < 18)
    22. 22. Parallel Collections <ul><li>Use Java 7 Fork Join framework </li></ul><ul><li>Split work by number of Processors </li></ul><ul><li>Each Thread has a work queue that is split exponentially. Largest on end of queue </li></ul><ul><li>Granularity balance against scheduling overhead </li></ul><ul><li>On completion threads “work steals” from end of other thread queues </li></ul>
    23. 23. General Collection Hierarchy GenTraversable GenIterable GenSeq Traversable Iterable Seq ParIterable ParSeq
    24. 24. Going Distributed <ul><li>Can we get the power of parallel collections to work on 10’000s of computers? </li></ul><ul><li>Hot technologies: MapReduce (Google’s and Hadoop) </li></ul><ul><li>But not everything is easy to fit into that mold </li></ul><ul><li>Sometimes 100’s of map-reduce steps are needed. </li></ul><ul><li>Distributed collections retain most operations, provide a powerful frontend for MapReduce computations. </li></ul><ul><li>Scala’s uniform collection model is designed to also accommodate parallel and distributed. </li></ul><ul><li>Projects at Google (Cascade), Berkeley (Spark), EPFL. </li></ul>
    25. 25. The Future <ul><li>Scala’s persistent collections are </li></ul><ul><li>easy to use: </li></ul><ul><li>concise: </li></ul><ul><li>safe: </li></ul><ul><li>fast: </li></ul><ul><li>scalable: </li></ul><ul><li>We see them play a rapidly increasing role in software development. </li></ul>few steps to do the job one word replaces a whole loop type checker is really good at catching errors collection ops are tuned, can be parallelized one vocabulary to work on all kinds of collections: sequential, parallel, or distributed.
    26. 26. Going further: Parallel DSLs <ul><li>But how do we keep a tomorrow’s hardware loaded? </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>
    27. 27. 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.
    28. 28. 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
    29. 29. 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
    30. 30. New in Scala 2.10: Reflection <ul><li>Previously: Needed to use Java reflection, </li></ul><ul><li>no runtime info available on Scala’s types. </li></ul><ul><li>Now you can do: </li></ul>
    31. 31. (Bare-Bones) Reflection in Java Want to know whether type A conforms to B? Write your own Java compiler! Why not add some meaningful operations? Need to write essential parts of a compiler (hard). Need to ensure that both compilers agree (almost impossible).
    32. 32. How to do Better? <ul><li>Problem is managing dependencies between compiler and reflection. </li></ul><ul><li>Time to look at DI again. </li></ul>Dependency Injection <ul><li>Idea: Avoid hard dependencies to specific classes. </li></ul><ul><li>Instead of calling specific classes with new , have someone else do the wiring. </li></ul>
    33. 33. Using Guice for Dependency Injection (Example by Jan Kriesten)
    34. 34. ... plus some Boilerplate
    35. 35. Dependency Injection in Scala Components are classes or traits Requirements are abstract values Wiring by implementing requirement values But what about cyclic dependencies?
    36. 36. The Cake Pattern Requirements are types of this Components are traits Wiring by mixin composition
    37. 37. Cake Pattern in the Compiler <ul><li>The Scala compiler uses the cake pattern for everything </li></ul><ul><li>Here’s a schema: </li></ul><ul><li>(In reality there are about ~20 slices in the cake.) </li></ul>
    38. 38. Towards Better Reflection <ul><li>Can we unify the core parts of the compiler and reflection? </li></ul><ul><li>Compiler Reflection </li></ul><ul><li>Different requirements: Error diagnostics, file access, classpath handling - but we are close! </li></ul>
    39. 39. Compiler Architecture reflect.internal.Universe nsc.Global (scalac) reflect.runtime.Mirror Problem: This exposes way too much detail!
    40. 40. Complete Reflection Architecture <ul><li>Cleaned-up facade: </li></ul><ul><li>Full implementation: </li></ul>reflect.internal.Universe nsc.Global (scalac) reflect.runtime.Mirror reflect.api.Universe / reflect.mirror
    41. 41. How to Make a Facade The Facade The Implementation Interfaces are not enough!
    42. 42. Conclusion <ul><li>Scala is a very regular language when it comes to composition: </li></ul><ul><li>Everything can be nested: </li></ul><ul><ul><li>classes, methods, objects, types </li></ul></ul><ul><li>Everything can be abstract: </li></ul><ul><ul><li>methods, values, types </li></ul></ul><ul><li>The type of this can be declared freely, can thus express dependencies </li></ul><ul><li>This gives great flexibility for SW architecture, allows us to attack previously unsolvable problems. </li></ul>
    43. 43. Follow us on twitter: @typesafe <ul><li> </li></ul>