Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / C#

Concurrency vs Parallelism

Rate me:
Please Sign up or sign in to vote.
3.83/5 (19 votes)
20 Nov 2018CPOL4 min read 38.7K   10   12
This article will explain the difference between concurrency and parallelism. Concurrency vs parallelism has been a debated topic for a long time.

Table of Contents

Actual Parallelism Vs Feel of Parallelism

Technical vocabulary in IT industry is sometimes very confusing and “Concurrency” and “Parallelism” are some of them. Many developers think “Concurrency and parallelism means executing at the same time” which is right 50%, but with one big difference:

  • Concurrency gives you a feel of parallelism and parallelism as the name implies is actual parallelism.

Feel of parallelism means you execute multiple tasks on the same core and the core switches context between tasks and serves them. You can also term this has time slicing / overlapping time period because your single core is just dedicating some time to one task and then some time to other.

Actual parallelism means you execute multiple tasks on multiple cores parallely.

Image 1

Note: “Concurrency is a broader term and Parallelism is a subset of it”.

Mapping to the real world, the left image depicts parallelism the right image depicts concurrency.

Image 2

Why a Feel of Parallelism and Why Not Actual?

In order to achieve actual parallelism, we need dedicated cores, separate memory and so on.
We need MORE RESOURCES.

Let’s say we want to show a progress bar for some task completed. Now we really do not want to have separate cores allocated to display the progress.

Image 3

We do not want PERFORMANCE here, we want that physiologically the end user feels both tasks are happening simultaneously.

We want to just beat the human eye capability of 100 FPS and give an illusion of parallelism without stressing our computer resources. But let’s say we want to process big Excel files with a million records, then yes we would love to have actual parallelism to achieve performance.

Concurrency Is About Design, Parallelism Is About Hardware

In order to achieve concurrency, we need to compose our application logic independently. For instance, let’s say you want to process employee data where you want to increment the salary by x% and bonus by x%.

Image 4

So you can decompose the application into logical units by following different designs:

Design 1

  • Divide data into 50% size each.
  • Process each 50% as separate unit.

Design 2

  • Process bonus calculation as separate unit.
  • Process salary calculation as separate unit.

Design 3

  • Divide data into 50% size each.
  • For every 50% data process bonus calculation separately and salary calculation separately.

There can be many such designs and combinations. So when you say your application is supporting concurrency, your application should be composed into small independent units.

Now you take these units and run on one core (Concurrency) or you run on multiple cores (Parallelism). So concurrency is about design while on parallelism, we talk more from the hardware perspective, 2 core, 3 cores and so on.

If you try to run every concurrent code as parallel, you have resource starvation unnecessarily. So ask yourself if you want an illusion (concurrent) or if you want performance (parallel).

Concluding

  Concurrency Parallelism
Basic definition Executing multiple tasks on the same core using overlapping or time slicing. Executing multiple tasks on different core.
Goal Feeling of parallelism without stressing out resources. Actual parallelism for performance.
Perspective Software design: Composition of independently executing computations in a co-operative fashion. Hardware: Executing computation parallel.
Resource utilization Light Heavy
  • Parallelism is a subset of concurrency.
  • Concurrency enables parallelism.
  • Concurrency is more about software design while parallelism is more about hardware.
  • Concurrency gives an illusion of parallelism while parallelism is about performance.
  • Concurrency just needs one core while parallelism needs at least 2 cores.

Further Reading

Concurrency and Parallelism video

Here we have something more in video based learning on Concurrency and Parallelism topic do view following 20+ minutes sit back, relax and enjoy full video: -

Image 5

For Further reading do watch  the below interview preparation videos and step by step video series.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect https://www.questpond.com
India India

Comments and Discussions

 
QuestionNice one Pin
Logesh Palani4-Aug-19 4:31
Logesh Palani4-Aug-19 4:31 
QuestionA more nuanced view Pin
asiwel1-Dec-18 19:34
professionalasiwel1-Dec-18 19:34 
GeneralMy vote of 3 Pin
tbayart24-Nov-18 9:25
professionaltbayart24-Nov-18 9:25 
GeneralRe: My vote of 3 Pin
wmjordan25-Nov-18 19:56
professionalwmjordan25-Nov-18 19:56 
GeneralRe: My vote of 3 Pin
Shivprasad koirala1-Dec-18 16:45
Shivprasad koirala1-Dec-18 16:45 
GeneralRe: My vote of 3 Pin
Shivprasad koirala1-Dec-18 16:44
Shivprasad koirala1-Dec-18 16:44 
QuestionDisagree Pin
asiwel22-Nov-18 7:27
professionalasiwel22-Nov-18 7:27 
AnswerRe: Disagree Pin
David Sherwood22-Nov-18 13:26
David Sherwood22-Nov-18 13:26 
AnswerRe: Disagree Pin
David Sherwood22-Nov-18 13:30
David Sherwood22-Nov-18 13:30 
GeneralGood follow-up discussion Pin
asiwel22-Nov-18 16:31
professionalasiwel22-Nov-18 16:31 
Yes, a process can be big, multi-part, even contain its own parallel processes ... or a very small and concise function of some sort. I watched the Rob Pike video mentioned in the literature review, which almost literally made the same or very similar case that the author here did. Pike mentions your point too. Both presenters associate "concurrency" with "program structure." But I still disagree somewhat with that argument. So what? If a "parallel" process is running on a machine with only one core ... either it just runs on the main thread (with no parallelism) or it multi-tasks using other thread time-slots (e.g. background methods to keep the UI active).

Calling that "concurrent" seems to me to be rather academic. Actually I would probably invert the entire argument and say that "parallel" makes more sense to mean "doing things together" and "concurrent" is even closer to the meaning of "doing things more or less at the same time" (both requiring two or more do'ers). And those "things" can be duplicate or completely different processes, even ones that can be awaited.

I might argue that (coordinated) teamwork - human or computer cores - is the essence of parallel operations, but if humans or PCs are doing some thing(s) at the same time, then they would be said to be performing concurrently.

Choreographed dancers perform in parallel; duets perform concurrently as well.

The StackOverFlow link (full of arguments) demonstrated IMHO that attempting to distinguish between these two terms as essentially "planning" and "doing" seems to be confusing to just about everybody.
GeneralRe: Good follow-up discussion Pin
Shivprasad koirala1-Dec-18 17:04
Shivprasad koirala1-Dec-18 17:04 
AnswerRe: Disagree Pin
Shivprasad koirala1-Dec-18 16:31
Shivprasad koirala1-Dec-18 16:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.