Notebooks
M
Modal
Modal Mandelbrot Fractal

Modal Mandelbrot Fractal

Building Mandelbrot fractal across 20 parallel CPU workers on modal.

modal-labsmodalworkersAlph

Modal: Fast Parallel Mandelbrot Fractal

Open in Alph

Generate a high-resolution Mandelbrot fractal by fanning out computation across 20 parallel CPU workers on Modal. Lightweight image, no GPU — just raw parallel compute.

How It Works

  1. Define remote functionscompute_strip and assemble_image run on Modal's cloud infrastructure, not locally
  2. Fan out with map — the Mandelbrot image is split into 20 horizontal strips, each computed in parallel on a separate CPU worker
  3. 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
Output