3 ms·
I think the author is missing the point regarding Haskell's concurrency vs. parallelism. "Rule of thumb: use Pure Parallelism if you can, Concurrency otherwise
by LukeHoersten 13y ago
I think the author is missing the point regarding Haskell's concurrency vs. parallelism.
"Rule of thumb: use Pure Parallelism if you can, Concurrency otherwise."
This isn't talking about parallelism vs. concurrency, the concepts, this is talking about Parallelism vs. Concurrency, the modules (capitalized). The emphasis here is on using PURE when you can (meaning no side effects like disk IO).
In Haskell, when you're working with pure computations, Haskell can make guarantees about what's going on and effectively manage the concurrency for you. From this concurrency, you can get parallelism almost for free (meaning no extra programming restructuring on the devs part). So the module is called Control.Parallel.
If you want to be doing parallel IO with Haskell, concurrency can't be managed automatically for the dev. This is Control.Concurrent.
"The people behind Haskell realize that one tool for both isn't good enough."
Both Control.Concurrent and Control.Parallel are for parallelism! The difference here is whether you're parallelising pure or side-effectful computations and by extension can get free concurrency. Haskell doesn't have different tools for parallelism and concurrency. It has different tools for parallelising pure vs. effects.
If you have parallelism, you have concurrency. You can have concurrent processes without parallelising them though. Simplifying: parallelism means "at the same time" and concurrency means "can safely happen at the same time".
- _yosefk 13y agoOK, so here's another quote (http://www.haskell.org/haskellwiki/Concurrency http://www.haskell.org/haskellwiki/Concurrency): "This page contains notes and information about how to write concurrent programs in Haskell. If you're more interested in performance than non-determinism, learn about parallelism first." Here it's not capitalized so it must be the concepts and not the modules... "If you have parallelism, you have concurrency" - not according to Rob Pike, who called Sawzall parallel but not concurrent. The main point I was making though was that computational code can be easily checked even if it's not pure - and the fact that you can express it as pure is a result of the same thing that let you easily check an impure spelling as well (basically it's determinism, and avoidance of constructs where determinism is hard to prove.) For event handling systems you can't easily check them, for much the same reasons that you can't express them as pure code.
- LukeHoersten 13y agoParallelism and concurrency are certainly different. Don't think I'm saying otherwise. Our disagreement is that I'm saying parallelism is a subset/type of concurrency and you are saying parallel execution can somehow not be concurrent execution. I still stand by my assertion that you misunderstood the quote from the Haskell wiki: "Rule of thumb: use Pure Parallelism if you can, Concurrency otherwise." as something that supports your claim that parallelism is not concurrency. From Wikipedia: "In computer science, concurrency is a property of systems in which several computations are executing simultaneously, and potentially interacting with each other. The computations may be executing on multiple cores in the same chip, preemptively time-shared threads on the same processor, or executed on physically separated processors." I find it hard to believe that parallel execution of multiple threads aren't "computations executing simultaneously" and therefor aren't concurrent. Do you have any more detail about why you (or Rob Pike) think that parallel execution is not also always concurrent execution?
- _yosefk 13y agoPike's definition was "handling many things at once" vs "doing many things at once"; Sawzall or, to take a simple example he also used, a dot product where you compute sub-products in parallel, is basically doing one logical thing at a time - you have your inputs and you're computing the output. You're doing it with more resources but it's one thing. SIMD instructions or superscalar execution is like that and everybody calls it a form of parallelism and nobody ever calls this concurrency, though the Wikipedia quote could be used to defend calling this concurrency. I think I don't want to argue about whether parallelism is a special case or not, really; I'm fine with it being a special case, as long as I get the point across that this special case deserves special treatment and is underserved by tools aiming at the general case...
- LukeHoersten 13y agoSeems reasonable. Worth the discussion at least. Thanks for responding to my comments.