pub struct ParallelExecutorWithDiagnostics<E>where
E: ParallelExecutor,{ /* private fields */ }Expand description
A parallel executor which wraps another parallel executor E and collects diagnostics about:
- how many threads are used for the parallel computation
- how many times each thread received a tasks
- average chunk size; i.e., average number of tasks, that each thread received
- and finally, explicit chunk sizes for the first task assignments.
The diagnostics are printed on the stdout once the parallel computation is completed. Therefore, this executor is suitable only for test purposed, but not for production.
Any executor can be converted into executor with diagnostics. In the example below, executor of the default runner is converted to executor with diagnostics.
§Examples
use orx_parallel::*;
// normal execution
let range = 0..4096;
let sum = range
.par()
.map(|x| x + 1)
.filter(|x| x.is_multiple_of(2))
.sum();
assert_eq!(sum, 4196352);
// execution with diagnostics
let range = 0..4096;
let sum = range
.par()
.with_runner(DefaultRunner::default().with_diagnostics())
.map(|x| x + 1)
.filter(|x| x.is_multiple_of(2))
.sum();
assert_eq!(sum, 4196352);
// prints diagnostics, which looks something like the following:
//
// - Number of threads used = 5
//
// - [Thread idx]: num_calls, num_tasks, avg_chunk_size, first_chunk_sizes
// - [0]: 25, 1600, 64, [64, 64, 64, 64, 64, 64, 64, 64, 64, 64]
// - [1]: 26, 1664, 64, [64, 64, 64, 64, 64, 64, 64, 64, 64, 64]
// - [2]: 13, 832, 64, [64, 64, 64, 64, 64, 64, 64, 64, 64, 64]
// - [3]: 0, 0, 0, []
// - [4]: 0, 0, 0, []Trait Implementations§
Source§impl<E> Clone for ParallelExecutorWithDiagnostics<E>where
E: ParallelExecutor + Clone,
impl<E> Clone for ParallelExecutorWithDiagnostics<E>where
E: ParallelExecutor + Clone,
Source§fn clone(&self) -> ParallelExecutorWithDiagnostics<E>
fn clone(&self) -> ParallelExecutorWithDiagnostics<E>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<E> ParallelExecutor for ParallelExecutorWithDiagnostics<E>where
E: ParallelExecutor,
impl<E> ParallelExecutor for ParallelExecutorWithDiagnostics<E>where
E: ParallelExecutor,
Data shared to the thread executors.
Source§type ThreadExecutor = ThreadExecutorWithDiagnostics<E>
type ThreadExecutor = ThreadExecutorWithDiagnostics<E>
Thread executor that is responsible for executing the tasks allocated to a thread.
Source§fn new(
kind: ComputationKind,
params: Params,
initial_input_len: Option<usize>,
max_num_threads: NonZeroUsize,
) -> Self
fn new( kind: ComputationKind, params: Params, initial_input_len: Option<usize>, max_num_threads: NonZeroUsize, ) -> Self
Creates a new parallel executor for the given computation
kind, parallelization params
and initial_input_len.Creates an initial shared state.
Source§fn do_spawn_new<I>(
&self,
num_spawned: NumSpawned,
shared_state: &Self::SharedState,
iter: &I,
) -> boolwhere
I: ConcurrentIter,
fn do_spawn_new<I>(
&self,
num_spawned: NumSpawned,
shared_state: &Self::SharedState,
iter: &I,
) -> boolwhere
I: ConcurrentIter,
Returns true if it is beneficial to spawn a new thread provided that: Read more
Source§fn new_thread_executor(
&self,
thread_idx: usize,
shared_state: &Self::SharedState,
) -> Self::ThreadExecutor
fn new_thread_executor( &self, thread_idx: usize, shared_state: &Self::SharedState, ) -> Self::ThreadExecutor
Creates a new thread executor provided that the current parallel execution state is
shared_state.Source§fn complete_task(self, shared_state: Self::SharedState)
fn complete_task(self, shared_state: Self::SharedState)
Executes the finalization tasks when the entire parallel computation is completed.
Auto Trait Implementations§
impl<E> Freeze for ParallelExecutorWithDiagnostics<E>where
E: Freeze,
impl<E> RefUnwindSafe for ParallelExecutorWithDiagnostics<E>where
E: RefUnwindSafe,
impl<E> Send for ParallelExecutorWithDiagnostics<E>where
E: Send,
impl<E> Sync for ParallelExecutorWithDiagnostics<E>
impl<E> Unpin for ParallelExecutorWithDiagnostics<E>where
E: Unpin,
impl<E> UnwindSafe for ParallelExecutorWithDiagnostics<E>where
E: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more