Skip to content

Commit 6d43c13

Browse files
committed
FIX: In ParallelSplits, count maximum number of splits
Instead of requiring to use the size in elements of the thing-to-split, simply use a counter for the number of splits.
1 parent 4277296 commit 6d43c13

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

src/parallel/impl_par_methods.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ where
4545

4646
// Zip
4747

48-
const COLLECT_MAX_PARTS: usize = 256;
48+
const COLLECT_MAX_SPLITS: usize = 10;
4949

5050
macro_rules! zip_impl {
5151
($([$notlast:ident $($p:ident)*],)+) => {
@@ -92,7 +92,7 @@ macro_rules! zip_impl {
9292
ParallelSplits {
9393
iter: self.and(SendProducer::new(output.raw_view_mut().cast::<R>())),
9494
// Keep it from splitting the Zip down too small
95-
min_size: total_len / COLLECT_MAX_PARTS,
95+
max_splits: COLLECT_MAX_SPLITS,
9696
}
9797
};
9898

src/parallel/par.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ zip_impl! {
288288
/// or producer `P`.
289289
pub(crate) struct ParallelSplits<P> {
290290
pub(crate) iter: P,
291-
pub(crate) min_size: usize,
291+
pub(crate) max_splits: usize,
292292
}
293293

294294
impl<P> ParallelIterator for ParallelSplits<P>
@@ -313,17 +313,17 @@ impl<P> UnindexedProducer for ParallelSplits<P>
313313
type Item = P;
314314

315315
fn split(self) -> (Self, Option<Self>) {
316-
if self.iter.size() <= self.min_size || !self.iter.can_split() {
316+
if self.max_splits == 0 || !self.iter.can_split() {
317317
return (self, None)
318318
}
319319
let (a, b) = self.iter.split();
320320
(ParallelSplits {
321321
iter: a,
322-
min_size: self.min_size,
322+
max_splits: self.max_splits - 1,
323323
},
324324
Some(ParallelSplits {
325325
iter: b,
326-
min_size: self.min_size,
326+
max_splits: self.max_splits - 1,
327327
}))
328328
}
329329

src/split_at.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub(crate) trait SplitAt {
88

99
pub(crate) trait SplitPreference : SplitAt {
1010
fn can_split(&self) -> bool;
11-
fn size(&self) -> usize;
1211
fn split_preference(&self) -> (Axis, usize);
1312
fn split(self) -> (Self, Self) where Self: Sized {
1413
let (axis, index) = self.split_preference();

src/zip/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,6 @@ macro_rules! map_impl {
11261126
{
11271127
fn can_split(&self) -> bool { self.size() > 1 }
11281128

1129-
fn size(&self) -> usize { self.size() }
1130-
11311129
fn split_preference(&self) -> (Axis, usize) {
11321130
// Always split in a way that preserves layout (if any)
11331131
let axis = self.max_stride_axis();

0 commit comments

Comments
 (0)