SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
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

Más contenido relacionado

Similar a GPars: Parallelism the Right Way

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 2011Russel Winder
 
Dataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel WinderDataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel Winderploibl
 
Dataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel WinderDataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel WinderJAXLondon2014
 
Just Keep Sending The Messages
Just Keep Sending The MessagesJust Keep Sending The Messages
Just Keep Sending The MessagesRussel Winder
 
Just Keep Sending The Messages
Just Keep Sending The MessagesJust Keep Sending The Messages
Just Keep Sending The MessagesRussel Winder
 
Given Groovy Who Needs Java
Given Groovy Who Needs JavaGiven Groovy Who Needs Java
Given Groovy Who Needs JavaRussel Winder
 
Testing: Python, Java, Groovy, etc.
Testing: Python, Java, Groovy, etc.Testing: Python, Java, Groovy, etc.
Testing: Python, Java, Groovy, etc.Russel Winder
 
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 WinderJAX London
 
Just Keep Passing The Messages
Just Keep Passing The MessagesJust Keep Passing The Messages
Just Keep Passing The MessagesRussel 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 HiveYukinori Suda
 
Making Python computations fast
Making Python computations fastMaking Python computations fast
Making Python computations fastRussel Winder
 
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.Russel Winder
 
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, etcRussel Winder
 
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 RevolutionRussel Winder
 
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 AgentsPuppet
 
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.Russel Winder
 
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 WinderJAX London
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteDr Nic Williams
 
"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 ClouderaDataconomy Media
 

Similar a 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
 

Más de Russel Winder

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 JVMverseRussel Winder
 
The Case for Kotlin and Ceylon
The Case for Kotlin and CeylonThe Case for Kotlin and Ceylon
The Case for Kotlin and CeylonRussel Winder
 
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 layerRussel Winder
 
Fast Python? Don't Bother
Fast Python? Don't BotherFast Python? Don't Bother
Fast Python? Don't BotherRussel Winder
 
Tales from the Workshops
Tales from the WorkshopsTales from the Workshops
Tales from the WorkshopsRussel Winder
 
Making Computations Execute Very Quickly
Making Computations Execute Very QuicklyMaking Computations Execute Very Quickly
Making Computations Execute Very QuicklyRussel Winder
 
Spocktacular testing
Spocktacular testingSpocktacular testing
Spocktacular testingRussel Winder
 
Spocktacular Testing
Spocktacular TestingSpocktacular Testing
Spocktacular TestingRussel Winder
 
Is Groovy static or dynamic
Is Groovy static or dynamicIs Groovy static or dynamic
Is Groovy static or dynamicRussel Winder
 
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 needRussel Winder
 
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 PythonRussel Winder
 
Is Groovy as fast as Java
Is Groovy as fast as JavaIs Groovy as fast as Java
Is Groovy as fast as JavaRussel Winder
 
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 GoRussel Winder
 
Java 8: a New Beginning
Java 8: a New BeginningJava 8: a New Beginning
Java 8: a New BeginningRussel Winder
 
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 languageRussel Winder
 
GPars: Groovy Parallelism for Java
GPars: Groovy Parallelism for JavaGPars: Groovy Parallelism for Java
GPars: Groovy Parallelism for JavaRussel Winder
 
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 Russel Winder
 
Switch to Python 3…now…immediately
Switch to Python 3…now…immediatelySwitch to Python 3…now…immediately
Switch to Python 3…now…immediatelyRussel Winder
 

Más de 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
 

Último

JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
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 Ontologyjohnbeverley2021
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
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 REVIEWERMadyBayot
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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...Jeffrey Haguewood
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
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 SavingEdi Saputra
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
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 challengesrafiqahmad00786416
 

Último (20)

JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
+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...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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
 

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