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§
Sourcetype Pool: ThreadPool
type Pool: ThreadPool
Underlying thread pool.
Sourcetype ChunkState
type ChunkState
State local to a chunk, created when the chunk begins and consumed when it completes.
Required Methods§
Sourcefn do_spawn_new(spawned: usize, state: &Self::State) -> Option<usize>
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.
Sourcefn new_state(
&mut self,
params: Params,
max_num_threads: usize,
size_hint: (usize, Option<usize>),
) -> Self::State
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.
Sourcefn configure_for_serialized_input(
state: &mut Self::State,
size_hint: (usize, Option<usize>),
)
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.
Sourcefn begin_thread(state: &Self::State, th_idx: usize)
fn begin_thread(state: &Self::State, th_idx: usize)
Called when a worker thread begins processing the computation.
Sourcefn next_chunk_size(
state: &Self::State,
size_hint: (usize, Option<usize>),
) -> usize
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.
Sourcefn begin_chunk(th_idx: usize, chunk_size: usize) -> Self::ChunkState
fn begin_chunk(th_idx: usize, chunk_size: usize) -> Self::ChunkState
Creates state for a chunk before its items are processed.
Sourcefn complete_chunk(state: &Self::State, chunk_state: Self::ChunkState)
fn complete_chunk(state: &Self::State, chunk_state: Self::ChunkState)
Called when a chunk completes, with the state returned by Self::begin_chunk.
Sourcefn complete_thread(state: &Self::State, th_idx: usize)
fn complete_thread(state: &Self::State, th_idx: usize)
Called when a worker thread finishes processing the computation.
Sourcefn complete_computation(state: Self::State)
fn complete_computation(state: Self::State)
Called after all worker threads finish, consuming the shared computation state.
Provided Methods§
Sourcefn with_diagnostics(self) -> WithDiagnostics<Self>
fn with_diagnostics(self) -> WithDiagnostics<Self>
Wraps this runner to print diagnostics about thread usage and chunk sizes (std only).
Sourcefn nt_state(
&mut self,
params: Params,
is_source_serialized: bool,
size_hint: (usize, Option<usize>),
computation_max_nt: Option<usize>,
) -> (usize, Self::State)
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.
Sourcefn broadcast_stop<I: ConcurrentIter>(
iter: &I,
state: &Self::State,
chunk_state: Self::ChunkState,
)
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".