Parallelize fold operations with pluggable execution strategies.
A Zig port of commonware's
commonware-parallel.
Stability upstream varies by primitive. lib.rs puts the Strategy trait, Sequential,
Batches, Grid, and Tiles in the BETA scope. With std, so are Rayon, ThreadPool,
and the rayon, policy, and topology modules. mocks, fold_plan, and fuzz are ALPHA.
See commonware's stability levels.
Every backlog item in docs/lanes/parallel.md is done, and its
test audit lists no open tests.
Sequential,sequential(sequential.zig): runs every operation on the calling thread, in input order.Rayon(rayon.zig): runs operations on a sharedThreadPool.with_policymakes it adaptive.ThreadPool,ThreadPoolConfig(pool.zig): a small fork-join pool whose workers start throughstd.Io.assert_strategy(root.zig): checks at compile time that a type implements the strategy interface. strategy.zig writes its operations once over each strategy's primitives.Range,Partitioned(ops.zig): the inputs a strategy iterates, and shared serial bodies.Batches(strategy.zig),Grid,Tiles(tiles.zig):run_batchesandrun_tiles.Task(task.zig): one CPU-bound job submitted withspawnand awaited withblock_on.Policy(policy.zig): adaptive serial or parallel, and inline or offload, decisions.Topology(topology.zig): the host's last-level cache domains, and how workers split into groups.Clock,TestClock(clock.zig): the clock that times measured runs.mocks(mocks.zig): mock strategies, such asExplorer, for testing code that is generic over a strategy.
zig build test-parallel # unit tests
zig build bench -Dbench-filter=parallel:: # fold and sort benchmarks (ReleaseFast)zig build test also runs each benchmark once on its smoke inputs.
All of these are recorded in the parallel lane decisions.
- There is no rayon port.
ThreadPoolis a fork-join pool whose workers arestd.Io.Group.concurrenttasks, so the deterministic runtime can host it. - Folds and maps split into
min(len, 64)balanced chunks, whatever the thread count. A fold gives the same result on every pool size. - Closures are
pub fnmethods on operation values. Sorts take Zig'slessThan(ctx, a, b)instead of anOrderingcomparator. spawntakes a caller-ownedTask(Op)instead of returning a future, so it never allocates. Every spawned task must beblock_on'd before its pool is destroyed.- Fallible operations return the first error in chunk order. Commonware allows any.
- The pool is one group, so
topologyports only the model: group leases, homing, and affinity writes are not ported.