High Performance Python (from Training at EuroPython 2011) by Ian Ozsvald - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

CHAPTER

TWO

 

MOTIVATION

I ran a 4 hour tutorial on High Performance Python at EuroPython 2011. I’d like to see the training go to more people so I’ve written this guide. This is based on the official tutorial with some additions, I’m happy to accept updates.

The slides for tutorial are linked on the front page of this document.

If you’d like some background on programming for parallelised CPUs then the Economist has a nice overview article entitled “Parallel Bars” (June 2nd 2011): http://www.economist.com/node/18750706. It doesn’t mention CUDA and OpenCL but the comment thread has some useful discussion. GvR gets a name-check in the article.

I’ll also give myself a quick plug - I run an Artificial Intelligence consultancy (http://MorConsulting.com) and rather enjoy training with Python.

I’d like to note that this report is a summary of work over many weeks preparing for EuroPython. I didn’t perform statistically valid tests, I did however run the timings many times and can vouch for their stability. The goal isn’t to suggest that there is “one best way” to do things - I’m showing you several journeys that takes different routes to faster execution times for this problem.

If you’re curious to see how the stock CPython interpreter compares to other languages like C and JavaScript then see thisbenchmark: http://shootout.alioth.debian.org/u32/which-programming-languages-are-fastest.php -you’ll note that it does rather poorly (up to 100* slower than C!). It also compares poorly against JavaScript V8 which is dynamically typed and interpreted - much like CPython.  Playing with comparisons against the JavaScript V8 examples got me started on this tutorial.

To see how CPython, PyPy, ShedSkin, IronPython and Jython compare to other languages (including C and V8) see this benchmark: http://attractivechaos.github.com/plb/ - as shown we can make Python run to 2-6* slower than C with little effort, and the gap with C is shrinking all the time. The flipside of course is that developing with Python is far faster than developing with C!

2.1 Changelog

  • v0.2 July 2011 with longer write-ups, some code improvements
  • v0.1 earliest release (rather draft-y) end of June 2011 straight after EuroPython 2011

2.2 Credits

  • Thanks to my class of 40 at EuroPython for making the event so much fun :-)
  • The EuroPython team for letting me teach, the conference was a lot of fun
  • Mark Dufour and ShedSkin forum members
  • Cython team and forum members
  • Andreas Klöckner for pyCUDA
  • Everyone else who made the libraries that make my day job easier

2.3 Other talks

The following talks were all given at EuroPython, many have links to slides and videos:

  • “Debugging and profiling techniques” by Giovanni Bajo: http://ep2011.europython.eu/conference/talks/debugging-and-profiling-techniques
  • “Python for High Performance and Scientific Computing” by Andreas Schreiber: http://ep2011.europython.eu/conference/talks/python-for-high-performance-and-scientific-computing
  • “PyPy hands-on” by Antonio Cuni - Armin Rigo: http://ep2011.europython.eu/conference/talks/pypy-hands-on
  • “Derivatives Analytics with Python & Numpy” by Yves Hilpisch: http://ep2011.europython.eu/conference/talks/derivatives-analytics-with-python-numpy
  • “Exploit your GPU power with PyCUDA (and friends)” by Stefano Brilli: http://ep2011.europython.eu/conference/talks/exploit-your-gpu-power-with-cuda-and-friends
  • “High-performance computing on gamer PCs” by Yann Le Du: http://ep2011.europython.eu/conference/talks/high-performance-computing-gamer-pcs
  • “Python Map Reduce Programming with Pydoop” by Simone Leo: http://ep2011.europython.eu/conference/talks/python-mapreduce-programming-with-pydoop
  • “Making CPython Fast Using Trace-based Optimisations” by Mark Shannon: http://ep2011.europython.eu/conference/talks/making-cpython-fast-using-trace-based-optimisations