Skip to content

Commit 089096a

Browse files
cleanup num_threads=0 docs (#69)
1 parent 867110c commit 089096a

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<!-- next-header -->
44

55
## git
6+
- `Searcher::search_many` takes `num_threads = 0` to reuse the global thread
7+
pool ([#69](https://github.com/RagnarGrootKoerkamp/sassy/pull/69))
8+
- Update `wide` to `1.5.0` and cleanup the wrapper types in `backend.rs` accordingly.
69

710
## 0.2.6
811
- Support `max_n_frac` directly in the `Searcher` API, rather than only in the CLI. A small breaking change removes the `max_n_frac` argument from `Searcher::search_all_alignents`. ([#66](https://github.com/RagnarGrootKoerkamp/sassy/pull/66), [#67](https://github.com/RagnarGrootKoerkamp/sassy/pull/67))

‎src/search.rs‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,8 @@ impl<P: Profile> Searcher<P> {
522522

523523
/// Search each given pattern in each given text, using the algorithms given by `mode` (see [`SearchMode`]).
524524
///
525-
/// Does multithreading using `rayon`. Pass `num_threads == 0` to run on
526-
/// rayon's process-global thread pool (built once for the whole program);
527-
/// size it up front with
528-
/// `rayon::ThreadPoolBuilder::new().num_threads(n).build_global()` if needed.
529-
/// A non-zero `num_threads` builds a dedicated pool for this call, which is
530-
/// convenient for a one-off but spawns and tears down `num_threads` OS
531-
/// threads every call — prefer the global pool (`0`) in hot loops.
525+
/// By default, just use `num_threads = 0` for rayon's global thread pool, which defaults to 1 thread per logical core.
526+
/// Otherwise, a local thread pool is built per call.
532527
pub fn search_many<PAT: AsRef<[u8]> + Sync, I: RcSearchAble + Sync>(
533528
&mut self,
534529
patterns: &[PAT],
@@ -589,12 +584,12 @@ impl<P: Profile> Searcher<P> {
589584
SearchMode::Auto => unreachable!("Not implemented yet"),
590585
SearchMode::BatchPatternsShort => unreachable!("Not implemented yet"),
591586
};
592-
// dispatch: global pool when num_threads == 0, else a dedicated pool
587+
593588
if num_threads == 0 {
594-
// Reuse rayon's process-global pool instead of building (and tearing
595-
// down) a fresh one on every call.
589+
// Use rayon's global thread pool
596590
run(self)
597591
} else {
592+
// Build a separate thread pool for this call.
598593
rayon::ThreadPoolBuilder::new()
599594
.num_threads(num_threads)
600595
.build()
@@ -3677,7 +3672,7 @@ mod tests {
36773672
eprintln!("alpha {:?}", searcher.alpha);
36783673
let k = rng.random_range(0..=pattern_len * 4 / 10);
36793674
eprintln!("k {k}");
3680-
// Include 0 to exercise the process-global rayon pool path.
3675+
// 0 threads uses the global thread pool.
36813676
let num_threads = rng.random_range(0..=4);
36823677
eprintln!("threads {num_threads}");
36833678

0 commit comments

Comments
 (0)