Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Concurrency vs Parallelism

3.83/5 (19 votes)
20 Nov 2018CPOL4 min read 43.2K  
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)