Please enable JavaScript.
Coggle requires JavaScript to display documents.
Example of Concurrency (Summation of N numbers (X1,X2,X3...Xn, Process1:…
Example of Concurrency
Mergesort
Sequential Programming (SP)
Sort each half of the array and then merge it
Eg. Input : 4, 2, 7, 6, 1, 8, 5, 0, 3, 9
Sort : 4, 2, 7, 6, 1 -> 1, 2, 4, 6, 7
Sort : 8, 5, 0, 3, 9 -> 0, 3, 5, 8, 9
Merge: ((1, 2, 4, 6, 7 ), (0, 3, 5, 8, 9)) -> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Concurrent Programming (CP)
Assume there exist a few processors. Hence the two sorts can be done in parallel.
But there is more potential for parallelism, i.e all processes (sort1, sort2, merge) can be done concurrently
the merge process must be signalled to inform it that the partial sort results are available, while the data results are available, while the data elements must be communicated
Procedure mergesort
A : array(1..N) of Integer;
procedure sort (Low, High : Integer);
procedure merge;
begin
sort(1, N/2);
sort(N/2+1, N);
merge;
end;
Summation of N numbers
X1,X2,X3...Xn
Process1: X1 + X2 + X3,… +Xn/2
Process2: X1 + X2 + X3,… +Xn/2
Process3: Process1 + Process2
Computing nCk
where 0 =< n =< k
nCk = numerator/denominator