Modal Mandelbrot Fractal
Building Mandelbrot fractal across 20 parallel CPU workers on modal.
modal-labsmodalworkersAlph
Export
How It Works
- Define remote functions —
compute_stripandassemble_imagerun on Modal's cloud infrastructure, not locally - Fan out with
map— the Mandelbrot image is split into 20 horizontal strips, each computed in parallel on a separate CPU worker - Assemble & colorize — strips are recombined and mapped to a smooth sinusoidal color palette (black = inside the set)
The region rendered is Seahorse Valley (x ∈ [-0.77, -0.74], y ∈ [0.08, 0.11]), one of the most intricate areas of the Mandelbrot set. At 4000×3000 pixels with 256 max iterations, the full render completed in ~36 seconds wall-clock time — including container cold-start, data transfer, and image assembly.
[3]
Setup & Configuration
We define two Modal remote functions:
compute_strip— each worker computes a horizontal slice of the fractal using vectorized NumPy operations over the complex plane.assemble_image— a single worker stitches the strips back together and applies a sinusoidal RGB color mapping (with the Mandelbrot interior rendered as black).
The image is intentionally minimal (debian_slim + numpy + pillow) so containers cold-start fast.
[4]
🔢 Rendering 4000x3000 Mandelbrot (256 iterations) 🚀 Fanning out to 20 parallel workers... ✅ Done in 36.0s 📐 Image: 4000x3000 pixels, 4073 KB
Run the Computation
Fan out the Mandelbrot calculation across 20 parallel workers on Modal, then assemble the strips into a single 4000×3000 PNG.
[5]
📐 Display size: 800x600, 67 KB