pub const JACOBIAN_BATCH_MIN_PROBLEMS: usize = 256;Expand description
Lane count below which a ComputeBackend::CpuMulti request runs
jacobian_batch on the calling thread instead.
§Measured crossover
Methodology. Same machine, date, build and load as
DERIVATIVE_BATCH_MIN_POINTS — 4 logical cores, load average 2.3-3.6,
not idle. n = 4 Jacobians, DiffSettings::central so each lane costs
8 evaluations of a 4-component function, best of 7, two independent runs.
Produced by the same #[ignore]d differentiate_crossover_benchmark test.
| Lanes | cheap serial | cheap speed-up (A) | (B) | costly speed-up (A) | (B) |
|---|---|---|---|---|---|
| 4 | 1.56 us | 0.19x | 0.16x | 0.21x | 0.21x |
| 8 | 3.05 us | 0.10x | 0.12x | 0.63x | 0.35x |
| 16 | 6.05 us | 0.19x | 0.21x | 0.60x | 0.65x |
| 32 | 12.06 us | 0.83x | 0.33x | 1.52x | 1.03x |
| 64 | 23.64 us | 0.57x | 0.70x | 1.18x | 2.18x |
| 128 | 48.36 us | 0.84x | 1.34x | 1.86x | 2.46x |
| 256 | 95.16 us | 1.09x | 1.11x | 1.88x | 2.61x |
| 1 024 | 373.05 us | 1.63x | 2.18x | 1.86x | 1.50x |
| 4 096 | 1590.74 us | 1.75x | 1.90x | 1.85x | 3.10x |
| 16 384 | 6702.36 us | 1.83x | 2.98x | 2.06x | 2.88x |
Result. 256 — the smallest lane count that won in both runs. It lands
on exactly the same value as
crate::math::minimise::MINIMISE_BATCH_MIN_PROBLEMS and
crate::math::parallel::ROOT_BATCH_MIN_PROBLEMS, and 256x below this
module’s own DERIVATIVE_BATCH_MIN_POINTS. The two numbers in one module
disagreeing by 256x is the clearest evidence yet for the point
crate::compute::CPU_MULTI_MIN_WORK_ITEMS makes: the crossover tracks
work per lane, not the algorithm. A Jacobian lane here does 8 function
evaluations, four vector allocations and a matrix assembly; a scalar
derivative lane does 2 evaluations and a division.
§A performance trap found by this measurement, recorded so it is not reintroduced
The first version of the central-difference column copied the point twice
per column (x.to_vec() for the +h probe and again for the -h probe).
With that version the parallel path never won at any size measured,
topping out at 0.96x on 16 384 lanes — allocation traffic, not arithmetic,
was the whole cost. Reusing a single probe buffer made the serial path ~1.4x
faster and restored parallel scaling to 1.8-3.0x. If a future change
reintroduces a per-column allocation, this crossover is the measurement that
will notice.
§Limitations
As for DERIVATIVE_BATCH_MIN_POINTS, plus: measured at n = 4 only. A
larger n raises the per-lane cost and should lower this crossover, but that
has not been measured.
§Units
A count of independent Jacobian problems, dimensionless.