1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Running strided-rs kernels on an [`Exec`] (feature `strided`).
//!
//! strided-rs parallelizes through its own [`ExecContext`]; this adapter
//! bridges the two so strided fanout stays inside the borrowed pool and a
//! small operation never enters it.
use ExecContext;
use crate::;
/// strided-basic's parallel threshold (`threading::MINTHREADLENGTH`, not
/// exported), itself Strided.jl's `MINTHREADLENGTH = 1 << 15`. Operations of
/// at most this many elements run serially.
pub const MIN_PARALLEL_LEN: usize = 1 << 15;
/// Run a strided operation of `len` logical elements on `exec`.
///
/// At or below [`MIN_PARALLEL_LEN`] `op` runs serially on the caller with
/// [`ExecContext::serial`] and the pool is never entered. Above it, the pool
/// is entered once and `op` receives a context bounded by the budget.
///
/// # Examples
///
/// ```
/// let n = tcontract_exec::strided::run_with_exec(&tcontract_exec::Exec::serial(), 10, |ctx| {
/// assert!(ctx.is_serial());
/// 1
/// });
/// assert_eq!(n, 1);
/// ```