Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is concurrent programming the same as parallel programming?

Are they both the same thing? Looking just at what concurrent or parallel means in geometry, I'd definetely say no:

In geometry, two or more lines are said to be concurrent if they intersect at a single point.

and

Two lines in a plane that do not intersect or meet are called parallel lines.

Again, in programming, do they have the same meaning? If yes...Why?

Thanks

like image 399
devoured elysium Avatar asked Nov 11 '10 02:11

devoured elysium


3 Answers

I agree that the geometry vocabulary is in conflict. Think of train tracks instead: Two trains which are on parallel tracks can run independently and simultaneously with little or no interaction. These trains run concurrently, in parallel.

The basic usage difficulty is that "concurrent" can mean "at the same time" (with the trains or code) or "at the same place" (with the geometric lines). For many practical purposes (trains, thread resources) these two notions are directly in conflict.

Natural language is supposed to be silly, ambiguous, and confusing. But we're programmers. We can take refuge in the clarity, simplicity, and elegance of our formal programming languages. Like perl.

like image 153
Josephine Avatar answered Oct 31 '22 01:10

Josephine


From Wikipedia:

Concurrent computing is a form of computing in which programs are designed as collections of interacting computational processes that may be executed in parallel.

Basically, programs can be written as concurrent programs if they are made up of smaller interacting processes. Parallel programming is actually doing these processes at the same time.

So I suppose that concurrent programming is really a style that lends itself to processes being executed in parallel to improve performance.

like image 42
Rafe Kettler Avatar answered Oct 31 '22 01:10

Rafe Kettler


No, definitely concurrent is different from parallel. here is exactly how.

Concurrency refers to the sharing of resources in the same time frame. As an example, several processes may share the same CPU or share memory or an I/O device.

Now, by definition two processes are concurrent if an only if the second starts execution before the first has terminated (on the same CPU). If the two processes both run on the same - say for now - single-core CPU the processes are concurrent but not parallel: in this case, parallelism is only virtual and refers to the OS doing timesharing. The OS seems to be executing several processes simultaneously. If there is only one single-core CPU, only one instruction from only one process can be executing at any particular time. Since the human time scale is billions of times slower than that of modern computers, the OS can rapidly switch between processes to give the appearance of several processes executing at the same time.

If you instead run the two processes on two different CPUs, the processes are parallel: there is no sharing in the same time frame, because each process runs on its own CPU. The parallelism in this case is not virtual but physical. It is worth noting here that running on different cores of the same multi-core CPU still can not be classified as fully parallel, because the processes will share the same CPU caches and will even contend for them.

like image 26
Massimo Cafaro Avatar answered Oct 31 '22 00:10

Massimo Cafaro