pub fn walk_steps_par<Y, E, F>(
walk_params: &WalkParams<Positive, Y>,
next_y: F,
) -> Result<Vec<Step<Positive, Y>>, E>Expand description
Parallel variant of walk_steps: identical contract and output, with
the per-step next_y calls executed on the rayon thread pool.
The walk itself (walker output, per-step volatilities, x-step sequence)
is computed serially and is identical to walk_steps; only the y-value
construction — the dominant cost when next_y rebuilds an option chain
or series — is fanned out. Output is deterministic and equal to the
serial driver’s for the same inputs because every per-step input is
precomputed and order is preserved on collection.
§Sequential/parallel equivalence
- The price path is drawn once, serially, from a single generator before
anything is fanned out:
deterministic_rng(seed)whenWalkParams::seedisSome(seed), the thread RNG otherwise. No random number is drawn on a rayon worker, so the thread count and the scheduling cannot reach the random stream. - Nothing is reduced across steps in parallel; the y-values are assembled
in step order, so no
Decimalorf64result depends on the order in which workers finish. - Hence, for a seeded walk and a
next_ythat is a pure function of its arguments,walk_steps_par(p, f)equalswalk_steps(p, f)bit for bit, on every run. - An unseeded walk draws a new path on every call, serial or parallel, so two calls agree only in distribution.
Semantics notes versus the serial driver:
next_ymust beFn + Sync(stateless or internally synchronized) instead ofFnMut.Ok(None)still ends the walk at the previous step; steps past the firstNoneare computed speculatively and their results — values AND errors — are discarded, exactly as the serial driver never evaluates them.- On failure, the first error in step order that precedes any stop signal is returned.
§Errors
Same as walk_steps.