2 ms·
Rust supports SIMD, with some utility structs that let you do it easily. I don't know of any libraries that auto-simd things though IIRC LLVM can do this on its
by Manishearth 11y ago
Rust supports SIMD, with some utility structs that let you do it easily. I don't know of any libraries that auto-simd things though IIRC LLVM can do this on its own sometimes.
- alkonaut 11y agoI think the parent was referring to "lightweight task"-based concurrency like C#'s PLinq: // C# int sum; Parallel.ForEach(myCollection, item => sum += item); Which operates using a reasonably sized thread pool rather than a thread per item. Something similar in Rust (Excuse my rusty rust) would look like. let someList = ... parallel::for(someList.iter(), |item| { // Do thing with each item }; I think there is ongoing work on this topic, but it will likely only be library-level and not language-level (Just like Linq is a language level feature in C# but PLinq is a library). There are some third party crates that do this like simple_parallel. Edit: Low-level simd exist as intrinsics and of course through llvm vectorizations.
- grayrest 11y agoThe simplest library for this kind of data parallelism is Rayon[1]. The README provides a nice overview and links to a series of blog posts about the details. [1] https://github.com/nikomatsakis/rayon/ https://github.com/nikomatsakis/rayon/
- Manishearth 11y agosimple_parallel exists and is pretty neat, yes. Rayon is another cool library here (https://github.com/nikomatsakis/rayon https://github.com/nikomatsakis/rayon), which lets you do foreach/mapreduce operations via work stealing on a pool with an extensible API that looks exactly like the regular iterator api (https://github.com/nikomatsakis/rayon#parallel-iterators https://github.com/nikomatsakis/rayon#parallel-iterators, for example). Note that a simd library exists which abstracts over the intrinsics (https://github.com/huonw/simd https://github.com/huonw/simd)