Gotta fill in the program .. Please retye the whole program after change. Write
ID: 644736 • Letter: G
Question
Gotta fill in the program .. Please retye the whole program after change.
Write a FORTRAN 90 program which reads this data from the keyboard (use the Unix redirect
"<" with the data le). The program nds the following sums:
A sum is found for each device. For devices with character codes "A", "B", "C" a calculation is
done based on a low value and a high value for the device status code. If the status code is less
than or equal to the low value then measurement 1 is added to the sum for the device. If the status
code is greater than the low value and less than the high value, then measurement 2 is added to
the sum for the device, otherwise the average of measurement 1 and 2 is added to the sum for the
device.
For devices with codes "D" and "E", just the low value is used and if the device status code is
less than or equal to the low value, then measurement 1 is summed in , otherwise the average of
measurements 1 and 2 is summed in.
Additionally print neatly formatted (identical to the example below) output of the data read in.
An example run with the program for this problem follows:
$ cat dat1
B352.7842 4.125
C424.3354 -9.011
E872.2169 1.552
B233.0701-18.632
D621.7537 2.341
C430.2527 -8.303
E863.7962 -4.978
B252.3949 18.347
E903.4536 17.243
D742.8008-15.528
$ ./a.out lab 3(a) solution by
B 35 2.7842 4.125
C 42 4.3354 -9.011
E 87 2.2169 1.552
B 23 3.0701 -18.632
D 62 1.7537 2.341
C 43 0.2527 -8.303
E 86 3.7962 -4.978
B 25 2.3949 18.347
E 90 3.4536 17.243
D 74 2.8008 -15.528
sumA= 0.00000000
sumB= 9.59000015
sumC= 4.58809996
sumD= -4.31624985
sumE= 11.6418495
A partial FORTRAN 90 program to accomplish the goals of this problem follows:
!lab 3(a) solution by
program lab3_a
implicit none
character ::code
integer::ic
integer :: InputStatus
real :: sumA=0.0,sumB=0.0,sumC=0.0,sumD=0.0,sumE=0.0
real v1,v2,val
integer:: low,high
print *, "lab 3(a) solution by "
do
read(5,"
if( )exit
write(*,"
select case (code)
case('A')
low=20; high=70
sumA=sumA+val
case ('B')
low=30; high=60
sumB=sumB+val
case ('C')
low=50; high = 90
sumC=sumC+val
case ('D')
low=50
sumD=sumD+val
case ('E')
low=30
sumE=sumE+val
end do
print *, "sumA=",sumA
print *, "sumB=",sumB
print *, "sumC=",sumC
print *, "sumD=",sumD
print *, "sumE=",sumE
end program lab3_a
Explanation / Answer
Classic case of four one-way traffic deadlock
Detection
To detect the deadlock situation let us consider each road as resources R1, R2, R3 and R4. Here we can see that each car waiting to enter the four way junction is actually waiting for each of these resources. Let us consider each of the cars as P1, P2, P3 and P4. Here, P1 is waiting for R2 which is currently occupied by P2 which in turn is waiting for R3. R3 is occupied by P3 which is waiting for R4 which is again occupied by P4 awaiting R1 to get free.
Recovery
To recover from this deadlock a victim has to be identified i.e.at least one process or car has to removed from the deadlock. This car has to restart from the beginning or from a midpoint.
There are several methods in this recovery process.
One is to terminate or remove all the cars involved in the deadlock and ask them to restart from the beginning.
Another process can be to terminate or remove one car at a time and check if the deadlock is resolved.
Prevention
Prevention of deadlock can be done by following several methods. First and foremost is to limiting the number of processes or cars in this case in the system. Also the number of processes and resources should be optimised so that the resources are well utilised. All this can prevent the deadlock from happening again.
5. a) The victim in this four way deadlock system can be randomly chosen one at a time from all the cars in the system and check each time to see if the deadlock has been resolved.
b) The fate of the victim is pretty harsh. The victim has to either restart from the beginning or from a convenient midpoint.
c) The victim has to either restart the whole process from the beginning or from a convenient midpoint and go through the entire process again.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.