Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection method for associative, but not commutative, reductions #132

Closed
mathstuf opened this issue Nov 3, 2016 · 8 comments
Closed

Comments

@mathstuf
Copy link

mathstuf commented Nov 3, 2016

Not sure how possible this is, but I'd like to be able to use parallel iterators with non-commutative reduction functions (e.g., collecting error messages in a deterministic order).

Maybe best to use .enumerate() and .sort() a Vec populated by the parallel iterator?

@cuviper
Copy link
Member

cuviper commented Nov 3, 2016

I don't know if it's promised, but the current implementation should actually preserve order in the reductions, just with associative differences as you note. This is a natural implication of the way the jobs are split recursively and then joined as it returns.

@nikomatsakis
Copy link
Member

I believe that in https://github.com/nikomatsakis/rayon/pull/120 I went ahead and promised that the order would be deterministic when doing reduce or fold.

@cuviper
Copy link
Member

cuviper commented Nov 4, 2016

Hmm, the new reduce says just associative, but reduce_with still says commutative too. Then sum, mul, min, and max all mention commutative operators.

@nikomatsakis
Copy link
Member

@cuviper well-- consistency is a lot to ask =)

In any case, I feel all right about just requiring associativity.

@mathstuf
Copy link
Author

Are there tests for just-associative reduction functions (String::push?) already?

@cuviper
Copy link
Member

cuviper commented Apr 13, 2017

Using collect into any of the ordered collections will exercise associative non-commutative reduce. Look at their FromParallelIterator implementations.

Any further question about this? Otherwise, I think we can close this issue.

@mathstuf
Copy link
Author

Yeah, the issue can likely be closed. I was more wondering whether there were tests to this effect rather than "well, the implementation works that way".

@cuviper
Copy link
Member

cuviper commented Apr 13, 2017

Ok, I don't think we have any plain mathematical tests of this, but all of the collection and string stuff mandates that it works this way. Also, find_first et al. would make no sense if we didn't maintain order.

@cuviper cuviper closed this as completed Apr 13, 2017
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

No branches or pull requests

3 participants