This is the 15th day of my participation in the August More Text Challenge

Concurrency and parallelism

Concurrency and parallelism are mainly concepts of multithreading. On the surface, the two concepts seem similar, but they actually represent different things.

concurrent

Concurrency means making progress on multiple tasks, at least ostensibly simultaneously. If your computer has only one CPU, your application may not be working on multiple tasks at the same time. To process multiple tasks, the CPU switches between tasks.

Parallel execution

Parallelism mainly refers to a computer with multiple cpus or cores and making progress on multiple cpus at the same time. But parallel execution is a different concept from parallelism.

Concurrent execution

Parallel concurrent execution is the execution of programs distributed across multiple cpus. Thread execution on the same CPU is concurrent, while execution on different cpus is parallel.

parallelism

Parallelism means breaking up a task into smaller subtasks that can be executed in parallel. Therefore, there is an essential difference between parallelism and concurrent execution.

  • To achieve true parallelism, an application must run multiple threads, each executing on a separate CPU or kernel.
  • It’s not always easy to split tasks into subtasks with the same number of cpus. Tasks are typically decomposed into a suitable number of subtasks, which are then scheduled across cpus by thread schedulers for optimal performance.

Concurrent and parallel composition

In a nutshell, concurrency refers to how a single CPU progresses on multiple tasks, and parallelism relates to how tasks are broken up and executed in parallel for multiple subtasks.

Concurrent nonparallelism

An application can be concurrent, but not parallel. This means that it appears to be making progress on multiple tasks at once (simultaneously), but the application switches between making progress on each task – until the task is complete. There is no true parallel execution of tasks in parallel threads/CPUS.

Parallel non-concurrent

Applications can also be parallel, but not concurrent. This means that the application can only handle one task at a time, and that task is broken down into subtasks that can be processed in parallel. However, each task (subtask) is completed before the next task is split and executed in parallel.

Neither concurrency nor parallelism

This means that it handles only one task at a time, and that task is never decomposed into subtasks that execute in parallel. This may be the case for a small command line application that has only one job that is too small to parallelize.

Afterword.

  • How many events through the ages? Leisurely. The Yangtze River is still rolling.