-
-
Notifications
You must be signed in to change notification settings - Fork 4
Recursive Parallel Iteration #120
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…tics without diagnostics yet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Recursive Parallel Iterators
IntoParIterRec trait can be used to create a parallel recursive iterator over an initial set of elements which is useful when working with non-linear data structures such as trees and graphs.
Consider, for instance, a tree which is defined by the following node struct:
Assume that we want to map all the data with
map: impl Fn(T) -> u64and compute the sum of mapped values of all nodes descending from aroot: &Node.We can express this computation and execute in parallel with the following:
Instead of
into_par, we useinto_par_recand provideextendfunction as its argument. This function defines the recursive extension of the parallel iterator such that every time we process anodewe first add its children to thequeue.Queueis the queue of elements to be processed and it exposes two growth methods to define the recursive extension:pushandextend.Although we create the parallel iterator differently, we get a
ParIter. Therefore, we have access to all features of a regular parallel iterator.For instance, assume we want to filter nodes first. Further, instead of summing up the mapped values, we need to collect them in a vector. We can express this computation just as we would do on a linear data structure:
For more details, you may see the parallelization_on_tree example.
Diagnostics
ParallelExecutorWithDiagnosticsexecutor is created. Any parallel executor can be converted into one with diagnostics. This executor is meant to be used for testing parallel computations and understand the distribution of the workload to threads. During the parallel computation, it collects diagnostics about:These metrics are printed on the stdout once the parallel computation is completed. Therefore, it is not meant to be used for production.
Running a parallel computation with diagnostics is convenient.
Related Issues
Not exactly fixes but provides a solution to #104 with probably a different approach than intended. Please also see the related computation experiments.
edit after second iteration
Fixes #104
Thanks to @davidlattimore for suggestions and feedback on the api.