You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to know if a parallel implementation of array::from_fn() could be added to rayon. If not, are there any ways to use it in a parallel manner with some lower level functions?
The text was updated successfully, but these errors were encountered:
Could you expand a bit on the use case you have for this? Arrays are usually relatively small so that parallelism wont help if the elements are cheap to compute. If the elements are indeed expensive to compute, I suspect the overhead of collecting a Vec and turning it into an array to be neglible.
Currently, I'm using a large 2 dimensional array as the main storage for my application. And, I frequently need to recompute the entire array. So I think it would be good to have a "nicer" way of doing this instead of collecting into a vec. (Especially when they're nested)
For 2d arrays, you will probably fare better with a serialized inner loop, unless the work is very imbalanced so you benefit from work-stealing. So you would be collecting Vec<[T; N]> or Box<[[T; N]]> with parallelism only on the outer index, then convert to a local array -- but it might be better to leave it on the heap anyway.
Another way to do it on the stack is to start with a MaybeUninit array, initialize it via par_iter_mut(), and then assume_init(). I think this is roughly what a native rayon::array::from_fn would do, but it gets tricky trying to ensure that drops happen if it's only partially initialized due to a panic. In your specific domain, you might be able to ignore that.
I would like to know if a parallel implementation of array::from_fn() could be added to rayon. If not, are there any ways to use it in a parallel manner with some lower level functions?
The text was updated successfully, but these errors were encountered: