• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
GPars: Parallelism the Right Way
 

GPars: Parallelism the Right Way

on

  • 1,464 views

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

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

Statistics

Views

Total Views
1,464
Views on SlideShare
1,452
Embed Views
12

Actions

Likes
0
Downloads
19
Comments
0

1 Embed 12

http://paper.li 12

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    GPars: Parallelism the Right Way GPars: Parallelism the Right Way Presentation Transcript

    • 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
    • Moores Law ● More transistors. ● More cores. ● More parallelism. ● Ubiqitous parallelism.Copyright © 2011 Russel Winder 2
    • Caveat ● Not all applications require parallelism. ● I/O bound best handled with single threaded event loop.Copyright © 2011 Russel Winder 3
    • Where Parallelism Is Needed ● Operating systems offer threads as access to the cores. ● Languages offer threads as infrastructure.Copyright © 2011 Russel Winder 4
    • Hummm... ● Shared memory multithreading is hard. ● Locks, semaphores, monitors, …Copyright © 2011 Russel Winder 5
    • Models of Management ● Actors ● Dataflow ● Communicating Sequential Processes (CSP) ● Data parallelismCopyright © 2011 Russel Winder 6
    • GPars ● A Groovy/Java implemented framework for easy expression of parallelism. ● Offers: – Actors – Dataflow – CSP – Data parallelismCopyright © 2011 Russel Winder 7
    • Builds on… ● GPars builds on java.util.concurrent and all the JSR166 goodness.Copyright © 2011 Russel Winder 8
    • 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
    • @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
    • @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
    • GPars Check it out, you know you want to. http://gpars.codehaus.org/Copyright © 2011 Russel Winder 12
    • 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
    • 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