Funnel Heap - A Cache-Oblivious Priority Queue Gerth Stlting Brodal - - PowerPoint PPT Presentation

funnel heap
SMART_READER_LITE
LIVE PREVIEW

Funnel Heap - A Cache-Oblivious Priority Queue Gerth Stlting Brodal - - PowerPoint PPT Presentation

Funnel Heap - A Cache-Oblivious Priority Queue Gerth Stlting Brodal Rolf Fagerberg BRICS University of Aarhus Thirteenth International Symposium on Algorithms and Computation Vancouver, BC, Canada, November 22, 2002 1 Outline of talk


slide-1
SLIDE 1

Funnel Heap

  • A Cache-Oblivious Priority Queue

Gerth Stølting Brodal Rolf Fagerberg

BRICS

University of Aarhus

Thirteenth International Symposium on Algorithms and Computation Vancouver, BC, Canada, November 22, 2002

1

slide-2
SLIDE 2

Outline of talk

  • Cache-oblivious model
  • Cache-oblivious results
  • Cache-oblivious priority queues
  • Funnel heap

– k - merger – the data structure – operations

Brodal, Fagerberg: Funnel Heap

2

slide-3
SLIDE 3

The Classic RAM Model

The RAM model:

CPU A R M

Add: O(1) Mult: O(1) Mem access: O(1)

Brodal, Fagerberg: Funnel Heap

3

slide-4
SLIDE 4

The Classic RAM Model

The RAM model:

CPU A R M

Add: O(1) Mult: O(1) Mem access: O(1) Real life:

Disk CPU L2 L1 A R M C a c C c a e h h e

Bottleneck: transfer between two highest memory levels in use

Brodal, Fagerberg: Funnel Heap

3

slide-5
SLIDE 5

The I/O Model

CPU External I/O Memory y r

  • m

e M

N = problem size M = memory size B = I/O block size

Aggarwal and Vitter 1988

  • One I/O moves B consecutive records from/to disk
  • Cost: number of I/Os

Scan(N) = O(N/B) Sort(N) = O

N

B logM/B N B

  • Brodal, Fagerberg: Funnel Heap

4

slide-6
SLIDE 6

Cache-Oblivious Model

Frigo, Leiserson, Prokop, Ramachandran 1999

  • Program in the RAM model
  • Analyze in the I/O model (for arbitrary B and M)

Advantages

  • Optimal on arbitrary level ⇒ optimal on all levels
  • B and M not hard-wired into algorithm

Brodal, Fagerberg: Funnel Heap

5

slide-7
SLIDE 7

Cache-Oblivious Results

  • Scanning ⇒ stack, queue, selection, . . .
  • Sorting, matrix multiplication, FFT

Frigo, Leiserson, Prokop, Ramachandran, FOCS’99

  • Cache oblivious search trees

Prokop 99 Bender, Demaine, Farach-Colton, FOCS’00 Rahman, Cole, Raman, WAE’01 Bender, Duan, Iacono, Wu and Brodal, Fagerberg, Jacob, SODA’02

  • Priority queue and graph algorithms

Arge, Bender, Demaine, Holland-Minkley, Munro, STOC’02

  • Computational geometry

Bender, Cole, Raman, ICALP’02 Brodal, Fagerberg, ICALP’02

  • Scanning dynamic sets

Bender, Cole, Demaine, Farach-Colton, ESA’02

Brodal, Fagerberg: Funnel Heap

6

slide-8
SLIDE 8

Priority Queues

Insert(e) DeleteMin Classic RAM:

  • Heap:

O(log2 n) time

Williams 1964

Brodal, Fagerberg: Funnel Heap

7

slide-9
SLIDE 9

Priority Queues

Insert(e) DeleteMin Classic RAM:

  • Heap:

O(log2 n) time, O

  • log2

N M

  • I/Os

Williams 1964

Brodal, Fagerberg: Funnel Heap

7

slide-10
SLIDE 10

Priority Queues

Insert(e) DeleteMin Classic RAM:

  • Heap:

O(log2 n) time, O

  • log2

N M

  • I/Os

Williams 1964

I/O model:

  • Buffer tree: O

1

B logM/B N B

  • = O

Sort(N)

N

  • I/Os

Arge 1995

Brodal, Fagerberg: Funnel Heap

7

slide-11
SLIDE 11

Cache-Oblivious Priority Queues

  • O

1

B logM/B N B

  • I/Os

Arge, Bender, Demaine, Holland-Minkley, Munro 2002

– Uses sorting and selection as subroutines – Requires tall cache assumption, M ≥ B2

Brodal, Fagerberg: Funnel Heap

8

slide-12
SLIDE 12

Cache-Oblivious Priority Queues

  • O

1

B logM/B N B

  • I/Os

Arge, Bender, Demaine, Holland-Minkley, Munro 2002

– Uses sorting and selection as subroutines – Requires tall cache assumption, M ≥ B2

  • Funnel heap

This talk – Uses only binary merging – Profile adaptive, i.e. O

1

B logM/B Ni B

  • I/Os

Ni is either the size profile, max depth profile, or #insertions during the lifetime of the ith inserted element

Brodal, Fagerberg: Funnel Heap

8

slide-13
SLIDE 13

Merge Trees

✲ ✸ s

Binary merger

Brodal, Fagerberg: Funnel Heap

9

slide-14
SLIDE 14

Merge Trees

✲ ✸ s

Binary merger

✲ ✍ ◆ ✲ ✣ ❫ ✲ ✸ s ✲ ✶ q ✲ ✶ q ✲ ✸ s ✲ ✶ q ✲ ✶ q ✲ ✣ ❫ ✲ ✸ s ✲ ✶ q ✲ ✶ q ✲ ✸ s ✲ ✶ q ✲ ✶ q

Merge tree

Brodal, Fagerberg: Funnel Heap

9

slide-15
SLIDE 15

Merging Algorithm

Fill(v) while out-buffer not full if left in-buffer empty Fill(left child) if right in-buffer empty Fill(right child) perform one merge step ✲ ✍ ◆ ✲ ✣ ❫ ✲ ✸ s ✲ ✶ q ✲ ✶ q ✲ ✸ s ✲ ✶ q ✲ ✶ q ✲ ✣ ❫ ✲ ✸ s ✲ ✶ q ✲ ✶ q ✲ ✸ s ✲ ✶ q ✲ ✶ q

Brodal, Fagerberg: Funnel Heap

10

slide-16
SLIDE 16

k - merger

k3 k

B1 B0 · · · · · · M1 M√ k M0 B√ k · · · M0 M1 B1 B√ k M√ k B2 M2 B0

Recursive memory layout Recursive defi nition of buffer sizes

Lemma: O( k3

B logM(k3) + k) I/Os per invocation (if M ≥ B2) Frigo, Leiserson, Prokop, Ramachandran 1999 Brodal, Fagerberg 2002

Brodal, Fagerberg: Funnel Heap

11

slide-17
SLIDE 17

The Priority Queue

✛ ✻ ✻ ✻✻ ✛ ✻ ✻ ✻✻ ✻

··

✛ ✛ · · · ✛ ✻ ✻ ✻✻ ✻

· · ·

✛ ✛ · · · ✛ ✻ ✻ ✻✻ ✻

· · · ·

A1 B1 s1 s1 v1 Ai vi Bi ki si si si Link i I

Brodal, Fagerberg: Funnel Heap

12

slide-18
SLIDE 18

The Priority Queue

✛ ✻ ✻ ✻✻ ✛ ✻ ✻ ✻✻ ✻

··

✛ ✛ · · · ✛ ✻ ✻ ✻✻ ✻

· · ·

✛ ✛ · · · ✛ ✻ ✻ ✻✻ ✻

· · · ·

A1 B1 s1 s1 v1 Ai vi Bi ki si si si Link i I

ki+1 ≈ k4/3

i

si+1 ≈ s4/3

i

ki ≈ s1/3

i

Brodal, Fagerberg: Funnel Heap

12

slide-19
SLIDE 19

The Priority Queue

✛ ✻ ✻ ✻✻ ✛ ✻ ✻ ✻✻ ✻

··

✛ ✛ · · · ✛ ✻ ✻ ✻✻ ✻

· · ·

✛ ✛ · · · ✛ ✻ ✻ ✻✻ ✻

· · · ·

A1 B1 s1 s1 v1 Ai vi Bi ki si si si Link i I

ki+1 ≈ k4/3

i

si+1 ≈ s4/3

i

ki ≈ s1/3

i

In total: A single binary merge tree

Brodal, Fagerberg: Funnel Heap

12

slide-20
SLIDE 20

Operations — DeleteMin

·· · · · · · · · · · · · · · A1 v1 I

  • If A1 is empty, call Fill(v1)
  • Search I and A1 for minimum element

Brodal, Fagerberg: Funnel Heap

13

slide-21
SLIDE 21

Operations — Insert

·· · · · · · · · · · · · · · ki I c1 c2 ci

  • Insert in I
  • If I overflows, call Sweep(i) for first i where ci ≤ ki

Sweep ≈ addition of one to number c1c2..ci..cmax si = s1 + i−1

j=1 kjsj

Brodal, Fagerberg: Funnel Heap

14

slide-22
SLIDE 22

Analysis

·· · · · · · · · · · · · · ·

We can prove:

  • Number N of insertions performed:

simax ≤ N

  • Number of I/Os per Insert for link i:

O

  • 1

B logM/B si

  • By the doubly-exponentially growth of si,

the total number of I/Os per Insert is O

  • k=0

1 B logM/B N (3/4)k

  • = O

1

B logM/B N

  • DeleteMin is amortized for free

Brodal, Fagerberg: Funnel Heap

15

slide-23
SLIDE 23

Profile Adaptive

·· · · · · · · · · · · · · ·

  • Modify Insert to apply Sweep(i) for

– first i where ci ≤ ki, or – link i is at most half-full, i.e. there exists Sij1 and Sij2 that can be merged

  • O

1

B logM/B Ni B

  • I/Os

Brodal, Fagerberg: Funnel Heap

16

slide-24
SLIDE 24

Conclusions

·· · · · · · · · · · · · · ·

  • Funnel heap - a cache-oblivious priority queue
  • Profile adaptive
  • Requires tall cache assumption

(necessary requirement Brodal, Fagerberg 2002)

Open problem

  • Worst-case bounds

Brodal, Fagerberg: Funnel Heap

17