GPars Workshop

2,127 views
2,082 views

Published on

Material for the GPars Workshop held at Greach 2013, Madrid 2012-01-26T11:45+01:00

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

No Downloads
Views
Total views
2,127
On SlideShare
0
From Embeds
0
Number of Embeds
640
Actions
Shares
0
Downloads
15
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

GPars Workshop

  1. 1. GPars Workshop Russel Winder email: russel@winder.org.uk xmpp: russel@winder.org.uk twitter: @russel_winder http://www.russel.org.ukCopyright © 2013 Russel Winder 1
  2. 2. Aims, Goals and Objectives ● Gain practical experience of the various models of concurrent and parallel behaviour available in GPars; actors, dataflow, data parallelism, etc. ● Have some fun.Copyright © 2013 Russel Winder 2
  3. 3. Subsidiary Aims, Goals and Objects ● Show that shared mutable memory multi-threading should return to being an operating systems development technique and not continue to be pushed as an applications programming technique – remember…Copyright © 2013 Russel Winder 3
  4. 4. …people should tremble in fear at the prospect of using Shared mutable memory multi-threading.Copyright © 2013 Russel Winder 4
  5. 5. Structure Introduction. Actors. Dataflow. Data Parallelism. Analysis. Closing.Copyright © 2013 Russel Winder 5
  6. 6. Protocol Short presentation. 3 (Short presentation → Practical period) Interaction. Short presentation. Questions or comments welcome at any time.Copyright © 2013 Russel Winder 6
  7. 7. Interstitial AdvertisementCopyright © 2013 Russel Winder 7
  8. 8. IntroductionCopyright © 2013 Russel Winder 8
  9. 9. It is no longer contentious that The Multicore Revolution is well underway.Copyright © 2013 Russel Winder 9
  10. 10. Quad core laptops and phones. Eight and twelve core workstations. Servers with “zillions” of cores.Copyright © 2013 Russel Winder 10
  11. 11. Parallel capable hardware is the norm.Copyright © 2013 Russel Winder 11
  12. 12. Software technology in use is now lagging hardware technology by decades.Copyright © 2013 Russel Winder 12
  13. 13. Operating systems manage cores with kernel threads. Operating systems are fundamentally shared mutable memory multi-threaded systems. Operating systems rightly use all the lock, semaphore, monitor, etc. technologies.Copyright © 2013 Russel Winder 13
  14. 14. Computationally intensive systems or subsystems definitely have to be parallel. Other systems likely use concurrency but not parallelism.Copyright © 2013 Russel Winder 14
  15. 15. Concurrency Execution as co-routines: Sequences of code give up the execution to pass it to another coroutine.Copyright © 2013 Russel Winder 15
  16. 16. More Concurrency Concurrency is a technique founded in a uniprocessor view of the world. Time-division multiplexing.Copyright © 2013 Russel Winder 16
  17. 17. Parallelism Having multiple executions active at the same time.Copyright © 2013 Russel Winder 17
  18. 18. Concurrency is a tool for structuring execution where a single processor is used by multiple computations. Parallelism is about making a computation complete faster than using a single processor.Copyright © 2013 Russel Winder 18
  19. 19. Copyright © 2013 Russel Winder 19
  20. 20. Copyright © 2013 Russel Winder 20
  21. 21. Copyright © 2013 Russel Winder 21
  22. 22. Copyright © 2013 Russel Winder 22
  23. 23. Copyright © 2013 Russel Winder 23
  24. 24. Copyright © 2013 Russel Winder 24
  25. 25. Copyright © 2013 Russel Winder 25
  26. 26. Squirrel behaviour emulates synchronized software behaviour.Copyright © 2013 Russel Winder 26
  27. 27. Locks deny parallelism.Copyright © 2013 Russel Winder 27
  28. 28. The whole purpose of a lock is to prevent parallelism.Copyright © 2013 Russel Winder 28
  29. 29. Parallelism is performance improvement. Performance improvement requires parallelism.Copyright © 2013 Russel Winder 29
  30. 30. Locks deny performance improvement.Copyright © 2013 Russel Winder 30
  31. 31. Locks are needed only if there is mutable shared state.Copyright © 2013 Russel Winder 31
  32. 32. Avoid mutable shared state.Copyright © 2013 Russel Winder 32
  33. 33. …but how…Copyright © 2013 Russel Winder 33
  34. 34. Use appropriate architectural models.Copyright © 2013 Russel Winder 34
  35. 35. Its all about controlling concurrency and parallelism with tools that applications programmers find usable.Copyright © 2013 Russel Winder 35
  36. 36. Shared mutable memory multi-threading is an operating system technique.Copyright © 2013 Russel Winder 36
  37. 37. Applications and tools programmers need computational models with integrated synchronization.Copyright © 2013 Russel Winder 37
  38. 38. Use processes and message passing.Copyright © 2013 Russel Winder 38
  39. 39. Its all easier if processes are single threaded.Copyright © 2013 Russel Winder 39
  40. 40. Dataflow Operators connected by Actors channels with activity Independent processes triggered by arrival of communicating via data on the channels. asynchronous exchange of messages. Data Parallelism Transform a sequence to another sequence where all individual actions happen at the same time.Copyright © 2013 Russel Winder 40
  41. 41. Agents A wrapper for some Active Objects shared mutable state. An object that is actually an actor but looks like a full service object. Fork/Join An toolkit for tree structured concurrency and parallelism. Software Transactional Memory Wrappers for mutable values that uses transactions rather than locks.Copyright © 2013 Russel Winder 41
  42. 42. ActorsCopyright © 2013 Russel Winder 42
  43. 43. Actors Independent processes communicating via asynchronous exchange of messagesCopyright © 2013 Russel Winder 43
  44. 44. Need an example.Copyright © 2013 Russel Winder 44
  45. 45. The Sleeping Barber ProblemCopyright © 2013 Russel Winder 45
  46. 46. The Sleeping Barber Problem ● The barbers shop has a ● If the barber is cutting, a new single cutting chair and a row customer checks to see if of waiting seats. there is a free waiting seat. ● The barber sleeps in the ● If there is join the queue cutting chair unless trimming to be trimmed. a customer. ● If there isnt leave ● Customers arrive at the shop disgruntled. at intervals. ● If the barber is asleep, the customer wakes the barber Problem originally due takes the cutting chair and to Edsgar Dijkstra. gets a trim.Copyright © 2013 Russel Winder 46
  47. 47. The cutting chair. The waiting chairs The barbers shop. A new customer enters the shop, check to see if they can go straight to the cutting chair, if not can they take a waiting chair, if not leave.Copyright © 2013 Russel Winder 47
  48. 48. Wikipedia article presents the classic operating systems approach using locks and semaphores. http://en.wikipedia.org/wiki/Sleeping_barber_problemCopyright © 2013 Russel Winder 48
  49. 49. Code!Copyright © 2013 Russel Winder 49
  50. 50. DataflowCopyright © 2013 Russel Winder 50
  51. 51. Dataflow Operators connected by channels with activity triggered by arrival of data on the channels.Copyright © 2013 Russel Winder 51
  52. 52. Code!Copyright © 2013 Russel Winder 52
  53. 53. If you want the code, clone the Git repository: http://www.russel.org.uk/Git/SleepingBarber.gitCopyright © 2013 Russel Winder 53
  54. 54. Or if you just want to browse: http://www.russel.org.uk/gitwebCopyright © 2013 Russel Winder 54
  55. 55. Data ParallelismCopyright © 2013 Russel Winder 55
  56. 56. Data Parallelism Transform a sequence to another sequence where all individual actions happen at the same time.Copyright © 2013 Russel Winder 56
  57. 57. Need an example.Copyright © 2013 Russel Winder 57
  58. 58. Copyright © 2013 Russel Winder 58
  59. 59. What is the Value of ? Easy, its known exactly. Its . Obviously.Copyright © 2013 Russel Winder 59
  60. 60. Its simples Александр Орлов 2009Copyright © 2013 Russel Winder 60
  61. 61. 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 2Copyright © 2013 Russel Winder 61
  62. 62. One Possible Algorithm ● Use quadrature to estimate the value of the integral – which is the area under the curve. 4 n 1 = ∑i=1 n i−0.5 2 Embarrassingly 1  parallel. n With n = 3 not much to do, but potentially lots of error. Use n = 107 or n = 109?Copyright © 2013 Russel Winder 62
  63. 63. Because addition is commutative and associative, expression can be decomposed into sums of partial sums.Copyright © 2013 Russel Winder 63
  64. 64. a+b+c+d+e+f = (a+b)+(c+d)+(e+f)Copyright © 2013 Russel Winder 64
  65. 65. Scatter – Gather map reduceCopyright © 2013 Russel Winder 65
  66. 66. Code!Copyright © 2013 Russel Winder 66
  67. 67. If you want the code, clone the Git repository: http://www.russel.org.uk/Git/Pi_Quadrature.gitCopyright © 2013 Russel Winder 67
  68. 68. Or if you just want to browse: http://www.russel.org.uk/gitwebCopyright © 2013 Russel Winder 68
  69. 69. An EndCopyright © 2013 Russel Winder 69
  70. 70. Multicore and multiprocessor are now the norm, not the exception.Copyright © 2013 Russel Winder 70
  71. 71. Parallelism only matters if computational performance matters.Copyright © 2013 Russel Winder 71
  72. 72. Unstructured synchronization of concurrent systems is not a feasible approach.Copyright © 2013 Russel Winder 72
  73. 73. Actors, dataflow, and data parallelism (and CSP, agents, fork/join,…) are the future of applications structure.Copyright © 2013 Russel Winder 73
  74. 74. Passing messages between processes is the way forward.Copyright © 2013 Russel Winder 74
  75. 75. Shared memory concurrency is a dead end for applications.Copyright © 2013 Russel Winder 75
  76. 76. Copyright © 2013 Russel Winder 76
  77. 77. Copyright © 2013 Russel Winder 77
  78. 78. Copyright © 2013 Russel Winder 78
  79. 79. Copyright © 2013 Russel Winder 79
  80. 80. Copyright © 2013 Russel Winder 80
  81. 81. Copyright © 2013 Russel Winder 81
  82. 82. Squirrels deny parallelism.Copyright © 2013 Russel Winder 82
  83. 83. Squirrels deny performance enhancement.Copyright © 2013 Russel Winder 83
  84. 84. Dont be a squirrel.Copyright © 2013 Russel Winder 84
  85. 85. Do not use explicit locking algorithms.Copyright © 2013 Russel Winder 85
  86. 86. Use computational architectures that promote parallelism and hence performance improvement: Actors Dataflow Data ParallelismCopyright © 2013 Russel Winder 86
  87. 87. Use Go on, you know you want to…Copyright © 2013 Russel Winder 87
  88. 88. Interstitial AdvertisementCopyright © 2013 Russel Winder 88
  89. 89. The EndCopyright © 2013 Russel Winder 89
  90. 90. GPars Workshop Russel Winder email: russel@winder.org.uk xmpp: russel@winder.org.uk twitter: @russel_winder website: http://www.russel.org.ukCopyright © 2013 Russel Winder 90

×