From c0c95e4bc5f50929499f0070ab79801ea9f52218 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 28 Jul 2025 22:05:36 +0200 Subject: expose function to set thread count --- hittekaart-py/Cargo.toml | 1 + hittekaart-py/src/lib.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/hittekaart-py/Cargo.toml b/hittekaart-py/Cargo.toml index 9a44118..7e69ef8 100644 --- a/hittekaart-py/Cargo.toml +++ b/hittekaart-py/Cargo.toml @@ -11,3 +11,4 @@ crate-type = ["cdylib"] [dependencies] pyo3 = "0.24.0" hittekaart = { path = "../hittekaart" } +rayon = "1.10.0" diff --git a/hittekaart-py/src/lib.rs b/hittekaart-py/src/lib.rs index 4b67777..2ad0e56 100644 --- a/hittekaart-py/src/lib.rs +++ b/hittekaart-py/src/lib.rs @@ -164,6 +164,14 @@ fn do_generate( Ok(()) } +#[pyfunction] +fn set_threads(threads: usize) -> PyResult<()> { + rayon::ThreadPoolBuilder::new() + .num_threads(threads) + .build_global() + .map_err(|e| err_to_py(&e)) +} + /// A Python module implemented in Rust. #[pymodule] fn hittekaart_py(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { @@ -171,6 +179,7 @@ fn hittekaart_py(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_function(wrap_pyfunction!(generate, m)?)?; + m.add_function(wrap_pyfunction!(set_threads, m)?)?; m.add("HitteError", py.get_type::())?; Ok(()) } -- cgit v1.2.3