-
Notifications
You must be signed in to change notification settings - Fork 501
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
Usage with “Read” or “Iterator” as provider? #46
Comments
Well, right now there isn't really a much better way (though you could handwrite a recursive function with |
This seems like a fairly popular feature judging on the number of issues people have created that are slight variations on this general My particular use case is that I've got an iterator which yields every permutation of 4 numbers from 18 to 200 (around 167,961,600,000,000 permutations), then does a bunch of filters and maps to find a bunch of "ideal" combinations. In this case it's not feasible to save the combinations into a |
It's a popular request, but there's not an obvious way to implement it. We've had a few ideas, but not any progress to report for it, sadly.
Perhaps I misunderstand, but wouldn't the number of permutations be (200-18)4 -- roughly 109? If you can set up that generator with ranges, you can parallelize that.
Another strategy is batch this work. Generate a manageable amount into a |
I'm using Rayon to parallelise a fairly CPU heavy operation on a bunch of Would a generic solution be to allow Rayon to (I'm fairly new to Rust, so apologies if I'm missing something and this is not actually easier than just supporting |
@grahame See also https://github.com/QuietMisdreavus/polyester, but I'm not sure that the cost of allocating |
550: add bridge from Iterator to ParallelIterator r=cuviper a=QuietMisdreavus Half of #46 This started getting reviewed in QuietMisdreavus/polyester#6, but i decided to move my work to Rayon proper. This PR adds a new trait, `AsParallel`, an implementation on `Iterator + Send`, and an iterator adapter `IterParallel` that implements `ParallelIterator` with a similar "cache items as you go" methodology as Polyester. I introduced a new trait because `ParallelIterator` was implemented on `Range`, which is itself an `Iterator`. The basic idea is that you would start with a quick sequential `Iterator`, call `.as_parallel()` on it, and be able to use `ParallelIterator` adapters after that point, to do more expensive processing in multiple threads. The design of `IterParallel` is like this: * `IterParallel` defers background work to `IterParallelProducer`, which implements `UnindexedProducer`. * `IterParallelProducer` will split as many times as there are threads in the current pool. (I've been told that #492 is a better way to organize this, but until that's in, this is how i wrote it. `>_>`) * When folding items, `IterParallelProducer` keeps a `Stealer` from `crossbeam-deque` (added as a dependency, but using the same version as `rayon-core`) to access a deque of items that have already been loaded from the iterator. * If the `Stealer` is empty, a worker will attempt to lock the Mutex to access the source `Iterator` and the `Deque`. * If the Mutex is already locked, it will call `yield_now`. The implementation in polyester used a `synchronoise::SignalEvent` but i've been told that worker threads should not block. In lieu of #548, a regular spin-loop was chosen instead. * If the Mutex is available, the worker will load a number of items from the iterator (currently (number of threads * number of threads * 2)) before closing the Mutex and continuing. * (If the Mutex is poisoned, the worker will just... stop. Is there a recommended approach here? `>_>`) This design is effectively a first brush, has [the same caveats as polyester](https://docs.rs/polyester/0.1.0/polyester/trait.Polyester.html#implementation-note), probably needs some extra features in rayon-core, and needs some higher-level docs before i'm willing to let it go. However, i'm putting it here because it was not in the right place when i talked to @cuviper about it last time. Co-authored-by: QuietMisdreavus <grey@quietmisdreavus.net> Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
It looks like this is still open as #550 which added |
Yes, I think it's fair to say that |
I see that only ranges and slices can be converted into parallel iterators.
i wonder how to best utilize rayon while reading from a file.
ATM I read files into buffers, then parse them using an iterator. i imagine there’s a better way to use rayon than:
The text was updated successfully, but these errors were encountered: