|
| 1 | +# A Parallel Mandelbrot Set Plotter |
| 2 | + |
| 3 | +This program plots the Mandelbrot set and writes it out as a PNG file. It uses Rust's concurrency primitives to distribute the work across eight threads. |
| 4 | + |
| 5 | +Different commits show different implementation strategies: |
| 6 | + |
| 7 | +* [Branch `single-threaded`](https://github.com/jorendorff/rust-mandelbrot/blob/single-threaded/src/main.rs) |
| 8 | + is the base version of the program. It does all the work on the main |
| 9 | + thread. |
| 10 | + |
| 11 | +* [Branch `bands`](https://github.com/jorendorff/rust-mandelbrot/commit/bands) |
| 12 | + splits the plotting area up into eight bands, and assigns one thread |
| 13 | + to each. This often makes poor use of the threads, because some |
| 14 | + bands take significantly longer than others to complete: once a fast |
| 15 | + thread completes its band, its CPU goes idle while its less |
| 16 | + fortunate brethren are still hard at work. |
| 17 | + |
| 18 | +* [Branch `task-queue`](https://github.com/jorendorff/rust-mandelbrot/commit/task-queue) |
| 19 | + gets an almost perfect linear speedup from its threads. It splits |
| 20 | + the plotting area up into many more bands, and then has threads draw |
| 21 | + bands from a common pool until the pool is empty. When a thread |
| 22 | + finishes one band, it goes back for more work. Since the bands still |
| 23 | + take different amounts of time to render, the problem cited above |
| 24 | + still occurs, but on a much smaller scale. |
| 25 | + |
| 26 | +* [Branch `lockfree`](https://github.com/jorendorff/rust-mandelbrot/commit/lockfree) |
| 27 | + uses Rust's atomic types to implement a lock-free iterator type, and |
| 28 | + uses that to dole out bands from the pool instead of a |
| 29 | + mutex-protected count. On Linux, this is no faster than the |
| 30 | + mutex-based version, which isn't too surprising: on Linux, locking |
| 31 | + and unlocking an uncontended mutex *is* simply a pair of atomic |
| 32 | + operations. |
| 33 | + |
| 34 | +* [Branch `rayon`](https://github.com/jorendorff/rust-mandelbrot/commit/rayon) |
| 35 | + uses the Rayon library instead of Crossbeam. Rayon provides a |
| 36 | + *parallel iterator* API that makes our code much simpler. It looks |
| 37 | + a lot like Rust code that uses plain old iterators. |
0 commit comments