4 ms·
Does Rust have a way to work with SIMD concurrency as opposed to just fork/join concurrency? Something along the lines of how openmp or cilk let you do a parall
by z1mm32m4n 11y ago
Does Rust have a way to work with SIMD concurrency as opposed to just fork/join concurrency? Something along the lines of how openmp or cilk let you do a parallel for all?
- fndjdh 11y agoYou seem to have concurrency confused with parallelism. Concurrency just means working on another task before the prior one has completed. You're describing parallelism which is doing multiple tasks at the same time.
- m0th87 11y agoParallelism necessarily implies concurrency [1] So, "SIMD concurrency" is not incorrect (although SIMD parallelism is more correct :) 1: http://programmers.stackexchange.com/a/155110 http://programmers.stackexchange.com/a/155110
- naasking 11y agoThis not true. CPUs have instruction parallelism, even on a single CPU, but there is no observable concurrency. SIMD is data-level parallelism, not concurrency.
- z1mm32m4n 11y agoBy SIMD concurrency, I meant that I was curious about a construct that actually translated into simultaneously executing code, not just a construct that denotes work that "could" be done simultaneously.
- Chilinot 11y agoA simple google search would have told you that there is work being done the introduce simd in Rust. There appear to be some basics there right now but not much if i understood my quick search.
- kbenson 11y agoAn active discussion about concurrency in rust with first developers commenting is a very appropriate place to ask that question, and ultimately much more likely to yield valid and current information than Google.
- Manishearth 11y agoRust 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)