17.01.2013 Views

Algorithms and Data Structures for External Memory

Algorithms and Data Structures for External Memory

Algorithms and Data Structures for External Memory

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

46 <strong>External</strong> Sorting <strong>and</strong> Related Problems<br />

blocks of Σ in reverse order. In the case of the write-once problem, the<br />

following natural greedy output algorithm is optimum: As the blocks<br />

of Σ R are written, we put each block into an output buffer <strong>for</strong> its<br />

designated disk. There are m output buffers, each capable of storing<br />

one block, so the writing can proceed only as quickly as space is freed<br />

up in the write buffers. In each parallel I/O step, we free up space by<br />

outputting a queued block to each disk that has at least one block in<br />

an output buffer. The schedule of I/O output steps is called the output<br />

schedule, <strong>and</strong> it is easy to see that it is optimum in terms of the number<br />

of parallel I/O steps required. Figure 5.6, when read right to left, shows<br />

the output schedule <strong>for</strong> the reverse sequence Σ R .<br />

When we run any output schedule <strong>for</strong> Σ R in reverse, we get a valid<br />

prefetch schedule <strong>for</strong> the original sequence Σ, <strong>and</strong> vice versa. There<strong>for</strong>e,<br />

an optimum output schedule <strong>for</strong> Σ R , which is easy to compute in a<br />

greedy fashion, can be reversed to get an optimum prefetch schedule<br />

<strong>for</strong> Σ. Figure 5.6, when considered from right to left, shows an optimum<br />

output schedule <strong>for</strong> sequence Σ R . When looked at left to right, it shows<br />

an optimum prefetch schedule <strong>for</strong> sequence Σ.<br />

The prefetch schedule of Figure 5.6 is “lazy” in the sense that the<br />

input I/Os seem to be artificially delayed. For example, cannot block e<br />

be input earlier than in step 4? Hutchinson et al. [202] give a prudent<br />

prefetching algorithm that guarantees the same optimum prefetch<br />

schedule length, but per<strong>for</strong>ms I/Os earlier when possible. It works by<br />

redefining the priority of a block to be the order it appears in the input<br />

step order of the lazy schedule (i.e., a, b, f, c, i, . . . in Figure 5.6).<br />

Prefetch buffers are “reserved” <strong>for</strong> blocks in the same order of priority.<br />

In the current I/O step, using the language of Section 5.3.1, we input<br />

every block in P that has a reserved prefetch buffer. Figure 5.7 shows<br />

the prudent version of the lazy schedule of Figure 5.6. In fact, if we<br />

iterate the prudent algorithm, using as the block priorities the input<br />

step order of the prudent schedule of Figure 5.7, we get an even more<br />

prudent schedule, in which the e <strong>and</strong> n blocks move up one more I/O<br />

step than in Figure 5.7. Further iteration in this particular example<br />

will not yield additional improvement.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!