GPars

1,470 views
1,379 views

Published on

Slides from my session on GPars at Gr8Conf EU 2012. It was a manifesto speech for using actors, dataflow, CSP and data parallelism and avoiding all explicit locking and indeed explicit shared-memory multi-threading.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,470
On SlideShare
0
From Embeds
0
Number of Embeds
169
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

GPars

  1. 1. GParsThe concurrency and parallelism framework for Groovy and Java applications Russel Winder@russel_winder russel@winder.org.uk http://www.russel.org.uk
  2. 2. Aims and GoalsConvince people that they: – Can deal with parallelism and concurrency without fear. – Already understand GPars. – Can use GPars tonight. –…
  3. 3. …should tremble in fear at the prospect of usingshared-memory multi-threading with Java…
  4. 4. …and even with Groovy.
  5. 5. Concurrency Execution as co-routines:Sequences of code give up the execution to pass it to another coroutine.
  6. 6. More ConcurrencyConcurrency is a technique founded in a uniprocessor view of the world. Time-division multiplexing.
  7. 7. ParallelismHaving multiple executions active all at the same time.
  8. 8. Concurrency is a tool for structuring execution where a single processor is used by multiple computations. Parallelism is about making acomputation complete faster than using a single processor.
  9. 9. Squirrel behaviour emulatessynchronized software behaviour.
  10. 10. Thanks to Paul King …Who uses synchronized?
  11. 11. Thanks to Paul King … You did it wrong.
  12. 12. Small addition by me…Who uses lock objects?
  13. 13. Small addition by me…You definitely did it wrong.
  14. 14. Locks deny parallelism.
  15. 15. The whole purpose of a lock is to prevent parallelism.
  16. 16. Parallelism is performance improvement.Performance improvement requires parallelism.
  17. 17. Locks deny performance improvement.
  18. 18. Locks are needed only ifthere is mutable shared state.
  19. 19. Avoid mutable shared state.
  20. 20. Use processes and message passing.
  21. 21. Its all easier if processes are single threaded.
  22. 22. …but how…
  23. 23. Use appropriate architectural models.
  24. 24. DataflowActors Operators connected by channels with activityIndependent processes triggered by arrival ofcommunicating via data on the channels.asynchronous exchangeof messages CSP Sequential processes connected by channels using synchronous message exchange (rendezvous). 31
  25. 25. ActorsIndependent processescommunicating viaasynchronous exchangeof messages 32
  26. 26. DataflowOperators connected bychannels with activitytriggered by arrival ofdata on the channels. 33
  27. 27. CSPSequential processesconnected by channelsusing synchronous messageexchange (rendezvous). 34
  28. 28. We need examples. 35
  29. 29.  36
  30. 30. What is the Value of ?Easy, its known exactly, its  (obviously). 37
  31. 31. Its simples Александр Орлов 2009 38
  32. 32. Approximating What is its value represented as a floating point number? – We can only obtain an approximation. – A plethora of possible algorithms to choose from, a popular one is to employ the following integral equation.  1 1 =∫0 dx 4 1x 2 39
  33. 33. One Possible AlgorithmUse quadrature to estimate the value of the integral –which is the area under the curve. 4 n 1 Embarrassingly parallel. = ∑i=1 n i−0.5 2 1  n With n = 3 not much to do, but potentially lots of error. Use n = 107 or n = 109? 40
  34. 34. Commutative and Associative Because addition is commutative and associative, expression can bedecomposed into sums of partial sums. 41
  35. 35. a+b+c+d+e+f =(a+b)+(c+d)+(e+f) 42
  36. 36. Scatter – Gathermap reduce 43
  37. 37. Code… 44
  38. 38. But isnt this just data parallelism? 45
  39. 39. More code… 46
  40. 40. If you want the code, clone the Git repository:http://www.russel.org.uk/Git/Pi_Quadrature.git 47
  41. 41. Or if you just want to browse:http://www.russel.org.uk/gitweb 48
  42. 42. The Sleeping Barber Problem 49
  43. 43. The Sleeping Barber ProblemThe barbers shop has a single If the barber is cutting, a new cutting chair and a row of customer checks to see if waiting seats. there is a free waiting seat.The barber sleeps in the cutting – If there is join the chair unless trimming a queue to be customer. trimmed.Customers arrive at the shop at – If there isnt leave intervals. disgruntled.If the barber is asleep, the customer wakes the barber Problem originally due sits in the cutting chair and to Edsger Dijkstra. gets a trim. 50
  44. 44. The cutting chair. The waiting chairs. The barbers shop.A new customer enters the shop,check to see if they can go straightto the cutting chair, if not can theytake a waiting chair, if not leave. 51
  45. 45. Wikipedia article presents the classic operatingsystems approach using locks and semaphores.http://en.wikipedia.org/wiki/Sleeping_barber_problem 52
  46. 46. More code… 53
  47. 47. If you want the code, clone the Git repository:http://www.russel.org.uk/Git/SleepingBarber.git 54
  48. 48. Or if you just want to browse:http://www.russel.org.uk/gitweb 55
  49. 49. 56
  50. 50. 57
  51. 51. 58
  52. 52. 59
  53. 53. 60
  54. 54. 61
  55. 55. Squirrels deny parallelism. 62
  56. 56. Squirrels deny performance enhancement. 63
  57. 57. Dont be a squirrel. 64
  58. 58. Do not use explicit locking algorithms. 65
  59. 59. Use computational architectures that promoteparallelism and hence performance improvement: Actors Dataflow CSP Data Parallelism 66
  60. 60. Use GPars. Go on, you know you want to… 67

×