Russel Winder
June 20, 2015
44

# Making Computations Execute Very Quickly

Presentation at PyData London 2015, 2015-06-20. Putting forward the proposal not to use Cython, NumPy and Numba to speed up Python computations, but to use C++, or better D or Chapel in a polyglot programming approach.

Code used as examples comes from https://github.com/russel/Pi_Quadrature

June 20, 2015

## Transcript

1. ### Copyright © 2015 Russel Winder 1 Making Computations Execute Very

Quickly Dr Russel Winder email: russel@winder.org.uk twitter: @russel_winder Web: http://www.russel.org.uk

4. ### Copyright © 2015 Russel Winder 4 CPU Bound vs I/O

Bound 1/2 — • Python is entirely fine for essentially I/O bound activity: • Managing user interfaces via native code widgets (Qt, GTK, Wx, ) … • Managing networking activity. Common theme here, the use of an event loop.
5. ### Copyright © 2015 Russel Winder 5 CPU Bound vs I/O

Bound 2/2 — • Python uses hardware floating point, but via the Python heap. • Python uses hardware integers for small integer values, but via the Python heap. Result: non-trivial numerical activity is slow.

of ?

2009

15. ### Copyright © 2015 Russel Winder 15 Approximating  • What

is it's value represented as a floating point number? • We can only obtain an approximation. • A plethora of possible algorithms to choose from, a popular one is to employ the following integral equation. π 4 =∫ 0 1 1 1+x2 dx
16. ### Copyright © 2015 Russel Winder 16 One possible algorithm •

Use quadrature to estimate the value of the integral which is the area under the curve. – π= 4 n ∑ i=1 n 1 1+( i−0.5 n ) 2 With n = 3 not much to do, but potentially lots of error. Use n = 107 or n = 109? Embarrassingly parallel.

and associative, expression can be decomposed into sums of partial sums.
20. ### Copyright © 2015 Russel Winder 20 a + b +

c + d + e + f = ( a + b ) + ( c + d ) + ( e + f )
21. ### Copyright © 2015 Russel Winder 21 Scatter Gather — map

reduce data parallel

24. ### Copyright © 2015 Russel Winder 24 The Python data model

and its GIL make Python unsuitable for parallel computation.
25. ### Copyright © 2015 Russel Winder 25 PyPy and NumPy do

not help, nor does Cython, Numba, etc., as much as they perhaps should.
26. ### Copyright © 2015 Russel Winder 26 Native code, e.g. C++,

D, Chapel, are the way forward for CPU-bound components of a Python-based system.
27. ### Copyright © 2015 Russel Winder 27 And then there is

OpenCL and OpenGL, soon to be replaced by Vulkan.
28. ### Copyright © 2015 Russel Winder 28 Making Computations Execute Very

Quickly Dr Russel Winder email: russel@winder.org.uk twitter: @russel_winder Web: http://www.russel.org.uk