Recursion in functional programming will not give high concurrency. Is it correct? -
I'm new to functional programming. In the compulsory programming, loops replace replication of FP. Another statement is the FP high concurrency. Instructions are implemented in parallel on multi-core / CPU systems as data is irreversible.
While in recursive, the steps can not be executed parallel to the stage execution, depending on the results of previous steps.
So, I'm convinced that the recycling in the FP will not give high concurrency. Am I right?
Sort. Data parallelism can not get you more parallel execution; This is it. However, you often have more data parallels, which are expressed in normal sequential algorithms, whether functional or necessary. For example, consider taking a vector scalar multiple: (note: this is a built-in self-style language):
function scalar_available (scalar c, vector v) {vector v1 ; For (int i = 0; i & lt; length (v); i ++) {v1 [i] = c * v [i]; } Return v1; }
Obviously, this is not going to run in parallel. If we rewrite it in a functional language using recursive then the situation does not improve (you can think of it as Haskell):
scalar_multiple c [] = [ ] Scalar_multiple c (x: xn) = c * x: scalar_multiple c xn
this is still sequential algorithm!
However, you can see that there is no data dependence --- if you do not really need the results of the first and the subsequent multiples to calculate the latter, then we have similarities here There is a possibility. It can be completed in a compulsory language:
function scalar_available (scalar c, vector v) {vector v1; Parallel_for (int i in 0..length (v) -1) {v1 [i] = c * v [i]; } Return v1; }
But this parallel_for
is a dangerous construction. Consider a search function:
function first (diagnosis p, vector v) {for (int i = 0; i & lt; length (v); i ++) {if ( P (v [i]) return; } Return -1; }
If we try to speed it up by replacing We will not return the first pointer to the element to satisfy the condition, simply a element which satisfies it is . We have broken the contract of function parallel. The clear solution 'does not allow the return of the code This is a 'toy' example again (use "just This is just a very simple example; Of course, in real equality it involves getting large amounts of work to reflect in comparison to this! with
parallel_for
for
inside
function first (denominator p, vector v) {parallel_for (in int i 0..length (v) -1) {if (p (v [i])) i; } Return -1; }
parallel_for
. But there are many other dangerous structures; In fact, you will see that I had to leave for the C-style loop because the patterns of pay scale and examination are dangerous in parallel languages. Consider:
function sequence (int n) {vector v; Int c = 0; Parallel_for (int i = 0..n-1) {v [i] = c ++; } Return V; }
v [i] = i;
!"), But this is Indicates: This function initiates v
in a random order due to parallelism, it has come to know that the creation of 'safe' consultants such as creation- for parallel_
is done in the same type of structure, which adds 'safe' parallel structures to those languages. By adding them to the necessary languages
Comments
Post a Comment