The coolest bits
Why bother!?
GPars 
Groovy Parallel Systems 
- multiple high-level parallelism abstractions 
- Java-usable 
- GAE-usable 
- part of Groovy SDK 
- open source (Apache 2 License) 
- Grooovy documentation
GPars 
Groovy Parallel Systems 
Team: 
Václav Pech, Dierk König, Russel Winder, 
Alex Tkachman, Paul King, Jon Kerridge, 
Rafał Sławik and others
One Ring to rule them all... 
Parallelism approach in GPars (originally?) found in implemented using 
Parallel collections Scala, Java jsr-166y / JDK5 executors 
jsr-166y Fork/Join (sugar) Java jsr-166y 
Actors Erlang, Scala java.util.concurrent 
Software Transactional Memory Clojure, Scala Multiverse 
Agents Clojure java.util.concurrent 
CSP CSP :) Dataflow* or JCSP 
Dataflow and extensions: 
Linda, Verilog, Agilent Vee, 
Pipelines, Kanbanflow 
Scala, Unreal Engine 
jsr-166y / JDK5 executors (?) 
Composable asynchronous functions ? jsr-166y / JDK5 executors
Our focus 
Parallelism approach in GPars (originally?) found in implemented using 
Parallel collections Scala, Java jsr-166y / JDK5 executors 
jsr-166y Fork/Join (sugar) Java jsr-166y 
Actors Erlang, Scala java.util.concurrent 
Software Transactional Memory Clojure, Scala Multiverse 
Agents Clojure java.util.concurrent 
CSP CSP :) Dataflow* or JCSP 
Dataflow and extensions: 
Linda, Verilog, Agilent Vee, 
jsr-166y / JDK5 executors 
Pipelines, Kanbanflow 
Scala, Unreal Engine 
(?) 
Composable asynchronous functions ? jsr-166y / JDK5 executors
Demo time! 
Enabling GPars GDSL in Intellij IDEA
Demo time! 
Parallel collections 
- withPool / enhancer 
- makeConcurrent / makeSequential / 
asParallel 
- GParsPool + ParallelEnhancer / 
GParsExecutorsPool + 
GParsExecutorsPoolEnhancer 
- Map-Reduce (Fork / Join pool only)
Things to consider / a warning... 
In this approach, your iteration body must be: 
- stateless 
- side-effect free 
- constrained to the current element 
Else - welcome to concurrency hell...
Demo time! 
Agents 
- updating immutable / mutable 
- syntax equivalents for .send 
- copy method 
- parallel behaviour 
- error handling 
- parallel groups, daemon threads  shutting 
down
Agents - what else is there 
- listeners 
- validators  validation gotchas 
- non-closure sends 
- prefer composition over inheritance 
- sendAndAwait
Agents - Q  A 
Questions? 
- what if I want to check a condition 
before updating state? 
- how do I 'lock' the state?
Demo time! 
Composable Asynchronous Functions 
- @AsyncFun / asyncFun() 
- async funs return DataflowVariable-s 
- blocking @AsyncFun-s for convenience 
- rest of the docs: instantiation variants, 
pool configuration
Bonus: on parallelism 
flavours
Choosing an approach 
Task parallelism 
Independent Async closures, Futures, whatever... 
Dependent Random / Unknown Dataflow 
Functional / Linear Composable asynchronous functions, 
Dataflow tasks, CSP 
Hierarchical / Recursive Fork / Join 
Shared state Agents, STM
Choosing an approach 
Data parallelism 
Geometrical / Linear Parallel collections 
Hierarchical / Recursive Fork / Join 
Streamed (regular) Pipeline DSL, Dataflow, CSP 
Event-driven (irregular) Actors
From GPARS User Guide
TL;DR 
Parallel collections 
Async functions 
Dataflow 
Agents 
Message passing 
- CSP 
- Dataflow 
- Actors
Also: Bashing actors a little :) 
Actors are overrated 
Dierk König
Also: Bashing actors a little :) 
Why there were no Actors in Clojure* 
● complex 
● no efficient sharing even for immutable structures 
● reduce flexibility 
● do not really distribute well from single to many 
machines 
* a purposefully exaggerating summary by me
Slides since Morpheus based on 
● Václav Pech - GPars How To Guide 
● Paul King - Concurrency with GPars 
● GPars User Guide - Applicability of concepts 
● GPars docs - Concepts compared 
● Dierk König - Concurrent programming for you and me 
● my personal biases :)
Recap 
- GPars is quite a lib :) 
- Be sure to try Dataflows 
- Actors are overrated ;)
Questions?
Thank you!

Gpars - the coolest bits

  • 1.
  • 2.
  • 3.
    GPars Groovy ParallelSystems - multiple high-level parallelism abstractions - Java-usable - GAE-usable - part of Groovy SDK - open source (Apache 2 License) - Grooovy documentation
  • 4.
    GPars Groovy ParallelSystems Team: Václav Pech, Dierk König, Russel Winder, Alex Tkachman, Paul King, Jon Kerridge, Rafał Sławik and others
  • 5.
    One Ring torule them all... Parallelism approach in GPars (originally?) found in implemented using Parallel collections Scala, Java jsr-166y / JDK5 executors jsr-166y Fork/Join (sugar) Java jsr-166y Actors Erlang, Scala java.util.concurrent Software Transactional Memory Clojure, Scala Multiverse Agents Clojure java.util.concurrent CSP CSP :) Dataflow* or JCSP Dataflow and extensions: Linda, Verilog, Agilent Vee, Pipelines, Kanbanflow Scala, Unreal Engine jsr-166y / JDK5 executors (?) Composable asynchronous functions ? jsr-166y / JDK5 executors
  • 7.
    Our focus Parallelismapproach in GPars (originally?) found in implemented using Parallel collections Scala, Java jsr-166y / JDK5 executors jsr-166y Fork/Join (sugar) Java jsr-166y Actors Erlang, Scala java.util.concurrent Software Transactional Memory Clojure, Scala Multiverse Agents Clojure java.util.concurrent CSP CSP :) Dataflow* or JCSP Dataflow and extensions: Linda, Verilog, Agilent Vee, jsr-166y / JDK5 executors Pipelines, Kanbanflow Scala, Unreal Engine (?) Composable asynchronous functions ? jsr-166y / JDK5 executors
  • 8.
    Demo time! EnablingGPars GDSL in Intellij IDEA
  • 9.
    Demo time! Parallelcollections - withPool / enhancer - makeConcurrent / makeSequential / asParallel - GParsPool + ParallelEnhancer / GParsExecutorsPool + GParsExecutorsPoolEnhancer - Map-Reduce (Fork / Join pool only)
  • 10.
    Things to consider/ a warning... In this approach, your iteration body must be: - stateless - side-effect free - constrained to the current element Else - welcome to concurrency hell...
  • 11.
    Demo time! Agents - updating immutable / mutable - syntax equivalents for .send - copy method - parallel behaviour - error handling - parallel groups, daemon threads shutting down
  • 12.
    Agents - whatelse is there - listeners - validators validation gotchas - non-closure sends - prefer composition over inheritance - sendAndAwait
  • 13.
    Agents - Q A Questions? - what if I want to check a condition before updating state? - how do I 'lock' the state?
  • 14.
    Demo time! ComposableAsynchronous Functions - @AsyncFun / asyncFun() - async funs return DataflowVariable-s - blocking @AsyncFun-s for convenience - rest of the docs: instantiation variants, pool configuration
  • 15.
  • 16.
    Choosing an approach Task parallelism Independent Async closures, Futures, whatever... Dependent Random / Unknown Dataflow Functional / Linear Composable asynchronous functions, Dataflow tasks, CSP Hierarchical / Recursive Fork / Join Shared state Agents, STM
  • 17.
    Choosing an approach Data parallelism Geometrical / Linear Parallel collections Hierarchical / Recursive Fork / Join Streamed (regular) Pipeline DSL, Dataflow, CSP Event-driven (irregular) Actors
  • 18.
  • 19.
    TL;DR Parallel collections Async functions Dataflow Agents Message passing - CSP - Dataflow - Actors
  • 20.
    Also: Bashing actorsa little :) Actors are overrated Dierk König
  • 21.
    Also: Bashing actorsa little :) Why there were no Actors in Clojure* ● complex ● no efficient sharing even for immutable structures ● reduce flexibility ● do not really distribute well from single to many machines * a purposefully exaggerating summary by me
  • 22.
    Slides since Morpheusbased on ● Václav Pech - GPars How To Guide ● Paul King - Concurrency with GPars ● GPars User Guide - Applicability of concepts ● GPars docs - Concepts compared ● Dierk König - Concurrent programming for you and me ● my personal biases :)
  • 23.
    Recap - GParsis quite a lib :) - Be sure to try Dataflows - Actors are overrated ;)
  • 24.
  • 25.