-
Notifications
You must be signed in to change notification settings - Fork 431
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
Rayon and random number generator #398
Comments
I think the easiest way would be to get your handle to fn normal(mu:f64, sigma: &Vec<f64>) -> Vec<f64> {
let mut v = Vec::with_capacity(sigma.len());
(0..sigma)
.into_par_iter()
.map(|_| {
let mut rng = thread_rng();
let mut g = Normal::new(mu, sigma[i] ).unwrap();
g.ind_sample(&mut rng)
})
.collect_into_vec(&mut v);
v
} You may also want to move Actually I think this is an important scenario where we don't have a good solution yet. This works with What some solutions do is generate a vector of random numbers first, and then use those in Rayon's parallel iteration. But that does not work with the way most of our |
I think it would not be hard tot improve Rand for this use. We would have tot add a |
@pitdicker Thanks. your example did work and was able to reduce the time from 4 to 2 second. |
Nice 😄.
I have been playing some more with rayon yesterday, and now have a commit that adds basic support in pitdicker@a216bfa. It needs some cleaning up, but is an alternative to the thread-local trickery so that it can be used with normal PRNGs. |
Great addition @pitdicker! I think for now you might just as well do |
#399 is open; I think any further discussion can take place there. |
What is the best way to pass thread-safe/thread-local random number generator so we can execute
distribution
operation with multiple threads?e.g . How can I run below code to generate normal distribution in parallel using
rayon
or alternate way?I tried using below code but due to mutable rng, it is not allowed.
The text was updated successfully, but these errors were encountered: