Quantitative Synthesis for Concurrent Programs

Pavol Cerný, Krishnendu Chatterjee, Thomas A. Henzinger, Arjun Radhakrishna, Rohit Singh

Abstract

We present an algorithmic method for the quantitative, performance-aware synthesis of concurrent programs. The input consists of a nondeterministic partial program and of a parametric performance model. The nondeterminism allows the programmer to omit which (if any) synchronization construct is used at a particular program location. The performance model, specified as a weighted automaton, can capture system architectures by assigning different costs to actions such as locking, context switching, and memory and cache accesses. The quantitative synthesis problem is to automatically resolve the nondeterminism of the partial program so that both correctness is guaranteed and performance is optimal. As is standard for shared memory concurrency, correctness is formalized “specification free”, in particular as race freedom or deadlock freedom. For worst-case (average-case) performance, we show that the problem can be reduced to 2-player graph games (with probabilistic transitions) with quantitative objectives. While we show, using game-theoretic methods, that the synthesis problem is Nexp-complete, we present an algorithmic method and an implementation that works efficiently for concurrent programs and performance models of practical interest. We have implemented a prototype tool and used it to synthesize finite-state concurrent programs that exhibit different programming patterns, for several performance models representing different architectures.

Introduction

Writing concurrent programs is notoriously difficult due to the complexities of thread synchronization and the risk of deadlocks or race conditions. Traditional program synthesis tools help by filling in "sketches" or partial programs to ensure safety. However, these tools are often performance-blind, focusing solely on whether a program is correct rather than how efficiently it runs on specific hardware.

This paper introduces a method for quantitative synthesis, which automatically generates concurrent programs that are both correct and optimized for performance. By integrating partial programs with parametric performance models and game theory, the proposed framework allows developers to navigate the trade-offs between synchronization overhead and concurrency levels.

Methodology

The synthesis task is framed as a 2-player quantitative game with imperfect information. In this game, Player 1 (the Synthesizer) attempts to choose synchronization constructs to minimize total cost, while Player 2 (the Scheduler) acts as an adversary, choosing thread interleavings to maximize cost or trigger errors. The "imperfect information" aspect reflects the reality that a static program must behave correctly across different runs without knowing the exact values of all variables.

Parametric Performance Models

A core component of this approach is the use of weighted automata to represent performance models. These models assign specific costs to various system actions, such as locking, context switching, and memory accesses.

A performance model represented as a weighted automaton, assigning costs to actions like memory access (m), locking (l), and context switching (cs).

By adjusting these weights, the synthesizer can account for different hardware architectures. For instance, if locking is expensive on a particular system, the synthesizer might favor coarse-grained locking over fine-grained alternatives.

Complexity and Optimization

While the synthesis problem is theoretically NEXP-complete, the authors employ several techniques to make it practical:

  • Strategy Elimination: Lightweight static analysis is used to prune suboptimal synchronization strategies early in the process.
  • MDP Evaluation: Once a strategy is selected, the program is modeled as a Markov Decision Process (MDP). A specialized "forward propagation" technique is used to solve these models efficiently.
  • Quantitative Abstraction: The concept of probabilistic bisimilarity is extended to ensure that simplified program models still provide accurate performance estimates.

Evaluation and Benchmarks

The tool was evaluated on four classic concurrent programming patterns:

  1. Producer-Consumer: Balancing global vs. cell-local locks.
  2. Optimistic Concurrency: Optimizing the number of retries before resorting to locking.
  3. Work Sharing: Determining the optimal number of threads to spawn based on initialization costs.
  4. Cache-Aware Synthesis: Testing the handling of cache locality in a pessimistic concurrency model.

Key Results

The prototype tool successfully synthesized optimal programs for most benchmarks in under a minute. In the Producer-Consumer example, the tool identified that fine-grained locking was 19% better when data copying was expensive, whereas coarse-grained locking was 25% better when locking overhead dominated. For optimistic concurrency, the tool accurately found the "sweet spot" for retry counts, matching empirical observations on physical hardware.

Discussion

The research highlights that architecture-awareness is essential for modern program synthesis. The "optimal" program is not static; it changes based on the relative costs of hardware operations. By treating correctness as a hard constraint within a quantitative objective (assigning "infinite" cost to errors like deadlocks), the synthesizer naturally prioritizes safety while optimizing for speed.

Conclusion and Future Work

This work demonstrates that despite high theoretical complexity, quantitative synthesis is feasible for critical concurrent kernels. Future research directions include scaling the approach for larger programs, incorporating more realistic expected workloads, and automating the generation of performance automata from hardware specifications.

Summary updated

BibTeX
@inproceedings{cerny2011quantitative,
  author = {Pavol Cerný and Krishnendu Chatterjee and Thomas A. Henzinger and Arjun Radhakrishna and Rohit Singh},
  title = {{Quantitative Synthesis for Concurrent Programs}},
  booktitle = {CAV},
  year = {2011},
  url = {https://openreview.net/forum?id=KDNdb6mzOf},
}
Figure