SlideShare une entreprise Scribd logo
1  sur  14
Télécharger pour lire hors ligne
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

Contenu connexe

Similaire à 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
 
Just Keep Passing The Messages
Just Keep Passing The MessagesJust Keep Passing The Messages
Just Keep Passing The MessagesRussel 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
 
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
 

Similaire à 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.
 
Just Keep Passing The Messages
Just Keep Passing The MessagesJust Keep Passing The Messages
Just Keep Passing The Messages
 
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
 
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
 

Plus 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
 

Plus 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
 

Dernier

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Dernier (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

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