The easiest way to parallelize data is to take a loop that you already have and handle each item in it in a thread.
This is essentially what
pmap does. If you replace a call to
pmap, it takes each call to the function's argument and executes it in a thread pool.
pmap is not completely lazy, but it's not completely strict either. Instead, it stays just ahead of the output consumed. So, if the output is never used, it won't be fully realized.
For this recipe, we'll calculate the Mandelbrot set. Each point in the output takes enough time that this is a good candidate to parallelize. We can just swap
pmap and immediately see a speedup.
The Mandelbrot set can be found by feeding a point ...