Skip to main content

Module execution_policy

Module execution_policy 

Source
Expand description

This module provides the execution policies (sequential / Jacobi-MT / atomic). Execution policies for parallelizable root-finding solvers.

Strategy + Template-Method decomposition:

  • Each algorithm supplies a per-root step (the Step trait) that computes one Newton correction for a root/factor. The step reads the current values of the other roots through a get closure provided by the policy, and returns the corrected value; the policy owns all writes to its data layout (live state, frozen snapshot, or seqlock buffer).
  • Each execution policy owns the iteration loop, the scheduling of the steps, and the convergence aggregation.

This mirrors execution_policy.hpp in ginger-cpp and _policy.py in ginger (Python): the algorithm (Aberth/Bairstow variant) is decoupled from the execution mode (sequential Gauss-Seidel, Jacobi-MT, or atomic decoupled).

Constants§

PARALLEL_THRESHOLD
Number of roots above which the multi-threaded policies are used by default.

Traits§

AtomicCell
Atomic cell abstraction over a pair of f64 values (seqlock-backed).
Step
A per-root Newton correction step shared by every execution policy.

Functions§

atomic_decoupled_run
Atomic decoupled execution: a single seqlock buffer is built once; each thread owns a chunk of slots (single-writer, multi-reader) and runs its own iteration loop independently with no per-iteration barrier, reading the other slots in round-robin order to reduce contention. The returned iteration count is the maximum across threads and is non-deterministic.
jacobi_mt_run
Jacobi multi-threaded execution: each iteration reads a frozen snapshot of the roots and updates them in parallel, so the iteration is order-independent. Small problems (<= 4 roots) fall back to the sequential policy.
sequential_run
Sequential Gauss-Seidel execution: roots are updated in-place in ascending index order within each iteration (later roots see earlier updates).
should_parallelize
Whether num_roots should use the multi-threaded execution policy.