Question

In: Computer Science

A pipeline algorithm

A pipeline algorithm is implemented so that a stream of data elements of type T produced by a process P0 passes through a sequence of processes P1, P2, ., Pn - 1, which operates on the elements in that order.
a. Define a generalized message buffer that contains all the partially consumed data elements and write an algorithm for process Pi (0 ≤ i ≤ n - 1), of the form
repeat
receive from predecessor;
consume element;
send to successor:
forever
Assume P0 receives input elements sent by Pn - 1. The algorithm should enable the processes to operate directly on messages stored in the buffer so that copying is unnecessary.
b. Show that the processes cannot be deadlocked with respect to the common buffer.

Solutions

Expert Solution

a. The buffer is declared to be an array of shared elements of type T. Another array defines the number of input elements available to each process. Each process keeps track of the index j of the buffer element it is referring to at the moment.

 

 

 

var buffer: array 0..max-1 of shared T;

 

 

available: shared array 0..n-1 of 0..max;

 

 

"Initialization"

 

 

var K: 1..n-1;

 

 

region available do begin

 

 

available(0) := max;

 

 

for every k do available (k) := 0;

 

 

end

 

 

"Process i"

 

 

var j: 0..max-1; succ: 0..n-1; begin

 

 

j := 0; succ := (i+1) mod n;

 

 

repeat

 

 

region available do

 

 

await available (i) > 0;

 

 

region buffer(j) do consume element;

 

 

region available do

 

 

begin

 

 

available (i) := available(i) - 1;

 

 

available (succ) := available (succ) + 1;

 

 

end

 

 

j := (j+1) mod max;

 

 

forever

 

 

end

 

 

 

In the above program, the construct region defines a critical region using some appropriate mutual-exclusion mechanism. The notation

 

 

 

region v do S

 

 

 

Means that at most one process at a time can enter the critical region associated with variable v to perform statement S

 

 

b. A deadlock is a situation in which:

 

 

 

P0 waits for Pn-1 AND

 

 

P1 waits for P0 AND

 

 

. . . . .

 

 

Pn-1 waits for Pn-2

 

 

Because

 

 

 

(available (0) = 0) AND

 

 

(available (1) = 0) AND

 

 

. . . . .

 

 

(available (n-1) = 0)

 

 

 

But if max > 0, this condition cannot hold because the critical regions satisfy the following invariant:

 

 


But if max > 0, this condition cannot hold because the critical regions satisfy the following invariant:

 

 

Related Solutions

pipeline algorithm
A pipeline algorithm is implemented so that a stream of data elements of type T produced by a process P0 passes through a sequence of processes P1, P2, ., Pn - 1, which operates on the elements in that order.a. Define a generalized message buffer that contains all the partially consumed data elements and write an algorithm for process Pi (0 ≤ i ≤ n - 1), of the formrepeatreceive from predecessor;consume element;send to successor:foreverAssume P0 receives input elements sent...
consider a natural gas pipeline. The pipeline is made of steel of thickness 2.00 cm. The...
consider a natural gas pipeline. The pipeline is made of steel of thickness 2.00 cm. The steel is coated on the inside with a 0.100 mm layer of Ni. The concentration of natural gas inside the pipeline is 0.100 kg/m3. The concentration outside is 0 kg/m3. The diffusion coefficient of natural gas in Ni is 2.01 x 10-21 m2/s and the diffusion coefficient of natural gas in steel is 7.00 x 10-17 m2/s. Calculate the flux of natural gas through...
Kinder Morgan, an oil and gas pipeline company, is contemplating the expansion of its TransMountain Pipeline,...
Kinder Morgan, an oil and gas pipeline company, is contemplating the expansion of its TransMountain Pipeline, which runs from Alberta to the British Columbia coast. The project is estimated to cost $7.4 billion and is expected to have a useful life of 15 years, with a salvage value of $0.5 billion. The new equipment will be added to an existing CCA Class with a rate of 5%. The pipeline expansion will increase capacity from the current level of 300,000 barrels...
Irion County Pipeline (ICP) enjoys monopoly power because it is the only pipeline available to transport...
Irion County Pipeline (ICP) enjoys monopoly power because it is the only pipeline available to transport crude oil out of Irion County. The demand (average revenue) curve for oil transport services is given by AR = 600 − (Q/2)—this implies a marginal revenue curve of 600 − Q. Here Q represents thousands of barrels of oil shipped each day. The average and marginal cost curves curves for moving oil are given as: AC = 20Q + (200/Q) MC = 40Q...
Strategic Transportation Management--Pipeline 1.Explain the dual nature of pipeline transportation in the U.S. Compare the two...
Strategic Transportation Management--Pipeline 1.Explain the dual nature of pipeline transportation in the U.S. Compare the two common forms of pipeline oil and water by using the elements of a transportation system.
A pipeline is to be inspected. There is a 10% chance that any 100ft section of...
A pipeline is to be inspected. There is a 10% chance that any 100ft section of pipeline will contain at least one defect (thinning walls, weld defect, etc). Assume the sections are independent (whether one sections fails or not is independent of whether other sections fail or not). What is the probability that, given 2 defective sections have been found so far, that exactly 12 sections of pipeline have been inspected? What is the probability that, given 50 sections have...
bakery algorithm
Now consider a version of the bakery algorithm without the variable choosing. Then we have1 int number[n];2 while (true) {3 number[i] = 1 + getmax(number[], n);4 for (int j = 0; j < n; j++){5 while ((number[j]! = 0) && (number[j],j) < (number[i],i)) { };6 }7 /* critical section */;8 number [i] = 0;9 /* remainder */;10 }Does this version violate mutual exclusion? Explain why or why not.
Banker’s Algorithm
Given the following state for the Banker’s Algorithm. 6 processes P0 through P54 resource types: A (15 instances); B (6 instances)C (9 instances); D (10 instances)Snapshot at time T0: a. Verify that the Available array has been calculated correctly.b. Calculate the Need matrix.c. Show that the current state is safe, that is, show a safe sequence of processes. In addition, to the sequence show how the Available (working array) changes as each process terminates.d. Given the request (3, 2, 3,...
When the transportation of natural gas in a pipeline is not feasible for economic reasons, it...
When the transportation of natural gas in a pipeline is not feasible for economic reasons, it is first liquefied using nonconventional refrigeration techniques and then transported in super-insulated tanks. In a natural gas liquefaction plant, the liquefied natural gas (LNG) enters a cryogenic turbine at 3 MPa and -160 °C at a rate of 20 kg/s and leaves at 0.3 MPa. If 115 kW power is produced by the turbine, determine the efficiency of the turbine. Take the density of...
The case of the Keystone XL pipeline is an example of the emotional aspect of many...
The case of the Keystone XL pipeline is an example of the emotional aspect of many environmental disputes, as our nation tries to come to grips with sustainability issues. Local and national opponents of the Keystone XL pipeline, which would carry crude oil from Canada to the Texas Gulf Coast, have protested for years to stop its construction (Figure 4.10). These efforts accelerated after President Trump approved the pipeline in March 2017, reversing President Obama’s decision to reject it on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT