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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//! Plan-free rayon-shaped surface.
//!
//! Provides the ergonomics of rayon's `join` and `par_iter_mut`
//! without requiring callers to construct a [`JobPlan`]. Each
//! function here delegates to the same underlying scheduler the
//! [`crate::sched::join`] / [`crate::sched::par_iter::for_each_chunk`]
//! paths use, with a default `JobPlan::new(0, n)` so consumers who
//! do not care about per-call tuning (hw_class / variant /
//! numa_hint / SMT activation / oversubscription) can call into
//! flynnel with the same shape rayon uses.
//!
//! When per-call tuning IS needed, use the typed
//! [`crate::sched::JobPlan`] surface directly (it is the same
//! scheduler underneath; the flat surface is purely an ergonomic
//! wrapper).
//!
//! # Examples
//!
//! Rayon-style `join`:
//!
//! ```no_run
//! let (left, right) = flynnel::flat::join(
//! || (0..1000).sum::<u32>(),
//! || (1000..2000).sum::<u32>(),
//! );
//! assert_eq!(left + right, (0..2000).sum::<u32>());
//! ```
//!
//! Rayon-style `par_iter_mut().for_each(...)`:
//!
//! ```no_run
//! let mut data: Vec<u32> = (0..1_000_000).collect();
//! flynnel::flat::par_for_each_mut(&mut data, |x| *x = x.wrapping_mul(3));
//! ```
//!
//! Slice-chunk shape (closure receives a `&mut [T]` slice instead
//! of one element at a time):
//!
//! ```no_run
//! let mut data: Vec<f64> = (1..=1_000_000).map(|i| i as f64).collect();
//! flynnel::flat::par_for_each_chunk_mut(&mut data, |slice| {
//! for x in slice {
//! *x = x.sqrt();
//! }
//! });
//! ```
use crateJobPlan;
/// Plan-free `join`: runs `a` and `b` potentially in parallel and
/// returns their results. Same semantics as `rayon::join`.
///
/// Internally constructs a default [`JobPlan`] sized to a
/// 2-element batch. Consumers that need to set `hw_class`,
/// `variant`, `numa_hint`, `use_smt`, or any of the per-call
/// tuning knobs should construct a [`JobPlan`] and call
/// [`crate::sched::join`] directly.
/// Plan-free per-element parallel for-each on a mutable slice.
/// Equivalent in shape to `slice.par_iter_mut().for_each(op)` in
/// rayon. The closure runs once per element, receiving `&mut T`.
///
/// Internally constructs a default [`JobPlan`] sized to the input
/// length and dispatches through [`crate::sched::par_iter::for_each_chunk`],
/// which routes work via the scheduler's hybrid-JEC wake protocol.
///
/// The slice-chunk variant [`par_for_each_chunk_mut`] is faster
/// when the per-element work is tight and you want SIMD-friendly
/// loop bodies; use this per-element form for closures whose
/// natural shape is a single-element operation.
/// Plan-free slice-chunk parallel for-each on a mutable slice.
/// The closure receives a contiguous `&mut [T]` chunk per leaf;
/// this is the natural shape for SIMD-friendly inner loops and is
/// what most flynnel users want.
///
/// Equivalent to the `&mut [T]`-closure shape of
/// [`crate::sched::par_iter::for_each_chunk`], with a default
/// [`JobPlan`] constructed for you.