Skip to content

Implement IndexedParallelIterator for one-dimensional arrays#815

Closed
bluss wants to merge 4 commits into
masterfrom
parallel-array-view-1d
Closed

Implement IndexedParallelIterator for one-dimensional arrays#815
bluss wants to merge 4 commits into
masterfrom
parallel-array-view-1d

Conversation

@bluss
Copy link
Copy Markdown
Member

@bluss bluss commented Apr 29, 2020

The rayon IndexedParallelIterator trait maps well to any one-dimensional indexed
sequence, and we can implement this trait as a special case (of the general
unindexed parallel iterator of an arbitrary array).

Implementing this is logical, it fits, but we still will recommend ndarray's Zip
for lock step iteration. The reason is performance. Zip will do it better.

bluss added 2 commits April 29, 2020 14:26
Impl this trait for 1D parallel iterators.

One piece is missing - opt_len - but it's mostly used for .collect()
optimization. We forgo this for now, because it would require some type
system delusion to conditionally call the right drive method inside
Parallel<ArrayView<..>>::drive_unindexed; conditional on if D is Ix1 or
not.
Comment thread src/parallel/par.rs

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
Copy link
Copy Markdown
Member Author

@bluss bluss Apr 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually reduces to the default iterator as a base case, that could be a regression in performance from currently (default iterator uses logical order - our par iters in general have benefitted from not having to guarantee a visit order)

Copy link
Copy Markdown
Member Author

@bluss bluss Apr 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visit order doesn't matter for 1D, only implementation quality (unless we count preferring forward over reverse, that is positive vs negative stride, and we don't have evidence for that).

Before, unindexed, we had the view's self.into_iter().fold(..) as the final step, using fold. In the new indexed case, we don't always access the iterator by using fold, and that's the possible quality problem.

bluss added 2 commits May 17, 2020 15:48
…tors

This enables the .collect() optimization in rayon. We implement the
necessary call to the indexed parallel iterator driver, for
one-dimensional array views.
When fold_with is used, use Zip::fold_while to fold the array view's
parallel iterator. Note that in some cases, the IntoIterator of
the view is used instead.
@bluss bluss force-pushed the parallel-array-view-1d branch from ef48aff to 21d59da Compare May 17, 2020 13:48
@bluss
Copy link
Copy Markdown
Member Author

bluss commented May 28, 2020

These implementations logically fit, but the performance of the enabled methods is not good - so not having these is a way to push users towards using ndarray::Zip for zipping and unordered parallel iterator methods anyway, which perform many times better.

@bluss bluss closed this May 28, 2020
@bluss bluss deleted the parallel-array-view-1d branch May 28, 2020 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant