3
votes

So I was thinking about concurrency vs parallelism after (I am preparing a short erlang tutorial) and how we can have something that is neither concurrent nor parallel (e.g. a classic C hello world running on one core), something that's concurrent but not parallel (e.g. an erlang program with multiple actors running on one code) and something that is both parallel and concurrent (e.g. the previous erlang program running on multiple cores).

However, I'm no so sure how we could have something meaningful that's parallel yet not concurrent; I guess we could chop the instructions of a program and run them in parallel but that wouldn't really produce any meaningful results. Would running two programs that don't interact on two cores be an example of a parallel system without concurrency? Somehow I feel that there could be a better example; any ideas?

1

1 Answers

7
votes

If you look around, you'll find a lot of disagreement on what, exactly, concurrency and parallelism are. You'll have to define them for your purposes before being able to give examples.

Concurrency is sometimes defined as multiple tasks whose order doesn't matter (so A can run before B, or B can run before A, without causing a problem). However, there is sometimes also the caveat that A and B must be working toward a common goal.

Parallelism is typically defined as two tasks running at the same time, such as with two processors or two separate computers. However, parallelism is also often thought of in terms of working toward a common goal, so the fact that two separate programs can execute simultaneously on a multiprocessor machine might not really be parallelism, because they have nothing to do with each other.

So, depending on the definitions, it may be impossible to have parallelism without concurrency, as (by those definitions) parallelism implies concurrency. Once you've got concrete definitions for concurrency and parallelism, then you can figure out what the examples should look like.

If I were explaining this in an Erlang tutorial, I'd probably avoid mentioning concurrency and parallelism entirely, just because it's so muddled. I'd say that Erlang has processes which work independently of each other, but which can communicate via message passing. If the hardware supports it, or if multiple Erlang nodes are in use, these processes might actually run simultaneously. Otherwise, Erlang schedules them to appear to run simultaneously, as far as we're concerned. This covers the broad ideas of concurrency and parallelism, hoperfully without worrying about pointless bickering over definitions

Note: The above sample definitions of concurrency and parallelism are not meant to be exhaustive or authoritative. They're merely for illustrative purposes.