SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
Copyright © 2015 Russel Winder 1
Making Python
computations fast
Dr Russel Winder
email: russel@winder.org.uk
twitter: @russel_winder
Web: http://www.russel.org.uk
Copyright © 2015 Russel Winder 2
Presentation slots are
very short…
Copyright © 2015 Russel Winder 3
Structure
Beginning
Middle
End
Copyright © 2015 Russel Winder 4
What is the value of ?π
Copyright © 2015 Russel Winder 5
π
Copyright © 2015 Russel Winder 6
It's simples.
Александр Орлов 2009
Copyright © 2007–2015 Russel Winder 7
The Maths
The equation:
Leads to the approximation formula:
∑i=0
n 4
(1+xi
2
)
Δ x≈π
∫0
1 4
(1+x
2
)
dx=π¿
Copyright © 2007–2015 Russel Winder 8
The Conception
Calculate an approximation to the area under
a conic section by filling the area with a known
number of rectangles of known size and then
sum the areas of the rectangles.
The narrower the rectangles, the more accurate the approximation.
This is a data parallel problem and
embarrassingly parallel.
Copyright © 2007–2015 Russel Winder 9
The Parallelism
● Addition is commutative and associative so we
can partition the overall summation in any way
we want:
a + b + c + d + e + f
( a + b ) + ( c + d ) + ( e + f )
Can partition the overall sum into bits to
be done on different processors.
This should make things faster.
Copyright © 2007–2015 Russel Winder 10
Adding the Parallelism
● Instead of doing all the calculations sequentially,
partition the problem into a number of chunks.
problem
subproblem
result
subproblem
subproblem
subproblem
.
.
.
scatter gather
fork join
reduce
Data parallel
map
Copyright © 2007–2015 Russel Winder 11
Some Code
● Sequential.
● Use threads to obtain parallelism…not.
● Use process to obtain parallelism.
Friends don't let friends use Python 2 instead of Python 3.
Copyright © 2007–2015 Russel Winder 12
It is all just too slow.
Copyright © 2007–2015 Russel Winder 13
More Code
● Use Cython.
● Use Numba.
cf. lightning talk at PyConUK 2014.
Copyright © 2007–2015 Russel Winder 14
A lot faster but… is
controlling parallelism in
Python the thing to do…
Copyright © 2007–2015 Russel Winder 15
Even More Code
● Use NumPy.
● Use C.
● Use C++/Boost.
● Use D/PyD.
● Use Chapel/PyChapel.
Offload the whole computation,
Leaving Python code as the
coordination code.
https://github.com/russel/Pi_Quadrature/tree/master/Python
http://dlang.org/
http://pyd.readthedocs.org/
http://chapel.cray.com/
http://pychapel.readthedocs.org/
Copyright © 2007–2015 Russel Winder 16
Parallelism and computation
is not Python's forte.
(Even though Python is a great language.)
Copyright © 2007–2015 Russel Winder 17
So do not do it.
Copyright © 2007–2015 Russel Winder 18
NUMA
PGAS
Copyright © 2007–2015 Russel Winder 19
Employ a multilingual,
polyglot programming mentality.
Copyright © 2015 Russel Winder 20
Making Python
computations fast
Dr Russel Winder
email: russel@winder.org.uk
twitter: @russel_winder
Web: http://www.russel.org.uk
Copyright © 2015 Russel Winder 21
John, you were a truly Pythonic hero,
I miss your physical presence here.

Contenu connexe

Similaire à Making Python computations fast

Predective analytcis v0.1 AS
Predective analytcis v0.1 ASPredective analytcis v0.1 AS
Predective analytcis v0.1 AS
Ankur Sansanwal
 

Similaire à Making Python computations fast (20)

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
 
GPars: Parallelism the Right Way
GPars: Parallelism the Right WayGPars: Parallelism the Right Way
GPars: Parallelism the Right Way
 
Predective analytcis v0.1 AS
Predective analytcis v0.1 ASPredective analytcis v0.1 AS
Predective analytcis v0.1 AS
 
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
 
Tales from the Workshops
Tales from the WorkshopsTales from the Workshops
Tales from the Workshops
 
Routed Fabrics For Ceph
Routed Fabrics For CephRouted Fabrics For Ceph
Routed Fabrics For Ceph
 
Automatic problem generation
Automatic problem generationAutomatic problem generation
Automatic problem generation
 
Three Optimization Tips for C++
Three Optimization Tips for C++Three Optimization Tips for C++
Three Optimization Tips for C++
 
Three Optimization Tips for C++
Three Optimization Tips for C++Three Optimization Tips for C++
Three Optimization Tips for C++
 
ACCU Keynote by Andrei Alexandrescu
ACCU Keynote by Andrei AlexandrescuACCU Keynote by Andrei Alexandrescu
ACCU Keynote by Andrei Alexandrescu
 
Testing: Python, Java, Groovy, etc.
Testing: Python, Java, Groovy, etc.Testing: Python, Java, Groovy, etc.
Testing: Python, Java, Groovy, etc.
 
JEEConf 2017 - In-Memory Data Streams With Hazelcast Jet
JEEConf 2017 - In-Memory Data Streams With Hazelcast JetJEEConf 2017 - In-Memory Data Streams With Hazelcast Jet
JEEConf 2017 - In-Memory Data Streams With Hazelcast Jet
 
The Case for Kotlin and Ceylon
The Case for Kotlin and CeylonThe Case for Kotlin and Ceylon
The Case for Kotlin and Ceylon
 
Ceph Day Amsterdam 2015 - Ceph over IPv6
Ceph Day Amsterdam 2015 - Ceph over IPv6 Ceph Day Amsterdam 2015 - Ceph over IPv6
Ceph Day Amsterdam 2015 - Ceph over IPv6
 
The Power of Motif Counting Theory, Algorithms, and Applications for Large Gr...
The Power of Motif Counting Theory, Algorithms, and Applications for Large Gr...The Power of Motif Counting Theory, Algorithms, and Applications for Large Gr...
The Power of Motif Counting Theory, Algorithms, and Applications for Large Gr...
 
Python week 7 8 2019-2020 for g10 by eng.osama ghandour
Python week 7 8 2019-2020 for g10 by eng.osama ghandourPython week 7 8 2019-2020 for g10 by eng.osama ghandour
Python week 7 8 2019-2020 for g10 by eng.osama ghandour
 
Multiple awr reports_parser
Multiple awr reports_parserMultiple awr reports_parser
Multiple awr reports_parser
 
NATE_Oct17_2015_Schwieterman
NATE_Oct17_2015_SchwietermanNATE_Oct17_2015_Schwieterman
NATE_Oct17_2015_Schwieterman
 
Icom4015 lecture12-s16
Icom4015 lecture12-s16Icom4015 lecture12-s16
Icom4015 lecture12-s16
 

Plus de Russel 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
 
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
 
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
 
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
 
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
 
Why Groovy When Java 8 or Scala, or…
Why Groovy When Java 8 or Scala, or…Why Groovy When Java 8 or Scala, or…
Why Groovy When Java 8 or Scala, or…
 
Closures: The Next "Big Thing" In Java
Closures: The Next "Big Thing" In JavaClosures: The Next "Big Thing" In Java
Closures: The Next "Big Thing" In Java
 

Dernier

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
panagenda
 
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
Safe Software
 
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
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
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
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Making Python computations fast

  • 1. Copyright © 2015 Russel Winder 1 Making Python computations fast Dr Russel Winder email: russel@winder.org.uk twitter: @russel_winder Web: http://www.russel.org.uk
  • 2. Copyright © 2015 Russel Winder 2 Presentation slots are very short…
  • 3. Copyright © 2015 Russel Winder 3 Structure Beginning Middle End
  • 4. Copyright © 2015 Russel Winder 4 What is the value of ?π
  • 5. Copyright © 2015 Russel Winder 5 π
  • 6. Copyright © 2015 Russel Winder 6 It's simples. Александр Орлов 2009
  • 7. Copyright © 2007–2015 Russel Winder 7 The Maths The equation: Leads to the approximation formula: ∑i=0 n 4 (1+xi 2 ) Δ x≈π ∫0 1 4 (1+x 2 ) dx=π¿
  • 8. Copyright © 2007–2015 Russel Winder 8 The Conception Calculate an approximation to the area under a conic section by filling the area with a known number of rectangles of known size and then sum the areas of the rectangles. The narrower the rectangles, the more accurate the approximation. This is a data parallel problem and embarrassingly parallel.
  • 9. Copyright © 2007–2015 Russel Winder 9 The Parallelism ● Addition is commutative and associative so we can partition the overall summation in any way we want: a + b + c + d + e + f ( a + b ) + ( c + d ) + ( e + f ) Can partition the overall sum into bits to be done on different processors. This should make things faster.
  • 10. Copyright © 2007–2015 Russel Winder 10 Adding the Parallelism ● Instead of doing all the calculations sequentially, partition the problem into a number of chunks. problem subproblem result subproblem subproblem subproblem . . . scatter gather fork join reduce Data parallel map
  • 11. Copyright © 2007–2015 Russel Winder 11 Some Code ● Sequential. ● Use threads to obtain parallelism…not. ● Use process to obtain parallelism. Friends don't let friends use Python 2 instead of Python 3.
  • 12. Copyright © 2007–2015 Russel Winder 12 It is all just too slow.
  • 13. Copyright © 2007–2015 Russel Winder 13 More Code ● Use Cython. ● Use Numba. cf. lightning talk at PyConUK 2014.
  • 14. Copyright © 2007–2015 Russel Winder 14 A lot faster but… is controlling parallelism in Python the thing to do…
  • 15. Copyright © 2007–2015 Russel Winder 15 Even More Code ● Use NumPy. ● Use C. ● Use C++/Boost. ● Use D/PyD. ● Use Chapel/PyChapel. Offload the whole computation, Leaving Python code as the coordination code. https://github.com/russel/Pi_Quadrature/tree/master/Python http://dlang.org/ http://pyd.readthedocs.org/ http://chapel.cray.com/ http://pychapel.readthedocs.org/
  • 16. Copyright © 2007–2015 Russel Winder 16 Parallelism and computation is not Python's forte. (Even though Python is a great language.)
  • 17. Copyright © 2007–2015 Russel Winder 17 So do not do it.
  • 18. Copyright © 2007–2015 Russel Winder 18 NUMA PGAS
  • 19. Copyright © 2007–2015 Russel Winder 19 Employ a multilingual, polyglot programming mentality.
  • 20. Copyright © 2015 Russel Winder 20 Making Python computations fast Dr Russel Winder email: russel@winder.org.uk twitter: @russel_winder Web: http://www.russel.org.uk
  • 21. Copyright © 2015 Russel Winder 21 John, you were a truly Pythonic hero, I miss your physical presence here.