Skip to main content

ParRunner

Trait ParRunner 

Source
pub trait ParRunner: Sized + Sync {
    type Pool: ThreadPool;
    type State: Send + Sync;
    type ChunkState;

Show 14 methods // Required methods fn pool(&self) -> &Self::Pool; fn pool_mut(&mut self) -> &mut Self::Pool; fn do_spawn_new(spawned: usize, state: &Self::State) -> Option<usize>; fn new_state( &mut self, params: Params, max_num_threads: usize, size_hint: (usize, Option<usize>), ) -> Self::State; fn configure_for_serialized_input( state: &mut Self::State, size_hint: (usize, Option<usize>), ); fn begin_thread(state: &Self::State, th_idx: usize); fn next_chunk_size( state: &Self::State, size_hint: (usize, Option<usize>), ) -> usize; fn begin_chunk(th_idx: usize, chunk_size: usize) -> Self::ChunkState; fn complete_chunk(state: &Self::State, chunk_state: Self::ChunkState); fn complete_thread(state: &Self::State, th_idx: usize); fn complete_computation(state: Self::State); // Provided methods fn with_diagnostics(self) -> WithDiagnostics<Self> { ... } fn nt_state( &mut self, params: Params, is_source_serialized: bool, size_hint: (usize, Option<usize>), computation_max_nt: Option<usize>, ) -> (usize, Self::State) { ... } fn broadcast_stop<I: ConcurrentIter>( iter: &I, state: &Self::State, chunk_state: Self::ChunkState, ) { ... }
}
Expand description

Controls how parallel computations are divided into chunks and run on a thread pool.

Required Associated Types§

Source

type Pool: ThreadPool

Underlying thread pool.

Source

type State: Send + Sync

Parallel computation state that is shared among thread computations.

Source

type ChunkState

State local to a chunk, created when the chunk begins and consumed when it completes.

Required Methods§

Source

fn pool(&self) -> &Self::Pool

Reference to the underlying thread pool.

Source

fn pool_mut(&mut self) -> &mut Self::Pool

Mutable reference to the underlying thread pool.

Source

fn do_spawn_new(spawned: usize, state: &Self::State) -> Option<usize>

Returns Some of the index of the new thread if it is beneficial to spawn a new thread for the remaining computation; it returns None otherwise.

Since this method is called sequentially, returned value will always be Some(spawned) if it returns some.

Source

fn new_state( &mut self, params: Params, max_num_threads: usize, size_hint: (usize, Option<usize>), ) -> Self::State

Creates an initial state for a new parallel computation.

Source

fn configure_for_serialized_input( state: &mut Self::State, size_hint: (usize, Option<usize>), )

Adjusts runner state for an input source that is consumed serially.

Source

fn begin_thread(state: &Self::State, th_idx: usize)

Called when a worker thread begins processing the computation.

Source

fn next_chunk_size( state: &Self::State, size_hint: (usize, Option<usize>), ) -> usize

Returns the next chunk size to be pulled from the input with remaining length provided by the size_hint for the current state.

Source

fn begin_chunk(th_idx: usize, chunk_size: usize) -> Self::ChunkState

Creates state for a chunk before its items are processed.

Source

fn complete_chunk(state: &Self::State, chunk_state: Self::ChunkState)

Called when a chunk completes, with the state returned by Self::begin_chunk.

Source

fn complete_thread(state: &Self::State, th_idx: usize)

Called when a worker thread finishes processing the computation.

Source

fn complete_computation(state: Self::State)

Called after all worker threads finish, consuming the shared computation state.

Provided Methods§

Source

fn with_diagnostics(self) -> WithDiagnostics<Self>

Wraps this runner to print diagnostics about thread usage and chunk sizes (std only).

Source

fn nt_state( &mut self, params: Params, is_source_serialized: bool, size_hint: (usize, Option<usize>), computation_max_nt: Option<usize>, ) -> (usize, Self::State)

Creates computation state and returns the effective thread limit with that state.

Applies the pool limit and any per-computation limit, then configures the state for serialized input when needed.

Source

fn broadcast_stop<I: ConcurrentIter>( iter: &I, state: &Self::State, chunk_state: Self::ChunkState, )

Exhausts the iterator and completes the active chunk when processing stops early.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<P: ParRunner> ParRunner for &mut P

Source§

type Pool = <P as ParRunner>::Pool

Source§

type State = <P as ParRunner>::State

Source§

type ChunkState = <P as ParRunner>::ChunkState

Source§

fn pool(&self) -> &Self::Pool

Source§

fn pool_mut(&mut self) -> &mut Self::Pool

Source§

fn do_spawn_new(spawned: usize, state: &Self::State) -> Option<usize>

Source§

fn new_state( &mut self, params: Params, max_num_threads: usize, size_hint: (usize, Option<usize>), ) -> Self::State

Source§

fn begin_thread(state: &Self::State, th_idx: usize)

Source§

fn next_chunk_size( state: &Self::State, size_hint: (usize, Option<usize>), ) -> usize

Source§

fn begin_chunk(th_idx: usize, chunk_size: usize) -> Self::ChunkState

Source§

fn complete_chunk(state: &Self::State, chunk_state: Self::ChunkState)

Source§

fn complete_thread(state: &Self::State, th_idx: usize)

Source§

fn complete_computation(state: Self::State)

Source§

fn configure_for_serialized_input( state: &mut Self::State, size_hint: (usize, Option<usize>), )

Implementors§