Contenido principal

Collatz Computation at Scale with MATLAB Parallel Server

R2026b
Since R2026b

This video shows MATLAB® Parallel Server™ achieving near-linear speedup on a large-scale parallel computation. The short video explains the Collatz conjecture, then shows the live updates MATLAB generates to track progress while computing Collatz sequences on 5,000 cores of a High-Performance Computing (HPC) cluster.

With Parallel Computing Toolbox™ alone, your computation is limited to the workers on a single machine. MATLAB Parallel Server allows you to distribute your computation across many nodes of a cluster. The video shows a visualization of the speedup when a 100-core single-node computation runs side by side with a 5000-core multi-node computation, and the cluster completes the work approximately 49x faster, demonstrating near-linear speedup at even larger scales.

Watch the Video

The video below introduces the Collatz conjecture problem and then shows the large‑scale, real‑time visualizations produced during the computation.

What the Video Shows

The video visualizes the Collatz sequences as they are computed. The visualization shows two execution modes running side by side:

  • Parallel Computing Toolbox — A batch pool job computing the Collatz sequence on one cluster node with 100 workers using a parfor-loop. This node also runs the MATLAB client that controls the computations and generates the visualizations. Batch pool jobs cannot send data directly to the MATLAB client, so workers send progress data using the job's ValueStore object.

  • MATLAB Parallel Server cluster — An interactive pool computing Collatz sequences across 5000 workers using a parfor-loop. Workers send frequent updates to the MATLAB client via a DataQueue object.

The video shows three runs of the same computation with different color and angle parameters, leading to different visualizations. For each run, the cluster panel shows that the 5000 cluster workers complete the computation approximately 49x faster than 100 workers, demonstrating near-linear speedup.

How the Computation Works

The computations evaluate Collatz sequences and display progress using the following approach:

  1. Vectorization — Instead of computing one sequence at a time, the code applies an update rule to an array of starting numbers simultaneously, exploiting MATLAB optimizations for array operations.

  2. Randomized blocks of starting values — The starting values are divided into blocks that take about one second to compute. Each block is an independent unit of work that a single worker can process without communicating with other workers. The code arranges the blocks in a random order rather than sequentially. Because larger starting values tend to produce longer sequences, randomization prevents long-running blocks from clustering together. This allows the different execution modes to complete work at a roughly uniform rate, which allows for a fair comparison in the visualization.

  3. Parallelize with parfor — A parfor-loop assigns blocks to workers. With Parallel Computing Toolbox only, blocks run on the workers of a single machine. With MATLAB Parallel Server, the same parfor-loop distributes blocks across workers on many cluster nodes.

  4. Send only visualization data — Workers compute all sequences in their assigned block but only generate and send visualization data back to the client when the block contains one of the 200 sequences selected for visualization. The interactive pool workers on the cluster send visualizing data to the client with a DataQueue object. Batch pool workers send visualization data to the client worker using a DataQueue object, and the client worker forwards it to the MATLAB client using the job's ValueStore object. This approach keeps communication minimal while still computing all the Collatz sequences, which is why speedup remains near-linear even at 5000 workers.

How the Visualization Works

To keep the display informative and responsive, only 200 sequences are sampled across all the starting values for the visualization. Each sequence is drawn starting at a point that corresponds to the value 1, extending outward toward the sequence's starting value. The line turns left for even numbers and turns right for odd numbers. The line thickness reflects how many sequences pass through a value. The “root” at one is thickest because all sequences meet there if the conjecture is true.

Hardware Used in Video

The hardware for both execution modes is identical to remove any variance in CPU properties. Each cluster node has 128 cores and 256 GB memory, and is configured with one MATLAB worker per core, which is approximately 2 GB memory for each MATLAB worker. This relatively low memory-per-worker configuration is sufficient for this example because the Collatz computation is a lightweight, CPU-bound workload that uses basic MATLAB functionality and requires very little memory per worker. Many other MATLAB applications, such as optimization, differential equation solving, large-scale data analysis, or simulations with substantial state, require considerably more memory per worker.

The single node computation uses 100 of its 128 cores for the parfor computation, with the remaining cores available for the MATLAB client and visualization plotting.

See Also

Functions

Objects

Topics