0
GPars               Parallelism the Right Way                                 Dr Russel Winder                            ...
Moores Law                       ●    More transistors.                       ●    More cores.                       ●    ...
Caveat                       ●    Not all applications require parallelism.                       ●    I/O bound best hand...
Where Parallelism Is Needed                       ●    Operating systems offer threads as access to the                   ...
Hummm...                       ●    Shared memory multithreading is hard.                       ●    Locks, semaphores, mo...
Models of Management                       ●    Actors                       ●    Dataflow                       ●    Comm...
GPars                       ●    A Groovy/Java implemented framework for easy                            expression of par...
Builds on…                       ●    GPars builds on java.util.concurrent and all the                            JSR166 g...
Usage                       ●    GPars works supremely well in Groovy scripts that                            manage Groov...
@Grab ( org.codehaus.gpars:gpars:1.0-SNAPSHOT )  import groovyx.gpars.GParsPool  void execute ( final int numberOfTasks ) ...
@Grab ( org.codehaus.gpars:gpars:1.0-SNAPSHOT )                import groovyx.gpars.ParallelEnhancer                void e...
GPars                    Check it out, you know you                              want to.                     http://gpars...
Mandatory Book Advert                       Python for Rookies                       Sarah Mount, James Shuttleworth and  ...
GPars               Parallelism the Right Way                                 Dr Russel Winder                            ...
Upcoming SlideShare
Loading in...5
×

GPars: Parallelism the Right Way

1,275

Published on

The lightning talk promoting GPars (http://gpars.codehaus.org) I gave at the LJC Unconference 2011

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,275
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "GPars: Parallelism the Right Way"

  1. 1. GPars Parallelism the Right Way Dr Russel Winder It’z Interactive Ltd russel@itzinteractive.com russel@russel.org.uk @russel_winderCopyright © 2011 Russel Winder 1
  2. 2. Moores Law ● More transistors. ● More cores. ● More parallelism. ● Ubiqitous parallelism.Copyright © 2011 Russel Winder 2
  3. 3. Caveat ● Not all applications require parallelism. ● I/O bound best handled with single threaded event loop.Copyright © 2011 Russel Winder 3
  4. 4. Where Parallelism Is Needed ● Operating systems offer threads as access to the cores. ● Languages offer threads as infrastructure.Copyright © 2011 Russel Winder 4
  5. 5. Hummm... ● Shared memory multithreading is hard. ● Locks, semaphores, monitors, …Copyright © 2011 Russel Winder 5
  6. 6. Models of Management ● Actors ● Dataflow ● Communicating Sequential Processes (CSP) ● Data parallelismCopyright © 2011 Russel Winder 6
  7. 7. GPars ● A Groovy/Java implemented framework for easy expression of parallelism. ● Offers: – Actors – Dataflow – CSP – Data parallelismCopyright © 2011 Russel Winder 7
  8. 8. Builds on… ● GPars builds on java.util.concurrent and all the JSR166 goodness.Copyright © 2011 Russel Winder 8
  9. 9. Usage ● GPars works supremely well in Groovy scripts that manage Groovy and Java classes. ● GPars works very well as a Java API.Copyright © 2011 Russel Winder 9
  10. 10. @Grab ( org.codehaus.gpars:gpars:1.0-SNAPSHOT ) import groovyx.gpars.GParsPool void execute ( final int numberOfTasks ) { GParsPool.withPool { final int n = 100000000i final double delta = 1.0d / n final startTimeNanos = System.nanoTime ( ) final int sliceSize = n / numberOfTasks final items = [ ] for ( int i in 0i ..< numberOfTasks ) { items << i } final pi = 4.0d * delta * items.collectParallel { taskId -> final int start = 1i + taskId * sliceSize final int end = ( taskId + 1i ) * sliceSize double sum = 0.0d ; for ( int i in start .. end ) { final double x = ( i - 0.5d ) * delta sum += 1.0d / ( 1.0d + x * x ) } sum }.sumParallel ( ) final elapseTime = ( System.nanoTime ( ) - startTimeNanos ) / 1e9 println ( ==== Groovy GPars GParsPool pi = + pi ) println ( ==== Groovy GPars GParsPool iteration count = + n ) println ( ==== Groovy GPars GParsPool elapse = + elapseTime ) println ( ==== Groovy GPars GParsPool processor count = + Runtime.getRuntime ( ).availableProcessors ( ) ) println ( ==== Groovy GPars GParsPool task count = + numberOfTasks ) } }Copyright © 2011 Russel Winder 10
  11. 11. @Grab ( org.codehaus.gpars:gpars:1.0-SNAPSHOT ) import groovyx.gpars.ParallelEnhancer void execute ( final int numberOfTasks ) { final int n = 100000000i final double delta = 1.0d / n final startTimeNanos = System.nanoTime ( ) final int sliceSize = n / numberOfTasks final items = [ ] for ( int i in 0i ..< numberOfTasks ) { items << i } ParallelEnhancer.enhanceInstance ( items ) final pi = 4.0d * delta * items.collectParallel { taskId -> final int start = 1i + taskId * sliceSize final int end = ( taskId + 1i ) * sliceSize double sum = 0.0d ; for ( int i in start .. end ) { final double x = ( i - 0.5d ) * delta sum += 1.0d / ( 1.0d + x * x ) } sum }.sumParallel ( ) final elapseTime = ( System.nanoTime ( ) - startTimeNanos ) / 1e9 println ( ==== Groovy GPars ParallelEnhancer pi = + pi ) println ( ==== Groovy GPars ParallelEnhancer iteration count = + n ) println ( ==== Groovy GPars ParallelEnhancer elapse = + elapseTime ) println ( ==== Groovy GPars ParallelEnhancer processor count = + Runtime.getRuntime ( ).availableProcessors ( ) ) println ( ==== Groovy GPars ParallelEnhancer task count = + numberOfTasks ) }Copyright © 2011 Russel Winder 11
  12. 12. GPars Check it out, you know you want to. http://gpars.codehaus.org/Copyright © 2011 Russel Winder 12
  13. 13. Mandatory Book Advert Python for Rookies Sarah Mount, James Shuttleworth and Russel Winder Thomson Learning Now called Cengage Learning. Developing Java Software Third Edition Russel Winder and Graham Roberts Wiley Buy these books!Copyright © 2010 Russel Winder 13
  14. 14. GPars Parallelism the Right Way Dr Russel Winder It’z Interactive Ltd russel@itzinteractive.com russel@russel.org.uk @russel_winderCopyright © 2011 Russel Winder 14
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×