Multi-Threaded Calculation in LibreOffice Calc

LibreOffice Calc enhances performance on large, complex spreadsheets by distributing formula calculations across multiple CPU cores through multi-threading. By leveraging parallel processing frameworks, dependency graph analysis, formula grouping, and optional OpenCL acceleration, the Calc engine drastically reduces computation times for resource-intensive data sets.

Dependency Graph Analysis and Task Scheduling

At the core of LibreOffice Calc’s multi-threaded engine is its dependency tracking system. Before calculating formulas, Calc builds a Directed Acyclic Graph (DAG) of cell dependencies to determine which cells rely on the results of others.

Formula Grouping (Vectorized Calculations)

Calc uses a technique called formula grouping to optimize repetitive calculations, such as identical formulas copied down large columns:

  1. Contiguous Array Recognition: When the same formula structure is applied over a continuous range of rows, Calc stores these as a single unified formula group rather than individual cell objects.
  2. Chunking Across Threads: The formula group is split into smaller chunks (e.g., blocks of 1,000 rows), which are concurrently calculated by available CPU threads without redundant parsing.
  3. Cache Optimization: By keeping memory structures contiguous and uniform, formula grouping ensures optimal CPU L1/L2 cache utilization, minimizing memory latency during parallel execution.

OpenCL and Heterogeneous Computing

In addition to standard CPU multi-threading, LibreOffice Calc supports heterogeneous calculation via OpenCL (Open Computing Language):

Thread Management and Configuration

Calc automatically detects the number of available logical CPU cores on the host machine and sets the thread pool size accordingly. Users can fine-tune these settings under Tools > Options > LibreOffice Calc > Calculate to define CPU thread limits or toggle OpenCL hardware acceleration, allowing system resources to be tailored to specific workload demands.