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
//! Whole-unit tasks over `K` same-type buffers, split in lockstep: the fused
//! alternative to one pass per output.
use drive_unit_tasks;
use crateBufferArray;
use crateExecutionPolicy;
/// [`crate::for_each_unit_task_mut_with`] over `K` buffers of one type, split in
/// lockstep.
///
/// The pair and triple forms take their buffers by separate type, which suits
/// two or three outputs of different types. A pass whose outputs share a type
/// and whose count is a property of the problem -- the six fields a
/// velocity-Verlet kick-and-drift writes, say -- takes them as one array
/// instead, and stays one pass rather than becoming `K` of them. Splitting a
/// fused pass into one call per output multiplies the parallel regions, and
/// each region's wake costs more than the traffic such a fusion saves.
///
/// Every buffer must have the same length, and that length must be whole
/// units. `f` receives each task's runs in the order the buffers were given.
///
/// # Examples
///
/// ```
/// use moirai_parallel::{for_each_unit_task_many_mut_with, WorkBytes};
///
/// let (mut xs, mut ys) = (vec![0_u64; 8], vec![1_u64; 8]);
/// for_each_unit_task_many_mut_with::<WorkBytes<{ 1 << 20 }>, _, _, _, _, 2>(
/// [&mut xs, &mut ys],
/// 4,
/// 64,
/// || (),
/// |(), _first_unit, [xs, ys]| {
/// for (x, y) in xs.iter_mut().zip(ys.iter_mut()) {
/// *x += 2;
/// *y += *x;
/// }
/// },
/// );
/// assert!(xs.iter().all(|&x| x == 2) && ys.iter().all(|&y| y == 3));
/// ```