ParallelExecutor

Trait ParallelExecutor 

Source
pub trait ParallelExecutor:
    Sized
    + Sync
    + 'static
    + Clone {
    type SharedState: Send + Sync;
    type ThreadExecutor: ThreadExecutor<SharedState = Self::SharedState>;

    // Required methods
    fn new(
        kind: ComputationKind,
        params: Params,
        initial_input_len: Option<usize>,
        max_num_threads: NonZeroUsize,
    ) -> Self;
    fn new_shared_state(&self) -> Self::SharedState;
    fn do_spawn_new<I>(
        &self,
        num_spawned: NumSpawned,
        shared_state: &Self::SharedState,
        iter: &I,
    ) -> bool
       where I: ConcurrentIter;
    fn new_thread_executor(
        &self,
        thread_idx: usize,
        shared_state: &Self::SharedState,
    ) -> Self::ThreadExecutor;
    fn complete_task(self, shared_state: Self::SharedState);
}
Expand description

A parallel executor which is responsible for taking a computation defined as a composition of iterator methods, spawns threads, shares tasks and returns the result of the parallel execution.

Required Associated Types§

Source

type SharedState: Send + Sync

Data shared to the thread executors.

Source

type ThreadExecutor: ThreadExecutor<SharedState = Self::SharedState>

Thread executor that is responsible for executing the tasks allocated to a thread.

Required Methods§

Source

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.

Source

fn new_shared_state(&self) -> Self::SharedState

Creates an initial shared state.

Source

fn do_spawn_new<I>( &self, num_spawned: NumSpawned, shared_state: &Self::SharedState, iter: &I, ) -> bool
where I: ConcurrentIter,

Returns true if it is beneficial to spawn a new thread provided that:

  • num_spawned threads are already been spawned, and
  • shared_state is the current parallel execution state.
Source

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)

Executes the finalization tasks when the entire parallel computation is completed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<E> ParallelExecutor for ParallelExecutorWithDiagnostics<E>

Source§

type SharedState = SharedStateWithDiagnostics<<E as ParallelExecutor>::SharedState>

Source§

type ThreadExecutor = ThreadExecutorWithDiagnostics<E>