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

THREE

 

THE MANDELBROT PROBLEM

In this tutorial we’ll be generating a Mandelbrot plot, we’re coding mostly in pure Python. If you want a background on the Mandelbrot set then take a look at WikiPedia.

We’re using the Mandelbrot problem as we can vary the complexity of the task by drawing more (or less) pixels and we can calculate more (or less) iterations per pixel. We’ll look at improvements in Python to make the code run a bit faster and then we’ll look at fast C libraries and ways to convert the code directly to C for the best speed-ups.

This task is embarrassingly parallel which means that we can easily parallelise each operation. This allows us to experiment with multi-CPU and multi-machine approaches along with trying NVIDIA’s CUDA on a Graphics Processing Unit.

This is the output we’re after:

img2.png

Figure 3.1: A 500 by 500 pixel Mandelbrot with maximum 1000 iterations