Trait rayon::par_iter::ParallelIterator
[−]
[src]
pub trait ParallelIterator: Sized { type Item: Send; fn weight(self, scale: f64) -> Weight<Self> { ... } fn weight_max(self) -> Weight<Self> { ... } fn for_each<OP>(self, op: OP) where OP: Fn(Self::Item) + Sync { ... } fn map<MAP_OP, R>(self, map_op: MAP_OP) -> Map<Self, MAP_OP> where MAP_OP: Fn(Self::Item) -> R { ... } fn filter<FILTER_OP>(self, filter_op: FILTER_OP) -> Filter<Self, FILTER_OP> where FILTER_OP: Fn(&Self::Item) -> bool { ... } fn filter_map<FILTER_OP, R>(self, filter_op: FILTER_OP) -> FilterMap<Self, FILTER_OP> where FILTER_OP: Fn(Self::Item) -> Option<R> { ... } fn flat_map<MAP_OP, PI>(self, map_op: MAP_OP) -> FlatMap<Self, MAP_OP> where MAP_OP: Fn(Self::Item) -> PI, PI: ParallelIterator { ... } fn reduce_with<OP>(self, op: OP) -> Option<Self::Item> where OP: Fn(Self::Item, Self::Item) -> Self::Item + Sync { ... } fn reduce_with_identity<OP>(self, identity: Self::Item, op: OP) -> Self::Item where OP: Fn(Self::Item, Self::Item) -> Self::Item + Sync, Self::Item: Clone + Sync { ... } fn sum(self) -> Self::Item where SumOp: ReduceOp<Self::Item> { ... } fn mul(self) -> Self::Item where MulOp: ReduceOp<Self::Item> { ... } fn min(self) -> Self::Item where MinOp: ReduceOp<Self::Item> { ... } fn max(self) -> Self::Item where MaxOp: ReduceOp<Self::Item> { ... } fn reduce<REDUCE_OP>(self, reduce_op: &REDUCE_OP) -> Self::Item where REDUCE_OP: ReduceOp<Self::Item> { ... } }
The ParallelIterator
interface.
Associated Types
Provided Methods
fn weight(self, scale: f64) -> Weight<Self>
Indicates the relative "weight" of producing each item in this
parallel iterator. A higher weight will cause finer-grained
parallel subtasks. 1.0 indicates something very cheap and
uniform, like copying a value out of an array, or computing x + 1
. If your tasks are either very expensive, or very
unpredictable, you are better off with higher values. See also
weight_max
, which is a convenient shorthand to force the
finest grained parallel execution posible. Tuning this value
should not affect correctness but can improve (or hurt)
performance.
fn weight_max(self) -> Weight<Self>
Shorthand for self.weight(f64::INFINITY)
. This forces the
smallest granularity of parallel execution, which makes sense
when your parallel tasks are (potentially) very expensive to
execute.
fn for_each<OP>(self, op: OP) where OP: Fn(Self::Item) + Sync
Executes OP
on each item produced by the iterator, in parallel.
fn map<MAP_OP, R>(self, map_op: MAP_OP) -> Map<Self, MAP_OP> where MAP_OP: Fn(Self::Item) -> R
Applies map_op
to each item of his iterator, producing a new
iterator with the results.
fn filter<FILTER_OP>(self, filter_op: FILTER_OP) -> Filter<Self, FILTER_OP> where FILTER_OP: Fn(&Self::Item) -> bool
Applies map_op
to each item of his iterator, producing a new
iterator with the results.
fn filter_map<FILTER_OP, R>(self, filter_op: FILTER_OP) -> FilterMap<Self, FILTER_OP> where FILTER_OP: Fn(Self::Item) -> Option<R>
Applies map_op
to each item of his iterator, producing a new
iterator with the results.
fn flat_map<MAP_OP, PI>(self, map_op: MAP_OP) -> FlatMap<Self, MAP_OP> where MAP_OP: Fn(Self::Item) -> PI, PI: ParallelIterator
Applies map_op
to each item of his iterator, producing a new
iterator with the results.
fn reduce_with<OP>(self, op: OP) -> Option<Self::Item> where OP: Fn(Self::Item, Self::Item) -> Self::Item + Sync
Reduces the items in the iterator into one item using op
.
See also sum
, mul
, min
, etc, which are slightly more
efficient. Returns None
if the iterator is empty.
Note: unlike in a sequential iterator, the order in which op
will be applied to reduce the result is not specified. So op
should be commutative and associative or else the results will
be non-deterministic.
fn reduce_with_identity<OP>(self, identity: Self::Item, op: OP) -> Self::Item where OP: Fn(Self::Item, Self::Item) -> Self::Item + Sync, Self::Item: Clone + Sync
Reduces the items in the iterator into one item using op
.
The argument identity
represents an "identity" value which
may be inserted into the sequence as needed to create
opportunities for parallel execution. So, for example, if you
are doing a summation, then identity
ought to be something
that represents the zero for your type (but consider just
calling sum()
in that case).
Example vectors.par_iter().reduce_with_identity(Vector::zero(), Vector::add)
.
Note: unlike in a sequential iterator, the order in which op
will be applied to reduce the result is not specified. So op
should be commutative and associative or else the results will
be non-deterministic. And of course identity
should be a
true identity.
fn sum(self) -> Self::Item where SumOp: ReduceOp<Self::Item>
Sums up the items in the iterator.
Note that the order in items will be reduced is not specified,
so if the +
operator is not truly commutative and
associative (as is the case for floating point numbers), then
the results are not fully deterministic.
fn mul(self) -> Self::Item where MulOp: ReduceOp<Self::Item>
Multiplies all the items in the iterator.
Note that the order in items will be reduced is not specified,
so if the *
operator is not truly commutative and
associative (as is the case for floating point numbers), then
the results are not fully deterministic.
fn min(self) -> Self::Item where MinOp: ReduceOp<Self::Item>
Computes the minimum of all the items in the iterator.
Note that the order in items will be reduced is not specified,
so if the Ord
impl is not truly commutative and associative
(as is the case for floating point numbers), then the results
are not deterministic.
fn max(self) -> Self::Item where MaxOp: ReduceOp<Self::Item>
Computes the maximum of all the items in the iterator.
Note that the order in items will be reduced is not specified,
so if the Ord
impl is not truly commutative and associative
(as is the case for floating point numbers), then the results
are not deterministic.
fn reduce<REDUCE_OP>(self, reduce_op: &REDUCE_OP) -> Self::Item where REDUCE_OP: ReduceOp<Self::Item>
Reduces the items using the given "reduce operator". You may
prefer reduce_with
for a simpler interface.
Note that the order in items will be reduced is not specified,
so if the reduce_op
impl is not truly commutative and
associative, then the results are not deterministic.
Implementors
impl<M> ParallelIterator for Enumerate<M> where M: IndexedParallelIterator
impl<M, FILTER_OP> ParallelIterator for Filter<M, FILTER_OP> where M: ParallelIterator, FILTER_OP: Fn(&M::Item) -> bool + Sync
impl<M, FILTER_OP, R> ParallelIterator for FilterMap<M, FILTER_OP> where M: ParallelIterator, FILTER_OP: Fn(M::Item) -> Option<R> + Sync, R: Send
impl<M, MAP_OP, PI> ParallelIterator for FlatMap<M, MAP_OP> where M: ParallelIterator, MAP_OP: Fn(M::Item) -> PI + Sync, PI: ParallelIterator
impl<'data, T: Sync + 'data> ParallelIterator for SliceIter<'data, T>
impl<'data, T: Send + 'data> ParallelIterator for SliceIterMut<'data, T>
impl<M, MAP_OP, R> ParallelIterator for Map<M, MAP_OP> where M: ParallelIterator, MAP_OP: Fn(M::Item) -> R + Sync, R: Send
impl<M> ParallelIterator for Weight<M> where M: ParallelIterator
impl<A, B> ParallelIterator for ZipIter<A, B> where A: IndexedParallelIterator, B: IndexedParallelIterator
impl ParallelIterator for RangeIter<u8>
impl ParallelIterator for RangeIter<u16>
impl ParallelIterator for RangeIter<u32>
impl ParallelIterator for RangeIter<usize>
impl ParallelIterator for RangeIter<i8>
impl ParallelIterator for RangeIter<i16>
impl ParallelIterator for RangeIter<i32>
impl ParallelIterator for RangeIter<isize>
impl<T: Send> ParallelIterator for VecIter<T>