Abstract
Software engineers designing recursive fork-join programs destined to run on massively parallel computing systems must be cognizant of how their program's memory requirements scale in a many-processor execution. Although tools exist for measuring memory usage during one particular execution of a parallel program, such tools cannot bound the worst-case memory usage over all possible parallel executions. This paper introduces Cilkmem, a tool that analyzes the execution of a deterministic Cilk program to determine its $p$-processor memory high-water mark (MHWM), which is the worst-case memory usage of the program over all possible $p$-processor executions. Cilkmem employs two new algorithms for computing the $p$-processor MHWM. The first algorithm calculates the exact $p$-processor MHWM in $O(T_1 \cdot p)$ time, where $T_1$ is the total work of the program. The second algorithm solves, in $O(T_1)$ time, the approximate threshold problem, which asks, for a given memory threshold $M$, whether the $p$-processor MHWM exceeds $M/2$ or whether it is guaranteed to be less than $M$. Both algorithms are memory efficient, requiring $O(p \cdot D)$ and $O(D)$ space, respectively, where $D$ is the maximum call-stack depth of the program's execution on a single thread. Our empirical studies show that Cilkmem generally exhibits low overheads. Across ten application benchmarks from the Cilkbench suite, the exact algorithm incurs a geometric-mean multiplicative overhead of $1.54$ for $p=128$, whereas the approximation-threshold algorithm incurs an overhead of $1.36$ independent of $p$. In addition, we use Cilkmem to reveal and diagnose a previously unknown issue in a large image-alignment program contributing to unexpectedly high memory usage under parallel executions.
Introduction
In parallel computing, specifically within recursive fork-join models like Cilk, memory usage is inherently non-deterministic. Because a scheduler decides which tasks run on which processors at any given time, one execution might use very little memory while another—due to different "stealing" patterns by idle processors—might use orders of magnitude more. This phenomenon, known as the "Memory Explosion Trap," occurs when a thief processor steals and executes allocations that would otherwise happen sequentially in a single-threaded execution.
Standard memory profilers only report the peak memory of a single execution, which is insufficient for guaranteeing that a program will not crash due to Out-of-Memory (OOM) errors on a massively parallel system. Cilkmem addresses this by computing the Memory High-Water Mark (MHWM), the absolute worst-case memory consumption across all possible execution schedules.
Methods and Modeling
Cilkmem models parallel programs as Series-Parallel Directed Acyclic Graphs (DAGs). In this model, edges represent "strands" of code (sequences of instructions without parallel control flow), and vertices represent fork or join points.
As shown in Figure 1, the structure of a parallel program can be decomposed into paths and parallel branches. If each branch $b_i$ allocates memory, a parallel scheduler might execute many such branches simultaneously, leading to a peak memory usage that is the sum of allocations across all active branches. Cilkmem accounts for "suspended" memory—allocations made by a parent task that remain in memory while child tasks run in parallel.
Algorithms
Cilkmem introduces two primary algorithms for MHWM analysis:
- Exact Algorithm (ExactOn): An online algorithm that computes the exact MHWM for $p$ processors in $O(T_1 \cdot p)$ time. It uses a dynamic programming approach to track memory allocations and suspended components as the program executes.
- Approximate Threshold Algorithm (ApproxOn): This algorithm solves the "approximate threshold problem": given a memory limit $M$, it determines if the program might exceed $M/2$ or if it is guaranteed to stay below $M$. By focusing on a subset of execution states called "stripped robust antichains," this algorithm runs in $O(T_1)$ time, making its overhead independent of the number of processors being simulated.
Cilkmem is implemented using the Tapir/LLVM compiler and the CSI (Compiler-Inserted Instrumentation) framework, allowing it to intercept memory calls (malloc, free) and parallel control flow instructions to build its internal model on the fly.
Evaluation and Results
The researchers evaluated Cilkmem using the Cilkbench Suite, which includes 10 parallel applications such as Strassen matrix multiplication, N-body simulation, and LU decomposition.
Performance
The tool demonstrates remarkably low performance overhead. For the exact algorithm at $p=128$, the geometric-mean multiplicative overhead was only 1.54x. The approximation algorithm was even more efficient, with a 1.36x overhead that remained constant even as the simulated processor count $p$ increased to 4096. This independence from $p$ allows developers to analyze programs destined for supercomputers on a standard workstation.
Real-world Case Study
Cilkmem was applied to a large-scale image-alignment pipeline used in brain connectomics. The tool identified a previously unknown issue where memory usage increased by 350 MB per processor. By pinpointing the exact lines in the source code responsible for this unexpected blow-up, Cilkmem enabled developers to diagnose and fix a critical scaling issue that would have otherwise led to OOM errors in production.
Conclusion
Cilkmem provides a practical and theoretically sound approach to bounding the memory usage of fork-join parallel programs. While currently limited to deterministic programs and serial analysis (the tool itself runs on one thread), it offers a significant leap forward in parallel performance engineering. Future work remains to extend these efficient bounds to arbitrary (non-series-parallel) DAGs and to parallelize the analysis tool itself.
Summary updated