-
Notifications
You must be signed in to change notification settings - Fork 487
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
Parallel processing of indexed for loops #67
Comments
Something like this ought to do it: (1..g.width() - 1)
.into_par_iter()
.flat_map(|i| (1..g.height() - 1).into_par_iter().map(|j| (i, j)))
.map(|(i, j)| ... processing ...) though I'd like to add a |
I tried your example and simplified it a bit, but it gives me a lifetime error (I'm still really bad at resolving those). This is my code: (1..1000usize)
.into_par_iter()
.flat_map(|x| (1..2000usize).into_par_iter().map(|y| (x, y)))
.map(|(x, y)| {
println!("{}, {}", x, y);
}); And this is the error:
Any idea how to resolve this? |
Try: |
facepalm . That fixed it, thank you! |
Another question just came up: Assuming I had some more work to do in the outer loop, how would I do this with rayon? Example:
|
Depends on what sort of processing you're hoping for. You could transcribe that more literally like:
But remember those closures have to be |
As @cuviper said, something like: (1..g.width() - 1).into_par_iter().for_each(|i| {
let mut intermediate_result = vec![];
(1..g.height() - 1).into_par_iter().map(|j| ...).collect_into(&mut intermediate_result);
process(intermediate_result);
}); might be what you are looking for. |
Exactly what I was looking for, thanks for your help guys! |
Great :) |
Is there any way to add parallelism with rayons to loops that look like this:
I do not even know if this would be possible in theory, but very helpful for some problems.
The text was updated successfully, but these errors were encountered: