6 ms·
While Rust doesn't promote a specific model for parallelism, it's stronger compiler helps a lot with that. https://doc.rust-lang.org/beta/nomicon/concurrency.h
by madez 9y ago
While Rust doesn't promote a specific model for parallelism, it's stronger compiler helps a lot with that.
https://doc.rust-lang.org/beta/nomicon/concurrency.html https://doc.rust-lang.org/beta/nomicon/concurrency.html
https://doc.rust-lang.org/book/second-edition/ch16-01-threads.html https://doc.rust-lang.org/book/second-edition/ch16-01-thread...
I don't think fixing C(++) can give what Rust can give, because Rust has a clean start with these strong guarantees built-in while for C(++) it would always be an addon. Defaults are powerful.
- beojan 9y agoC++ has parallel algorithms built in (http://en.cppreference.com/w/cpp/algorithm http://en.cppreference.com/w/cpp/algorithm). Parallelism is complicated though, and easy parallelism pretty much requires a functional style. Things like Haskell's Accelerate library (https://www.stackage.org/package/accelerate https://www.stackage.org/package/accelerate) seem the ideal way forward to me.
- smitherfield 9y agoShould be noted that so far only Visual Studio (partially) implements C++17 parallel algorithms, although there are several third-party implementations.[1] Apples to oranges comparison of course, since Rayon isn't [planned to become?] part of the Rust standard library. [1] http://www.bfilipek.com/2017/08/cpp17-details-parallel.html#current-implementation http://www.bfilipek.com/2017/08/cpp17-details-parallel.html#...
- beojan 9y agoIf you're including third-party libraries, you have things like ArrayFire and Intel TBB.
- chrismorgan 9y agoA really powerful outworking of it is seen in the Rayon crate, where you can change a sequential iterator into a parallel iterator just by adding the crate, importing the trait and changing `iter` to `par_iter`. If it’s not thread-safe to do, then it won’t compile. (That’s the big difference from C++.) If it is, it will, and it’ll be smart about how it runs, spreading the load across all available cores pretty much optimally, or not bothering with multiple threads if it’s not going to be worth it (e.g. single-threaded, or only one item in the iterator). And all that with close enough to no overhead. Basically, Rayon makes data parallelism really easy in a way that few if any other languages do. I’d love to have an equivalent in Python or Node, but it’s just not possible to achieve such a thing in most languages—even if you ignore the thread safety aspect. Parallelism hasn’t seen a great deal of use until it’s urgently needed, because it’s hard to get right in most environments, and you normally need to substantially refactor code to make it happen. My hope is that with the likes of Rayon, parallelism can be a much more natural thing that people that care even a little about performance will just do, because it’s so easy to do. https://crates.io/crates/rayon https://crates.io/crates/rayon
- pjmlp 9y ago> Parallelism hasn’t seen a great deal of use until it’s urgently needed This is the main reason why, initially, Windows Store APIs were all async. Microsoft learned that when developers can choose between both models, by default most chose synch models.
- ethagnawl 9y agoFWIW, you can also achieve similar behavior in Clojure via pmap, Reducers, etc.
- floatboth 9y agoAnd in Haskell https://www.stackage.org/haddock/lts-10.6/parallel-3.2.1.1/Control-Parallel-Strategies.html https://www.stackage.org/haddock/lts-10.6/parallel-3.2.1.1/C... And in .NET https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.parallel?view=netframework-4.7.1 https://docs.microsoft.com/en-us/dotnet/api/system.threading... And in Java https://blog.oio.de/2016/01/22/parallel-stream-processing-in-java-8-performance-of-sequential-vs-parallel-stream-processing/ https://blog.oio.de/2016/01/22/parallel-stream-processing-in... Rayon is notable because Rust is a native-compiled, no-GC language.
- brazzy 9y agoTo me, the "If it’s not thread-safe to do, then it won’t compile" part sounds rather more notable.
- coolsunglasses 9y agoThat's true of Haskell for the parallelism faculties. It's also true for STM. You can still get stuck or have race conditions with the other concurrency abstractions but it's less common than I encountered elsewhere. I didn't have problems resulting from mutable shared state that was aliased across threads and wasn't supposed to be, it's always explicit.
- mitchtbaum 9y ago
- ilogik 9y agoDoesn't go also make it relatively easy to write parallel code?
- ztoben 9y agoI believe you're thinking of concurrency, which go handles pretty well with goroutines.
- icedchai 9y agoGo can use multiple cores. Goroutines will run in parallel (assuming GOMAXPROCS > 1.)
- gameswithgo 9y agoNot especially. It has goroutines, C# has Tasks, C++ has green thread libraries. Added onto this are channels which are basically thread safe queues, other languages have those too. (I am aware that there are differences between what features goroutines and Tasks provides) Go's implementation of these things is nice, neat, and all included out of the box though which is nice. In general you can make parallelism easy, or efficient, rarely both, at least not in a way that can solve problems generally. edit: I should add Go does also come with a data-race detection tool which can be very useful. Not sure any other language includes that out of the box!
- Thaxll 9y agoExcept in other languages it's not part of the core, it's an external library. So on the end it's easy to write "parallel" code.
- gameswithgo 9y agoIn C#, Task is part of the language, thread safe queues are part of the core libs. Still not quite as tightly integrated as Go though.
- burntsushi 9y ago
- Bitcoin_McPonzi 9y agoIt seems like every thread here, not matter what the topic, brings out the Rust astroturfers.
- gilrain 9y agoAs someone who frequently posts about my personally-excellent experiences with Rust, what makes you suspect it's astroturf rather than just turf? You think Mozilla is paying people to post about Rust using puppet accounts? C'mon.
- arbie 9y agoIt does seem a little odd that every comment about Rust gushes about its progress and stability without discussing any downsides. One would be similarly suspicious if, e.g., Perl6 were discussed this way.
- chillee 9y agoThat's what happens when you have a new hip language/framework that has a lot of hype. You see the same with Rust, Elixir, VSCode, Elm, Purescript, ReasonML, etc. It's not astroturfing, it's just a lot of beginners that are overly excited to proselytize their new discovery.
- pault 9y agoI don't think it's fair to claim these people are all beginners. More likely it's a phenomenon where mature languages have been around long enough that you already know their strong and weak points, but when you look at a language in development you only see its potential.
- chillee 9y agoI mean, it's not just true for new languages. For Haskell, you see beginners claim that "it's a perfect language and can do no wrong", while experts in the language will acknowledge its faults, including: long compile times, the downsides of laziness, etc.
- deleted 9y ago[deleted]