Skip to content

Commit 9fa265a

Browse files
committed
perf: parallelize numerical gradients, jacobians, hessians
1 parent a4accea commit 9fa265a

6 files changed

Lines changed: 340 additions & 122 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ jobs:
6161
flags: "--features ndarray"
6262
- features: faer
6363
flags: "--features faer"
64+
# Exercise the rayon-backed `parallel` path (FiniteDiff probe
65+
# fan-out). Matrix backends are needed for the FD Jacobian/Hessian
66+
# tests; faer + nalgebra cover both.
67+
- features: parallel
68+
flags: "--features nalgebra,faer,parallel"
6469
steps:
6570
- uses: actions/checkout@v6
6671
- uses: Swatinem/rust-cache@v2

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/basin/Cargo.toml‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ ndarray-blas = ["ndarray", "ndarray/blas"]
4848
# is the home of `ComplexField` / `RealField` — bounds the faer-backend
4949
# linalg impls need to remain F-generic.
5050
faer = ["dep:faer", "dep:generativity", "dep:faer-traits"]
51-
# Opt-in parallel evaluation (currently faer's rayon-backed linalg). Off by
52-
# default because basin is typically embedded inside a caller that already
53-
# manages parallelism (multi-start sweeps, R/Python schedulers, outer rayon
54-
# loops) — a default-on thread pool causes oversubscription and fights the
55-
# caller. WASM-incompatible: enabling this on wasm32-unknown-unknown will
56-
# fail to compile. No-op unless a backend that hooks into it is also enabled.
57-
parallel = ["faer?/rayon"]
51+
# Opt-in parallel evaluation. Fans the independent probes of a
52+
# finite-difference gradient / Jacobian / Hessian across a `rayon` thread pool
53+
# (`FiniteDiff`, via `core::parallel`), and turns on faer's rayon-backed
54+
# linalg. Off by default because basin is typically embedded inside a caller
55+
# that already manages parallelism (multi-start sweeps, R/Python schedulers,
56+
# outer rayon loops) — a default-on thread pool causes oversubscription and
57+
# fights the caller. WASM-incompatible: enabling this on wasm32-unknown-unknown
58+
# will fail to compile. Under this feature `FiniteDiff: Gradient/Jacobian/
59+
# Hessian` additionally requires the wrapped problem to be `Sync`.
60+
parallel = ["dep:rayon", "faer?/rayon"]
5861
# Standard test-problem corpus (Rosenbrock, ...). Pure-Rust, no extra deps;
5962
# default-on so plain `cargo test` keeps working without `--features problems`
6063
# (integration tests can't see `cfg(test)` lib gating). Downstream can drop
@@ -100,6 +103,10 @@ rand_chacha = { version = "0.10", default-features = false }
100103
# Standard-normal sampling for CMA-ES. rand_distr 0.6 pairs with rand 0.10.
101104
# default-features off to stay consistent with the wasm-safe rand setup.
102105
rand_distr = { version = "0.6", default-features = false }
106+
# Opt-in CPU parallelism (the `parallel` feature only). Not wasm-compatible —
107+
# kept off by default per the WASM hard constraint. MSRV well under basin's
108+
# (rayon 1.x builds far below 1.87), so it doesn't constrain the CRAN pin.
109+
rayon = { version = "1", optional = true }
103110

104111
[dev-dependencies]
105112
# Statistical bench harness. dev-dependency only — never enters the

‎crates/basin/src/core.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub mod inner;
5959
pub mod math;
6060
pub mod numdiff;
6161
pub mod observer;
62+
#[doc(hidden)]
63+
pub mod parallel;
6264
pub mod problem;
6365
pub mod rng;
6466
pub mod solver;

0 commit comments

Comments
 (0)