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. How to Program, Part VI
  7. exercises
  8. pyMPI tutorial
  9. Calculating PI, Part I
  10. Calculating PI, Part II
  11. Calculating PI, Part III
  12. Dividing Work
  13. More MPI
  14. Poogle - Web Search
  15. Mandelbrot Sets
  16. Mandelbrot, The Code
  17. Mandelbrot, The Images
  18. Mandelbrot In CUDA
  19. Conway's Life, Part I
  20. Life Code Listing
  21. Conway's Life, Part II
  22. 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:

complex.py
1x = 1.0j
2print x,x**2,x**3,x**4
$ python ./complex.py
1j (-1+0j) (-0-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. :)