SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
GPars
               Parallelism the Right Way

                                 Dr Russel Winder

                                   It’z Interactive Ltd
                                   russel@itzinteractive.com
                                   russel@russel.org.uk
                                   @russel_winder
Copyright © 2011 Russel Winder                                 1
Moore's 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 parallelism




Copyright © 2011 Russel Winder                                         6
GPars

                       ●    A Groovy/Java implemented framework for easy
                            expression of parallelism.
                       ●    Offers:
                                 –   Actors
                                 –   Dataflow
                                 –   CSP
                                 –   Data parallelism




Copyright © 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_winder
Copyright © 2011 Russel Winder                                 14

Weitere ähnliche Inhalte

Ähnlich wie GPars: Parallelism the Right Way

Just Keep Sending The Messages
Just Keep Sending The MessagesJust Keep Sending The Messages
Just Keep Sending The Messages
Russel Winder
 
Performance evaluation of cloudera impala 0.6 beta with comparison to Hive
Performance evaluation of cloudera impala 0.6 beta with comparison to HivePerformance evaluation of cloudera impala 0.6 beta with comparison to Hive
Performance evaluation of cloudera impala 0.6 beta with comparison to Hive
Yukinori Suda
 

Ähnlich wie GPars: Parallelism the Right Way (20)

Just Keep Passing the Messages from Groovy and Grails eXchange 2011
Just Keep Passing the Messages from Groovy and Grails eXchange 2011Just Keep Passing the Messages from Groovy and Grails eXchange 2011
Just Keep Passing the Messages from Groovy and Grails eXchange 2011
 
Dataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel WinderDataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel Winder
 
Dataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel WinderDataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel Winder
 
Just Keep Sending The Messages
Just Keep Sending The MessagesJust Keep Sending The Messages
Just Keep Sending The Messages
 
Just Keep Sending The Messages
Just Keep Sending The MessagesJust Keep Sending The Messages
Just Keep Sending The Messages
 
GPars Workshop
GPars WorkshopGPars Workshop
GPars Workshop
 
Given Groovy Who Needs Java
Given Groovy Who Needs JavaGiven Groovy Who Needs Java
Given Groovy Who Needs Java
 
Testing: Python, Java, Groovy, etc.
Testing: Python, Java, Groovy, etc.Testing: Python, Java, Groovy, etc.
Testing: Python, Java, Groovy, etc.
 
Java Tech & Tools | Just Keep Passing the Message | Russel Winder
Java Tech & Tools | Just Keep Passing the Message | Russel WinderJava Tech & Tools | Just Keep Passing the Message | Russel Winder
Java Tech & Tools | Just Keep Passing the Message | Russel Winder
 
Just Keep Passing The Messages
Just Keep Passing The MessagesJust Keep Passing The Messages
Just Keep Passing The Messages
 
Performance evaluation of cloudera impala 0.6 beta with comparison to Hive
Performance evaluation of cloudera impala 0.6 beta with comparison to HivePerformance evaluation of cloudera impala 0.6 beta with comparison to Hive
Performance evaluation of cloudera impala 0.6 beta with comparison to Hive
 
Making Python computations fast
Making Python computations fastMaking Python computations fast
Making Python computations fast
 
Java is dead, long live Scala, Kotlin, Ceylon, etc.
Java is dead, long live Scala, Kotlin, Ceylon, etc.Java is dead, long live Scala, Kotlin, Ceylon, etc.
Java is dead, long live Scala, Kotlin, Ceylon, etc.
 
Java is Dead, Long Live Ceylon, Kotlin, etc
Java is Dead,  Long Live Ceylon, Kotlin, etcJava is Dead,  Long Live Ceylon, Kotlin, etc
Java is Dead, Long Live Ceylon, Kotlin, etc
 
ACCU 2012: Go, D, C++ and The Multicore Revolution
ACCU 2012:  Go, D, C++ and The Multicore RevolutionACCU 2012:  Go, D, C++ and The Multicore Revolution
ACCU 2012: Go, D, C++ and The Multicore Revolution
 
Lessons I Learned While Scaling to 5000 Puppet Agents
Lessons I Learned While Scaling to 5000 Puppet AgentsLessons I Learned While Scaling to 5000 Puppet Agents
Lessons I Learned While Scaling to 5000 Puppet Agents
 
Java is dead, long live Scala Kotlin Ceylon etc.
Java is dead, long live Scala Kotlin Ceylon etc.Java is dead, long live Scala Kotlin Ceylon etc.
Java is dead, long live Scala Kotlin Ceylon etc.
 
It's all about processes communicating - Russel Winder
It's all about processes communicating - Russel WinderIt's all about processes communicating - Russel Winder
It's all about processes communicating - Russel Winder
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
"Petascale Genomics with Spark", Sean Owen,Director of Data Science at Cloudera
"Petascale Genomics with Spark", Sean Owen,Director of Data Science at Cloudera"Petascale Genomics with Spark", Sean Owen,Director of Data Science at Cloudera
"Petascale Genomics with Spark", Sean Owen,Director of Data Science at Cloudera
 

Mehr von Russel Winder

Mehr von Russel Winder (20)

On Concurrency and Parallelism in the JVMverse
On Concurrency and Parallelism in the JVMverseOn Concurrency and Parallelism in the JVMverse
On Concurrency and Parallelism in the JVMverse
 
The Case for Kotlin and Ceylon
The Case for Kotlin and CeylonThe Case for Kotlin and Ceylon
The Case for Kotlin and Ceylon
 
On the Architectures of Microservices: the next layer
On the Architectures of Microservices: the next layerOn the Architectures of Microservices: the next layer
On the Architectures of Microservices: the next layer
 
Fast Python? Don't Bother
Fast Python? Don't BotherFast Python? Don't Bother
Fast Python? Don't Bother
 
Tales from the Workshops
Tales from the WorkshopsTales from the Workshops
Tales from the Workshops
 
Making Computations Execute Very Quickly
Making Computations Execute Very QuicklyMaking Computations Execute Very Quickly
Making Computations Execute Very Quickly
 
GPars Remoting
GPars RemotingGPars Remoting
GPars Remoting
 
GPars 2014
GPars 2014GPars 2014
GPars 2014
 
Spocktacular testing
Spocktacular testingSpocktacular testing
Spocktacular testing
 
Spocktacular Testing
Spocktacular TestingSpocktacular Testing
Spocktacular Testing
 
Is Groovy static or dynamic
Is Groovy static or dynamicIs Groovy static or dynamic
Is Groovy static or dynamic
 
Dataflow: the concurrency/parallelism architecture you need
Dataflow: the concurrency/parallelism architecture you needDataflow: the concurrency/parallelism architecture you need
Dataflow: the concurrency/parallelism architecture you need
 
Are Go and D threats to Python
Are Go and D threats to PythonAre Go and D threats to Python
Are Go and D threats to Python
 
Is Groovy as fast as Java
Is Groovy as fast as JavaIs Groovy as fast as Java
Is Groovy as fast as Java
 
Who needs C++ when you have D and Go
Who needs C++ when you have D and GoWho needs C++ when you have D and Go
Who needs C++ when you have D and Go
 
Java 8: a New Beginning
Java 8: a New BeginningJava 8: a New Beginning
Java 8: a New Beginning
 
Why Go is an important programming language
Why Go is an important programming languageWhy Go is an important programming language
Why Go is an important programming language
 
GPars: Groovy Parallelism for Java
GPars: Groovy Parallelism for JavaGPars: Groovy Parallelism for Java
GPars: Groovy Parallelism for Java
 
GroovyFX: or how to program JavaFX easily
GroovyFX: or how to program JavaFX easily GroovyFX: or how to program JavaFX easily
GroovyFX: or how to program JavaFX easily
 
Switch to Python 3…now…immediately
Switch to Python 3…now…immediatelySwitch to Python 3…now…immediately
Switch to Python 3…now…immediately
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

GPars: Parallelism the Right Way

  • 1. GPars Parallelism the Right Way Dr Russel Winder It’z Interactive Ltd russel@itzinteractive.com russel@russel.org.uk @russel_winder Copyright © 2011 Russel Winder 1
  • 2. Moore's Law ● More transistors. ● More cores. ● More parallelism. ● Ubiqitous parallelism. Copyright © 2011 Russel Winder 2
  • 3. Caveat ● Not all applications require parallelism. ● I/O bound best handled with single threaded event loop. Copyright © 2011 Russel Winder 3
  • 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. Hummm... ● Shared memory multithreading is hard. ● Locks, semaphores, monitors, … Copyright © 2011 Russel Winder 5
  • 6. Models of Management ● Actors ● Dataflow ● Communicating Sequential Processes (CSP) ● Data parallelism Copyright © 2011 Russel Winder 6
  • 7. GPars ● A Groovy/Java implemented framework for easy expression of parallelism. ● Offers: – Actors – Dataflow – CSP – Data parallelism Copyright © 2011 Russel Winder 7
  • 8. Builds on… ● GPars builds on java.util.concurrent and all the JSR166 goodness. Copyright © 2011 Russel Winder 8
  • 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. @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. @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. GPars Check it out, you know you want to. http://gpars.codehaus.org/ Copyright © 2011 Russel Winder 12
  • 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. GPars Parallelism the Right Way Dr Russel Winder It’z Interactive Ltd russel@itzinteractive.com russel@russel.org.uk @russel_winder Copyright © 2011 Russel Winder 14