Concurrency - property of systems in which several computational processes are executing at the same time, and potentially interacting with each other.
Parallelism - computation in which many calculations are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved concurrently ("in parallel").
If I'm reading the article correctly, the author is saying that with parallelism, you can perform independent operations in parallel (like sorting both halves of a quicksort), whereas concurrency as people think about it deals more with parallel operations on a shared state?
Parallelism often implies that the tasks are working towards the same goal together, like dividing-up the workload among sibling processors. This is purely for performance.
Concurrency is simply the introduction of non-determinsm, like having a thread run a task in the background. Concurrency can be used to make a networked GUI application more responsive to the end user, even if there is no performance benefit.
I don't agree with the author's conflation of concurrency with non-determinism. To me, concurrency means there may be more than one operation logically "in flight" at any given time; parallelism means there may be more than one operation physically happening at any given time. Determinism vs non-determinism is an orthogonal issue.
You could have a single-threaded cycle-counting CPU simulator which is entirely deterministic, yet if it is simulating a multi-threaded program, that program would exhibit concurrency (for example, if it were a web server, it could be serving multiple requests over separate TCP connections concurrently, working a little on each request round-robin).
To appreciate his point, you must be aware that Harper is thinking about a formalization of concurrency. In such a formalization, you could have a deterministic execution of the concurrent processes as you hint, but you will also have a trace of incoming events in the formalization, not under the control of the CPU.
For the system as a whole to be deterministic, you would have it be deterministic for arbitrary event traces. This is rarely the case in practice though. Harper does not tend to just sling out a postulate unless he has good reason to think it is so, backed up by a formal system in which he identified the association.
It could be that he has identified concurrency goes hand in hand with non-determinism. To me, it does sound rather plausible.
It sounds poorly defined to me. Concurrency for me means a specific thing, and that specific thing does not have a necessary implication of non-determinism. My position is similar to dmbarbour's (https://existentialtype.wordpress.com/2011/03/17/parallelism...).
Your distinction appeals to physicality, to a "real world". The author comes from a purer mathematical perspective, where it does not matter whether the code runs on silicon, is emulated by another machine, or is evaluated by humans on a blackboard.
Parallelism is purely an efficiency issue; the result of a computation does not change if run sequentially or in parallel. In other words, it only affects the cost model, not the semantics.
Concurrency means adopting some non-determinism in the semantics, either for necessity (e.g. in concurrent servers) or as a program structuring mechanism. In your example, if we are concerned with the semantics of the simulator, then there is no parallelism OTOH, if we are concerned with the semantics of the simulated code, then it's likely that we would use concurrency in it's definition (even if we "really know" that there is no underlying physical nondeterminism).
Parallelism is just an optimization; and concurrency does not imply non-determinism. Concurrency means you've got more than one thing in flight at a time. Having more than one task in flight, whether you switch using coroutines, or asynchronous completions, or an OS scheduler running on a timer interrupt, or cycle counting in a virtual machine, or via higher level language constructs like futures and promises, or reactive programming, is concurrency; but not all of these things are non-deterministic.
Peter Van Roy's book defines it as "an execution is called nondeterministic if there is an execution state in which there is a choice of what to do next". I believe the only thing you mention that does not conform to this definition is co-routining, but I wouldn't categorise it as concurrency either (nor does the book).
There's a nice answer on FRP at http://stackoverflow.com/questions/1028250/what-is-functiona... - if choices in execution are not revealed to the program, you can still have concurrency without non-determinism. But again, one needs to call in to question what tasks are making progress concurrently, because depending on the level of abstraction you're looking at, you can say that there is concurrency or there isn't. In other words, you might have parallelism at a low level of abstraction, which is a physical optimization of concurrency, and at that low level it might even be non-deterministic, but that non-determinism may not be exposed at a higher level.
Take a spreadsheet implementation as an example. There may be multiple events coming in, and numbers in the sheet updating as the expressions are recalculated. It might even be a multi-user spreadsheet; so it seems there is concurrency (for some level of abstraction). But is there non-determinism?
Sure, you can have deterministic concurrency. But that's not what he's talking about. Concurrent operations being non-deterministic is the accepted norm. If you're talking about deterministic concurrency, then you can qualify it as such; anything else is pedantry.
If someone is trying to be precise in what they talk about, pedantry is correct. The trouble I had with the author is that he is redefining what I understand by the term concurrency.
There may be some difference in accounting. The recursion depth of Blelloch's recursive function you linked to is O(log n), but it uses an operation that cannot be implemented in constant time: partitioning the elements into those greater and less than the pivot. I'd guess that operation is itself O(log n), which would account for the O(log^2 n).
By "in some sense", do you mean it can be parallelized to O(1) time as long as you don't have to actually build up the data structures that result from partitioning (e.g. arrays)? Then it's not clear to me why this assumption is applicable to quicksorting an array. Doesn't it call for some non-obvious representation of intermediate results?
But isn't recursion depth the same as depth if each operation in your recursive function is constant time (except for the recursing bits)? Thus you can look at recursive depth as computing depth modulo the bits you compute in your function at a fixed level. I was speculating that partitioning would require O(log n) parallel steps. Can you give details or provide a link to achieving it constant depth?
Quicksort takes O(N log N) time when comparing two keys is constant time. But as N → ∞, if your keys continue to have a fixed number of bits, you're going to have a lot of duplicate keys. (Consider sorting four billion 8-bit bytes.) In that case you can do better than Quicksort; you can simply partition the data in O(N) time among the unique keys, then sort the keys in O(1) time, then concatenate the partitions in O(N) time.
So if you have to have unique keys, each comparison is going to take O(log N) time instead of O(1) time, so the overall algorithm takes O(N log² N) time. On the other hand, this is somewhat of a theoretical consideration if your keys are more than about 4–6 bytes long in the first place, since it's not very practical to store 2⁴⁸ records. But 2⁴⁸ is a long way from ∞, and if you're going to fudge by treating the theoretical factor of log N as constant, you might as well claim that Quicksort is O(N) with a constant of, say, less than 100 comparisons per key.
I don't know anything about analyzing parallel quicksort, but maybe this key-comparison-time factor explains it? Because it seems like key comparisons would pretty much have to be serialized on Quicksort's critical path, no?
Yes. It's maybe more frequently seen on other functions such as trig functions (e.g. the identity sin²α+cos²α=1) but it crops up a lot on logarithms in computational complexity (as here). I've certainly never seen it used to mean anything else. As grandpa says, base is written as subscript.
Non-determinism is not concurrency either (I think the author is wrong to conflate the two).
Parallelism is a physical, hardware, implementation of concurrency. VLIW, vector operations, GPUs etc. execute very fine-grained operations in parallel, but whether this is regarded as concurrency in any given context depends on how "lumpily" you define a concurrent task for that particular context. For example, fancy parallel instructions might be used to resize images in a thumbnail generator in a web server, but if the task being considered is the processing of a web request, then there is no concurrency. If the task being considered is processing a line, stripe or block of pixels, then there is concurrency.
Concurrency is concerned with nondeterministic composition of programs (or their components). Parallelism is concerned with asymptotic efficiency of programs with deterministic behavior.
Interesting distinction. My understanding is that these terms are typically used interchangeably in a more general sense. Perhaps it would be better to come up with some different terms for these concepts.
So pretty much he is saying that concurrency and parallelism aren't the same thing. (Which is kind of a 'duh' if you think about it).
Parallelism is concerned with efficiency of the algorithm in a parallel environment. His example is that quick-sort is an easily parallelized algorithm (each level of recursion is two completely independent steps). This means that at each level, you can run the independent steps at the same time, meaning that in a parallel environment, you can see a big speed improvement.
Concurrency is more dealing with the control flow of a program. Concurrency tries to manage resources in a 'nondeterministic' environment.
Pretty much, its like an OS scheduler. The OS scheduler has to manage all of its resources, like the printer or the hard drive or whatever else, between different concurrently running processes, and prevent things like race conditions or deadlock. This isn't a parallelism issue, because you can have, for example, a single threaded processor with a multi-tasking operating system.
Concurrency = managing shared resources. Things like mutual exclusion and transactions. Getting processors to get in line (serialization/composition) for a shared resource instead of just trampling over each other by just grabbing it when they want (non-determinism), so that actions that depend on being done in order and without interruption can be done.
Parallelism = splitting up subtasks that don't depend on each other. If the tasks don't depend on each other, the things doing them shouldn't need to talk. If you have enough processors, you can do almost everything at once, so the algorithm is only as slow as things that actually need to be done in order (asymptotic efficiency).
In imperative programming, we tell the computer what order to do things in, so it doesn't know what actions don't depend on each other - to parallelize, we have to worry about concurrency. In functional programming, the compiler knows what depends on what (what uses the result of something else), so it can parallelize things that don't depend on each other. It might be implemented with concurrency, but the programmer doesn't need to worry about it.
Parallelism is recognizing the 5 guys should be able to dig a ditch close to 5 times as fast as 1. Concurrency is making sure everyone has a shovel and is digging in the right place.
Determinism is making sure the digging is in the right place. Non-deterministic digging may be possible, but it's harder to get right.
Concurrency could also be having one guy with one shovel, but digging iteratively in 5 separate places and digging a shovelful or two at a time.
Or to put it another way, parallelism is digging two ditches with 4 people 4 times as fast as 1 person digging two ditches; concurrency is 1 person digging two ditches at the same time, alternating; determinism is making sure that the two ditches are being dug correctly, at an even pace, etc.
Great illustration! I just imagine 5 ditches all over the place and going into 5 different directions and/or crossing, or one big hole as all 5 started at the same place and, while shoveling, were hitting each other with elbows and the other end of shovel, or, starting at the correct place and in the correct direction, just 1 guy digging at any given time while the other 4 waiting for their chance to dig. ( i did my share of digging at student summer construction projects some 20+ years ago :)
Parallelism is a property of the machine. We are obsessed with the idea of making a program run in less time by better utilizing the hardware.
Concurrency is a property of the program. It is about describing that multiple events can happen independently of each other.
An operating system kernel (old ones) are concurrent but not parallel for instance. Concurrently it will handle multiple users, input from keyboard, network and disk, switch process contexts and so on. Yet, only a single CPU will be doing the task, so everything happens in a serial stream of events.
The point where the two blend is when you have a concurrent system and want it to execute faster. Then, you will often find yourself employing parallel tactics to speed the system up. In the OS case, modern NIC's and disk drives have processors on them carrying out tasks in parallel to the CPU. So the system is not strictly concurrent anymore. They also have SMP-capability of course.
Parallel but not concurrent systems exist as well. The perhaps best example is a GPU, which is massively parallel (1700+ cores is not uncommon), but all the cores are doing the same thing. Hence, it cannot handle different events at different times with independence.
But Bob Harper really makes two points, and Simon Marlow's article only covers one of them. The fist point is that parallel functional languages makes it possible to write correct parallel programs easily, by not exposing any nondeterminism to the programmer. The second point is that for such a language it's particularly easy to describe what the running time of the program will be, by talking about the depth and work of a computation.
Of course, the reason Marlow doesn't make that point is that it's not true for Haskell! In ML, the work involved in computing f(g(1)) is the work of computing g plus the work of computing f. But in Haskell that's not true, since if f doesn't use it's argument, g will never run.
Concurrency does not necessarily have anything to do with parallel programming, although the latter may need to be aware of concurrency issues if the parallel algorithm needs to manage shared resources and sequential dependencies.
The gist of the article is that functional languages lend themselves to parallel constructs, and such tooling should be built into languages themselves to free the programmer from worrying about concurrency issues. For more details, read on...
Asymptotic efficiency is just a fancy way of saying algorithmic efficiency. In computer science terms, asymptotic analysis measures how work increases relative to how much input needs to be processed; eg, sorting an N-element list using Quicksort would take an amount of work corresponding to NlogN.
Now, when you try to parallelize an algorithm such as Quicksort, you are concerned with your speedup -- how much you will gain by processing in parallel. The speedup is not always linear because of sequential dependencies within the algorithm. Wiki has a decent primer on the subject: http://en.wikipedia.org/wiki/Speedup.
In this case, the article was looking at the asymptotic efficiency of Quicksort's critical section; eg, the part that could be parallelized, to determine just how much it could be parallelized.
Concurrency, on the other hand, deals with more classical problems such as scheduling and resource deadlock. It is the OS's job to manage resources, which is why you hear a lot about concurrency in terms of the OS. And since thread/process scheduling by the OS is unpredictable, this is where 'nondeterministic composition' comes from. This manifests in things like race conditions. http://en.wikipedia.org/wiki/Race_condition
So it may become the parallel application's responsibility to avoid such nondeterministic behavior within resources shared by the application. Note this doesn't just apply to threads running on the same computer/OS; it may also apply to data coming in from the network from a distributed parallel algorithm.
In conventional, procedural programming languages, concurrency has to be addressed explicitly through things like locks and barriers. Functional languages help make this more implicit due to immutability. Languages like Erlang go one step further and absolve you of any responsibility for things like IPC.
Parallelism - computation in which many calculations are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved concurrently ("in parallel").
Go to slide #13 in my presentation:
http://www.slideshare.net/nivertech/migrationtomulticore