1. How to Program, Part I
  2. How to Program, Part II
  3. How to Program, Part III
  4. How to Program, Part IV
  5. How to Program, Part V
  6. exercises
  7. pyMPI tutorial
  8. Calculating PI, Part I
  9. Calculating PI, Part II
  10. Calculating PI, Part III
  11. Poogle - Web Search
  12. Mandelbrot Sets
  13. Mandelbrot, The Code
  14. Mandelbrot, The Images
  15. Conway's Life, Part I
  16. Life Code Listing
  17. Conway's Life, Part II
  18. MPI Life Code Listing

Mandelbrot Sets

Loosely based on a C language program created at uchicago.edu.

Mandelbrot sets are images of self-similar repeating structures (i.e. fractals).

To explain this code it will be necessary to introduce a few extra concepts. The first are complex numbers:

file: complex.py
1 x = 1.0j
2 print x,x**2,x**3,x**4
> python complex.py
1j (-1+0j) -1j (1+0j)

Complex numbers are special values are built from familiar real numbers, and special imaginary numbers. Thus, the operations on complex numbers allow you to perform mathematical operations on pairs of numbers. We don't expect you to understand them deeply, we just want you to grasp two points:

  1. Complex numbers are useful for certain computations
  2. Python supports them

If you want, you can think of the calculation in pixel as just a magic box.

The next bit of magic is the "bmp" module that we have provided. It allows you to make a bitmapped image from a two-dimensional array of values. As you become more advanced in the art of programming you should eventually be able to understand how it works. For now, just use it.

What we really want you to understand from this program is the way it uses parallel programming. Rows of the image are considered as tasks. A single master process hands out tasks to the worker processes, and as the workers finish a task they come back and request another.

This way of doing things keeps all the workers busy all the time, even when the difficulty of the tasks is variable.

Possibly a simpler calculation could have been used to illustrate this style of programming, but this one makes a really cool picture. :)