Tutorial 1 Answers for Questions 5 and 6 5a) The easiest way to do this is to split the list into two parts. CPU I will sum up part A and place it’s result back into shared memory. CPU II will sum up part B and place its results into shared memory also. CPU A will then take both results, sum it up to produce the final answer. Note that there may be a need for part A to do some synchronization at the end before it computes the final sum – i.e. it must wait for CPU II to place it’s results before it can proceed. This can be done easily with a binary semaphore. 5b) Now that we have many processors, the above technique may not be too convenient. To see why: for m numbers with n CPUs, the first pass will require sums on ceil(m/n) (ceil(x) rounds up the value x, so ceil(1.2) = 2, ceil(2.0) = 2, ceil(2.3) = 3 etc.). This produces a total of ceil(m/n)partial sums that must again be divided up amongst the n CPUs, giving us ceil(m/n2) partial sums, which must again be divided up amongst the n CPUs all the way till there is only 1 grand sum. Note that at each step synchronization across all n CPUs is necessary before the next pass can be made, to ensure that all the partial sums are in. An easier way to accomplish this is for each processor to independently delete 2 numbers from the set, sum them up, and place the result back into the list, up to the point that there is only one number left. This one number is the result. E.g.: Sum 1, 3, 5, 5, 7, 9, 10 on 3 CPUs. Pass I: CPU I takes 1+3 = 4 CPU II takes 5+5 = 10 CPU III takes 7+9 = 16. All three write their results back to the list. The list is now updated with 10, 4, 10, 16. Pass II: CPU I takes 10 + 4 = 14, CPU II takes 10+16 = 26 and both write their results back to the list. The list is now 14, 26 Pass III: CPU I takes 14 + 26 = 40, and writes it back to the list. The list now contains 40, the final sum. Little synchronization is needed between processes. 6a) (Please refer to diagram). At this point, without interrupts, the CPU cannot proceed until the I/O is ready, and hence each 110 ms I/O operation results in 110 ms of CPU idle time. Total time is: 10 + 5 + 110 + 5 + 25 + 5 + 110 + 5 + 75 + 5 + 110 + 5 = 470 ms 6b) The important thing to understand for this part is that I/O and CPU can proceed together, and that I/O will interrupt the CPU once it is done. CPU I/O 10 5i 25 5o 5i 110 75 5o 5i 110 5o 110 5i = 5 ms before I/O operatioon, 5o = 5 ms after I/O operation Beyond the first 15 ms, the I/O dominates the execution time. After the 25ms CPU burst, I/O request cannot be made as the I/O device is busy, so there is a (110 – 25) = 85 ms idle time. Once I/O is completed, the CPU is interrupted and 5 ms is needed to handle the interrupt, and a further 5 ms is needed to start a new I/O. Then the CPU executes the 75 ms burst. It cannot begin the third I/O as the I/O is busy, so the system is idle for (110 – 75) = 35 ms. After the I/O completes. 5ms is spent processing after the I/O, and a further 5 ms is spent starting the third I/O. After the third I/O completes, 5 ms is spent for I/O completion. Total time: 15 + 110 + 5 + 5 + 110 + 5 + 5 + 110 + 5 = 370 ms. 6c) CPU I/O 10 5i 15 15 5o 10 5i 15 15 5o 60 5i 5o 15 5i = 5 ms before I/O operatioon, 5o = 5 ms after I/O operation Here execution is actually dominated by the CPU time, since I/O time is shorter than the CPU burst times. After the initial 10ms CPU burst, I/O is initiated taking 5 ms. The 15 ms of I/O runs concurrently with the 25ms CPU burst, but after 15 ms the 25ms CPU burst is interrupted. It takes 5 ms to process the interrupt, after which the 25ms burst is resumed for a further 10 ms. It then makes an I/O request, taking 5 ms. The I/O is carried out simultaneously with the 75 ms CPU burst. After 15 ms, the 75 ms burst is interrupted. 5ms is spent handling the interrupt, after which the 75 ms burst resumes for the remaining 60 ms. It then spends 5 ms making the 3rd I/O request, and now since there are no more CPU bursts the CPU remains idle throughout the 15 ms of I/O. After that 5 ms is spent handling the interrupt that occurs when the I/O completes. So we have a total time of: 10 + 5 + 15 + 5 + 10 + 5 + 15 + 5 + 60 + 5 + 15 + 5 = 155 ms. 6d) For a), CPU is idle for all I/O accesses. So idle time is 110 x 3 = 330 ms For b), CPU is idle for 85 ms, 35 ms and 110 ms. Total time is 230 ms For c), CPU is idle only at the last I/O operation. So CPU is idle for 15 ms.