News for hackers. Stuff that matters.
Re:Introduction to Functional Programming in OCaml by catnaroek on Sunday September 04, 2016 @12:53PM (#12425343)
async is for concurrent I/O, not parallel processing.
Re:Introduction to Functional Programming in OCaml by gpderetta on Sunday September 04, 2016 @07:59PM (#12427330)
I don't know about ocaml, but in general async is also about parallelism as it exposes concurrency opportunities. See cilk spawn for example.
Re:Introduction to Functional Programming in OCaml by catnaroek on Monday September 05, 2016 @12:16AM (#12428074)
Parallelism and concurrency are fundamentally different things. Parallelism is running independent computations simultaneously. Concurrency control is managing the use of shared resources by temporarily granting exclusive access to them to individual computations.

Imperative languages tend to blur the distinction between parallelism and concurrency, because the global state of a process by itself can be considered a shared resource. But in functional languages, it's natural to expect a sharper distinction: Because most data structures are logically immutable, the primary use for concurrency control is managing the interaction between the program and the “outside world”. On the other hand, parallelism is a powerful tool for speeding up the program's own internal calculations, even when no interaction with the “outside world” is involved.

Re:Introduction to Functional Programming in OCaml by gpderetta on Monday September 05, 2016 @05:44AM (#12429168)
Concurrency is a property of the software (i.e. the problem domain): i.e. having multiple independent control flows. Parallelism is a property of the hardware, i.e. having the capability of running multiple operations (be it pure computation, memory access or IO).

To make use of parallel hardware you need concurrent software. Async is a way of exposing additional concurrency, thus enabling parallelism, to the hardware.

Re:Introduction to Functional Programming in OCaml by catnaroek on Monday September 05, 2016 @08:51AM (#12429918)
> Parallelism is a property of the hardware, i.e. having the capability of running multiple operations (be it pure computation, memory access or IO).

Parallelism is a property of the program too: if it doesn't have independent subcomputations, the program is going to run sequentially even in hardware that supports parallelism.

> To make use of parallel hardware you need concurrent software.

Parallel Haskell shows otherwise.

Re:Introduction to Functional Programming in OCaml by gpderetta on Monday September 05, 2016 @09:10AM (#12430035)
>if it doesn't have independent subcomputations, the program is going to be run sequentially even in hardware that supports parallelism.

the property of having independent sub-computations is called concurrency.

Re:Introduction to Functional Programming in OCaml by catnaroek on Monday September 05, 2016 @09:25AM (#12430125)
> the property of having independent sub-computations is called concurrency.

Nope. If I have two n-dimensional vectors, and want to compute their sum, there's no concurrency whatsoever: there's just n independent computations (each scalar sum). A pure parallelism problem.

(Well, there is a concurrency problem at a lower level of abstraction, if you want to schedule these computations over less than n processors. That's because the processors are shared resources that require temporary exclusive access to be used.)

References:

(0) https://existentialtype.wordpress.com/2011/03/17/parallelism...

(1) https://existentialtype.wordpress.com/2014/04/09/parallelism...

Re:Introduction to Functional Programming in OCaml by gpderetta on Monday September 05, 2016 @09:57AM (#12430328)
I see your blog article and raise a wikipedia [1]:

"In computer science, concurrency is the decomposability property of a program, algorithm, or problem into order-independent or partially-ordered components or units. This means that even if the concurrent units of the program, algorithm, or problem are executed out-of-order or in partial order, the final outcome will remain the same. This allows for parallel execution of the concurrent units, which can significantly improve overall speed of the execution in multi-processor and multi-core systems."

Note the 'decomposability' part, i.e. the having the property of being decomposable.

[1] https://en.wikipedia.org/wiki/Concurrency_%28computer_scienc...

Re:Introduction to Functional Programming in OCaml by catnaroek on Monday September 05, 2016 @10:06AM (#12430382)
Zeroth, I'm not the owner of that blog. He's a CS researcher, I'm just a lowly programmer in the trenches. Just wanted to make that clear.

First, the Wikipedia article you quote is partially incorrect:

> This means that even if the concurrent units of the program, algorithm, or problem are executed out-of-order or in partial order, the final outcome will remain the same.

This is not true. Consider the following example: Mr. Foo and Ms. Bar are happily married, and own a shared bank account, whose initial balance is $400. Concurrently, they attempt to withdraw $200 and $300 respectively. The scheduling of the withdrawal operations will determine the final result:

(0) Foo has $200, Bar has nothing, and the final account balance is $200.

(1) Foo has nothing, Bar has $300, and the final account balance is $100.

> Note the 'decomposability' part, i.e. the having the property of being decomposable.

Both parallelism and concurrency are about decomposition. They are different kinds of decomposition, though. Parallel tasks cooperate towards a common goal. Concurrent tasks compete for access to common resources.

Re:Introduction to Functional Programming in OCaml by gpderetta on Monday September 05, 2016 @10:29AM (#12430503)
I think that Wikipedia claim is predicated on 'same result' for originally partially ordered results. Even a sequential implementation can produce different results if the requests arrive in different order.

> Parallel tasks cooperate towards a common goal. Concurrent tasks compete for access to common resources.

This definition is interesting, but I think it lack descriptive power: are web server tasks parallel as they are all contributing at fulfilling the incoming client request queue? Are threads of a matrix multiplication process concurrent as they compete for access to the cpu?

It also misses the whole reason for parallelism which is speed-up (by a constant) of execution.

Anyway, to go full circle, I stand by my assertion that async can be all about parallelism.

[BTW, this has been a great conversation, sometimes one need to put their thought in writing to actually fully understand them]

Re:Introduction to Functional Programming in OCaml by catnaroek on Monday September 05, 2016 @10:39AM (#12430545)
> Even a sequential implementation can produce different results if the requests arrive in different order.

I never said that the withdrawal requests must be served in the same exact order they were received. This may or may not be the case.

> are web server tasks parallel as they are all contributing at fulfilling the incoming client request queue?

At the highest level of abstraction, they're concurrent. The client request queue is a low-level implementation detail, and a high-level language could well hide it from you. (Yes, this means that people often do unnecessarily low-level programming, even when using so-called “high-level languages”.)

>> Parallel tasks cooperate towards a common goal. Concurrent tasks compete for access to common resources.

> This definition is interesting, but I think it lack descriptive power

Those particular sentences weren't definitions. The actual definitions were what I said a few comments earlier: “Parallelism and concurrency are fundamentally different things. Parallelism is running independent computations simultaneously. Concurrency control is managing the use of shared resources by temporarily granting exclusive access to them to individual computations.”

> It also misses the whole reason for parallelism which is speed-up (by a constant) of execution.

It doesn't. If there is only one goal, then the only possible point to splitting a computation into parallel subcomputations can be to speed up the global computation.

Re:Introduction to Functional Programming in OCaml by gpderetta on Monday September 05, 2016 @10:56AM (#12430632)
>> Even a sequential implementation can produce different results if the requests arrive in different order. >I never said that the withdrawal requests must be served in the same exact order they were received. This may or may not be the case.

My point is if there is no ordering in the first place, there is no ordering to be preserved.

> Parallelism is running independent computations simultaneously. Concurrency control is managing the use of shared resources by temporarily granting exclusive access to them to individual computations.”

Concurrency control != concurrency though.

Re:Introduction to Functional Programming in OCaml by catnaroek on Monday September 05, 2016 @01:19PM (#12431314)
> Concurrency control != concurrency though.

Concurrency is simply the situation where two or more processes need exclusive access to a shared resource, so it's fair to say that, whenever there's concurrency, there's a need for concurrency control.