pub trait ParallelRunner: Sized + Sync {
type SharedState: Send + Sync;
type ThreadRunner: ThreadRunner<SharedState = Self::SharedState>;
// Required methods
fn new(
kind: ComputationKind,
params: Params,
initial_input_len: Option<usize>,
) -> Self;
fn new_shared_state(&self) -> Self::SharedState;
fn do_spawn_new<I>(
&self,
num_spawned: usize,
shared_state: &Self::SharedState,
iter: &I,
) -> bool
where I: ConcurrentIter;
fn new_thread_runner(
&self,
shared_state: &Self::SharedState,
) -> Self::ThreadRunner;
}
Expand description
A parallel runner 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§
Data shared to the thread runners.
Sourcetype ThreadRunner: ThreadRunner<SharedState = Self::SharedState>
type ThreadRunner: ThreadRunner<SharedState = Self::SharedState>
Thread runner that is responsible for executing the tasks allocated to a thread.
Required Methods§
Sourcefn new(
kind: ComputationKind,
params: Params,
initial_input_len: Option<usize>,
) -> Self
fn new( kind: ComputationKind, params: Params, initial_input_len: Option<usize>, ) -> Self
Creates a new parallel runner for the given computation kind
, parallelization params
and initial_input_len
.
Creates an initial shared state.
Sourcefn do_spawn_new<I>(
&self,
num_spawned: usize,
shared_state: &Self::SharedState,
iter: &I,
) -> boolwhere
I: ConcurrentIter,
fn do_spawn_new<I>(
&self,
num_spawned: usize,
shared_state: &Self::SharedState,
iter: &I,
) -> boolwhere
I: ConcurrentIter,
Returns true if it is beneficial to spawn a new thread provided that:
num_spawned
threads are already been spawned, andshared_state
is the current parallel execution state.
Sourcefn new_thread_runner(
&self,
shared_state: &Self::SharedState,
) -> Self::ThreadRunner
fn new_thread_runner( &self, shared_state: &Self::SharedState, ) -> Self::ThreadRunner
Creates a new thread runner provided that the current parallel execution state is
shared_state
.
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.