1.Suppose we have the internal memory that can handle 12 numbers at a time, and the following two runs on the tapes:
Run 1: 1, 3, 5, 7, 8, 9, 10, 12
Run 2: 2, 4, 6, 15, 20, 25, 30, 32
Use 2-way merge with 4 input buffers and 2 output buffers for parallel operations. Which of the following three operations are NOT done in parallel?
(3分)
A.1 and 2 are written onto the third tape; 3 and 4 are merged into an output buffer; 6 and 15 are read into an input buffer
B.3 and 4 are written onto the third tape; 5 and 6 are merged into an output buffer; 8 and 9 are read into an input buffer
C.5 and 6 are written onto the third tape; 7 and 8 are merged into an output buffer; 20 and 25 are read into an input buffer
D.7 and 8 are written onto the third tape; 9 and 15 are merged into an output buffer; 10 and 12 are read into an input buffer
工作原理:buffer 一个一个按顺序被写。两个run轮流对buffer进行写。
需要注意的是:如果之前有没有merge完成的,比较复杂,需要等待。
一共4+2个buffer, 内存有12个数,因此每个buffer2个数。六个buffer,后两个是输出的
1.写入buffer1,此时没有merge条件
1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|
1,3 | |||||
2.写入第2个buffer | |||||
1 | 2 | 3 | 4 | 5 | 6 |
- | - | - | - | - | - |
1,3 | 2,4 | ||||
3.写入buffer3 1,2merege,写入output buffer |
1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|
3 | 4 | 5, 7 | 1,2 |
4.写入bufferr4 1,2 merge,5写入磁盘,所以写入6
1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|
5, 7 | 6, 15 | 3,4 | |||
5.写入buffer1 1,3merge,6写入磁盘 |
1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|
8,9 | 7 | 15 | 5, 6 |
6.写入buffer2, 1,3 merge, 5写入磁盘
1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|
9 | 20, 25 | 15 | 7,8 |
7.写入buffer3, delay, 6写入磁盘
1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|
9 | 20, 25 | 10,12 |
8.写入buffer4, 1,3 merge
…
这题A描述的是3->4, B描述的是4->5,C描述的是5->6, D错在不是9和15 merge, 9和10 merge