Skip to content

Concurrency and Parallelism

Farrokh Karimi edited this page Aug 14, 2018 · 6 revisions

Home Page
Previous Page

Concurrency

In simple words, concurrency is the occurrence of two or more events at the same time. Concurrency is a natural phenomenon because many events occur simultaneously at any given time.

In terms of programming, concurrency is when two tasks overlap in execution. With concurrent programming, the performance of our applications and software systems can be improved because we can concurrently deal with the requests rather than waiting for a previous one to be completed.

Concurrency is when two tasks overlap in execution. It could be a situation where an application is progressing on more than one task at the same time. We can understand it diagrammatically; multiple tasks are making progress at the same time, as follows:

Levels of concurrency

There are three important levels of concurrency in terms of programming as following:

  • Low-Level Concurrency: In this level of concurrency, there is explicit use of atomic operations. We cannot use such kind of concurrency for application building, as it is very error-prone and difficult to debug. Even Python does not support such kind of concurrency.

  • Mid-Level Concurrency: In this concurrency, there is no use of explicit atomic operations. It uses the explicit locks. Python and other programming languages support such kind of concurrency. Mostly application programmers use this concurrency.

  • High-Level Concurrency: In this concurrency, neither explicit atomic operations nor explicit locks are used. Python has concurrent.futures module to support such kind of concurrency.

Parallelism

Parallelism may be defined as the art of splitting the tasks into subtasks that can be processed simultaneously. It is opposite to the concurrency, as discussed above, in which two or more events are happening at the same time. We can understand it diagrammatically; a task is broken into a number of subtasks that can be processed in parallel, as follows:

Necessity of Parallelism

We can achieve parallelism by distributing the subtasks among different cores of single CPU or among multiple computers connected within a network. Consider the following important points to understand why it is necessary to achieve parallelism:

  • Efficient code execution: With the help of parallelism, we can run our code efficiently. It will save our time because the same code in parts is running in parallel.

  • Faster than sequential computing: Sequential computing is constrained by physical and practical factors due to which it is not possible to get faster computing results. On the other hand, this issue is solved by parallel computing and gives us faster computing results than sequential computing.

  • Less execution time: Parallel processing reduces the execution time of program code.

If we talk about real life example of parallelism, the graphics card of our computer is the example that highlights the true power of parallel processing because it has hundreds of individual processing cores that work independently and can do the execution at the same time. Due to this reason, we are able to run high-end applications and games as well.

Concurrency vs. Parallelism

Both concurrency and parallelism are used in relation to multithreaded programs but there is a lot of confusion about the similarity and difference between them. The big question in this regard is: Is concurrency same as parallelism? Although both the terms appear quite similar but the answer to the above question is NO, concurrency and parallelism are not same. Now, if they are not same then what is the basic difference between them? In simple terms, concurrency deals with managing the access to shared state from different threads and on the other side, parallelism deals with utilizing multiple CPUs or its cores to improve the performance of hardware. To get more idea about the distinction between concurrency and parallelism, consider the following points:

  • Neither parallel nor concurrent: An application can be neither parallel nor concurrent. This means that it works on only one task at a time and the task is never broken into subtasks.

  • Concurrent but not parallel: An application can be concurrent but not parallel means that it processes more than one task at the same time but the tasks are not broken down into subtasks.

  • Parallel but not concurrent: An application can be parallel but not concurrent means that it only works on one task at a time and the tasks broken down into subtasks can be processed in parallel.

  • Both parallel and concurrent: An application can be both parallel and concurrent means that it both works on multiple tasks at a time and the task is broken into subtasks for executing them in parallel.

MPI

The Message Passing Interface Standard (MPI) is a message passing library standard based on the consensus of the MPI Forum, which has over 40 participating organizations, including vendors, researchers, software library developers, and users. The goal of the Message Passing Interface is to establish a portable, efficient, and flexible standard for message passing that will be widely used for writing message passing programs. As such, MPI is the first standardized, vendor independent, message passing library. The advantages of developing message passing software using MPI closely match the design goals of portability, efficiency, and flexibility. MPI is not an IEEE or ISO standard, but has in fact, become the "industry standard" for writing message passing programs on HPC platforms.

Why we using MPI?

  • Standardization: MPI is the only message passing library that can be considered a standard. It is supported on virtually all HPC platforms. Practically, it has replaced all previous message passing libraries.

  • Portability: There is little or no need to modify your source code when you port your application to a different platform that supports (and is compliant with) the MPI standard.

  • Performance Opportunities: Vendor implementations should be able to exploit native hardware features to optimize performance. Any implementation is free to develop optimized algorithms.

  • Functionality: There are over 430 routines defined in MPI-3, which includes the majority of those in MPI-2 and MPI-1.

  • Availability: A variety of implementations are available, both vendor and public domain.

Next Page

Clone this wiki locally