diff --git a/docs/changelog.md b/docs/changelog.md index 941ea72c..440646ec 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,7 @@ _This project uses semantic versioning_ ## UNRELEASED +- Allow changing number of threads with env variable [#330](https://github.com/egraphs-good/egglog-python/pull/330) ## 11.0.0 (2025-08-08) - Change conversion between binary operators to consider converting both types [#320](https://github.com/egraphs-good/egglog-python/pull/320) - Add ability to parse egglog expressions into Python values [#319](https://github.com/egraphs-good/egglog-python/pull/319) diff --git a/docs/reference/usage.md b/docs/reference/usage.md index 20fb37c0..94d7876d 100644 --- a/docs/reference/usage.md +++ b/docs/reference/usage.md @@ -22,6 +22,14 @@ pip install anywidget It follows [SPEC 0](https://scientific-python.org/specs/spec-0000/) in terms of what Python versions are supported. +## Parallelism and threads + +The underlying Rust library uses Rayon for parallelism. You can control the worker thread count via the environment variable `RAYON_NUM_THREADS`. If this variable is not set or is invalid, the Python bindings default to using a single thread (`1`). + +```shell +export RAYON_NUM_THREADS=4 # use 4 threads +``` + (community)= ## Community diff --git a/src/lib.rs b/src/lib.rs index a34daad2..26a585db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,8 +11,13 @@ use pyo3::prelude::*; /// Bindings for egglog rust library #[pymodule] fn bindings(m: &Bound<'_, PyModule>) -> PyResult<()> { + // Configure Rayon thread pool from env var, defaulting to 1 if unset/invalid. + let num_threads = std::env::var("RAYON_NUM_THREADS") + .ok() + .and_then(|s| s.parse::().ok()) + .unwrap_or(1); rayon::ThreadPoolBuilder::new() - .num_threads(1) + .num_threads(num_threads) .build_global() .unwrap();