orx_parallel/parameters/
params.rs1use super::{chunk_size::ChunkSize, iteration_order::IterationOrder, num_threads::NumThreads};
2use crate::Par;
3
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
6pub struct Params {
7 pub num_threads: NumThreads,
11 pub chunk_size: ChunkSize,
15 pub iteration_order: IterationOrder,
20}
21
22impl Params {
23 pub fn new(
25 num_threads: impl Into<NumThreads>,
26 chunk_size: impl Into<ChunkSize>,
27 iteration_order: IterationOrder,
28 ) -> Self {
29 Self {
30 num_threads: num_threads.into(),
31 chunk_size: chunk_size.into(),
32 iteration_order,
33 }
34 }
35
36 pub fn is_sequential(self) -> bool {
40 self.num_threads.is_sequential()
41 }
42
43 pub fn apply<P: Par>(&self, par: P) -> P {
45 par.num_threads(self.num_threads)
46 .chunk_size(self.chunk_size)
47 .iteration_order(self.iteration_order)
48 }
49
50 pub(crate) fn with_num_threads(self, num_threads: impl Into<NumThreads>) -> Self {
53 Self {
54 num_threads: num_threads.into(),
55 chunk_size: self.chunk_size,
56 iteration_order: self.iteration_order,
57 }
58 }
59
60 pub(crate) fn with_chunk_size(self, chunk_size: impl Into<ChunkSize>) -> Self {
61 Self {
62 num_threads: self.num_threads,
63 chunk_size: chunk_size.into(),
64 iteration_order: self.iteration_order,
65 }
66 }
67
68 pub(crate) fn with_collect_ordering(self, iteration_order: IterationOrder) -> Self {
69 Self {
70 num_threads: self.num_threads,
71 chunk_size: self.chunk_size,
72 iteration_order,
73 }
74 }
75}