Enum orx_parallel::NumThreads
source · pub enum NumThreads {
Auto,
Max(NonZeroUsize),
}
Expand description
NumThreads
represents the degree of parallelization. It is possible to define an upper bound on the number of threads to be used for the parallel computation.
When set to 1, the computation will be executed sequentially without any overhead.
In this sense, parallel iterators defined in this crate are a union of sequential and parallel execution.
§Rules of Thumb / Guidelines
It is recommended to set this parameter to its default value, NumThreads::Auto
.
This setting assumes that it can use all available threads; however, the computation will spawn new threads only when required.
In other words, when we can dynamically decide that the task is not large enough to justify spawning a new thread, the parallel execution will avoid it.
A special case is NumThreads::Max(NonZeroUsize::new(1).unwrap())
, or equivalently NumThreads::sequential()
.
This will lead to a sequential execution of the defined computation on the main thread.
Both in terms of used resources and computation time, this mode is not similar but identical to a sequential execution using the regular sequential Iterator
s.
Lastly, NumThreads::Max(t)
where t >= 2
can be used in the following scenarios:
- We have a strict limit on the resources that we can use for this computation, even if the hardware has more resources.
Parallel execution will ensure that
t
will never be exceeded. - We have a computation which is extremely time-critical and our benchmarks show that
t
outperforms theNumThreads::Auto
on the corresponding system.
Variants§
Auto
This setting assumes that it can use all available threads; however, the computation will spawn new threads only when required. In other words, when we can dynamically decide that the task is not large enough to justify spawning a new thread, the parallel execution will avoid it.
Max(NonZeroUsize)
Limits the maximum number of threads that can be used by the parallel execution.
A special case is NumThreads::Max(NonZeroUsize::new(1).unwrap())
, or equivalently NumThreads::sequential()
.
This will lead to a sequential execution of the defined computation on the main thread.
Both in terms of used resources and computation time, this mode is not similar but identical to a sequential execution using the regular sequential Iterator
s.
Lastly, NumThreads::Max(t)
where t >= 2
can be used in the following scenarios:
- We have a strict limit on the resources that we can use for this computation, even if the hardware has more resources.
Parallel execution will ensure that
t
will never be exceeded. - We have a computation which is extremely time-critical and our benchmarks show that
t
outperforms theNumThreads::Auto
on the corresponding system.
Implementations§
source§impl NumThreads
impl NumThreads
sourcepub fn sequential() -> Self
pub fn sequential() -> Self
Equivalent to NumThreads::Max(NonZeroUsize::new(1).unwrap())
.
This will lead to a sequential execution of the defined computation on the main thread.
Both in terms of used resources and computation time, this mode is not similar but identical to a sequential execution using the regular sequential Iterator
s.
Trait Implementations§
source§impl Clone for NumThreads
impl Clone for NumThreads
source§fn clone(&self) -> NumThreads
fn clone(&self) -> NumThreads
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for NumThreads
impl Debug for NumThreads
source§impl Default for NumThreads
impl Default for NumThreads
source§fn default() -> Self
fn default() -> Self
Default value for number of threads is NumThreads::Auto
.
source§impl From<usize> for NumThreads
impl From<usize> for NumThreads
source§impl PartialEq for NumThreads
impl PartialEq for NumThreads
impl Copy for NumThreads
impl Eq for NumThreads
impl StructuralPartialEq for NumThreads
Auto Trait Implementations§
impl Freeze for NumThreads
impl RefUnwindSafe for NumThreads
impl Send for NumThreads
impl Sync for NumThreads
impl Unpin for NumThreads
impl UnwindSafe for NumThreads
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)