[Optimization] Parallel Computing, Concurrent Computing and Threading
Parallel Computing =/= Concurrent Computing. What is threading?
Parallel computing is a type of computation in which many calculations or the execution of processes are carried out simultaneously.
Large problems can often be divided into smaller ones, which can then be solved at the same time.
There is no taking turns, they are advanced at the same time. Naturally this is not possible with single-core CPU, but multiple-core architecture is required instead.
It can be said that if computation is parallel it is also concurrent (but not necessarily the other way around) - since parallel computation also fulfills the definition of concurrent computation.
There is no taking turns, they are advanced at the same time. Naturally this is not possible with single-core CPU, but multiple-core architecture is required instead.
It can be said that if computation is parallel it is also concurrent (but not necessarily the other way around) - since parallel computation also fulfills the definition of concurrent computation.
Concurrent computing is a form of computing in which several computations are executed during overlapping time periods—concurrently—instead of sequentially (one completing before the next starts).
This is not exactly same as Parallel computing. Concurrent operation means that two computations can both make progress and advance regardless of the other. If there are two threads, for example, then both make progress independently. The second computation doesn't need to wait for the first one to complete before it can be advanced.
In single-core setup it is possible that the computations take turns in execution. The CPU might run few instructions from the other thread, then suspend it and switch over to the second and run few steps from it and so on.
Summary
Concurrent = Two queues and one coffee machine.
Parallel = Two queues and two coffee machines.
Parallel = Two queues and two coffee machines.
Threading vs Parallelism
Threading is usually referred to having multiple processes working at the same time on a single CPU (well actually not - you think they do but they switch very fast between them).Parallelism is having multiple processes working at the same time on multiple CPU's.
You can have multi-threading on a single core machine, but you can only have parallelism on a multi core machine. Thus, threading is a specific implementation of parallelism.
In general:
- If we think CPU as a company and threads as its workers then, it help us to understand threading and parallelism more easily.
- Like a company have many workers, the CPU also have many threads.
- Also there may be more than one company and therefore there may be more than one CPU's.
- Therefore when workers(threads) work in a company(CPU), it is called threading.
- And when two or more companies(CPU) work independently or together, it is called parallelism.
More Reading:
Good read on threading and parallism performance analysis using Ruby (and JRuby - since Ruby doesn't have parallism) --> https://hackernoon.com/need-faster-code-try-multithreading-5dc30c83837c
Resource:
- https://stackoverflow.com/questions/806499/threading-vs-parallelism-how-do-they-differ
- https://stackoverflow.com/questions/1897993/what-is-the-difference-between-concurrent-programming-and-parallel-programming
- https://en.wikipedia.org/wiki/Parallel_computing
- https://en.wikipedia.org/wiki/Concurrent_computing
- https://bytearcher.com/articles/parallel-vs-concurrent/
Comments
Post a Comment