cache-oblivious dynamic dictionaries with optimal update/query tradeoff

40
Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff Gerth Stølting Brodal Aarhus University Dansk Selskab for Datalogi, Frederiksbjerg, October 13, 2010 Indeksstrukturer til Ekstern Hukommelse

Upload: dora

Post on 24-Feb-2016

70 views

Category:

Documents


0 download

DESCRIPTION

Indeksstrukturer til Ekstern Hukommelse. Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff. Gerth Stølting Brodal Aarhus University. Dansk Selskab for Datalogi, Frederiksbjerg , October 13, 2010. Gerth Stølting Brodal. Kurt Mehlhorn. 2007-. 1994-2006. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Gerth Stølting BrodalAarhus University

Dansk Selskab for Datalogi, Frederiksbjerg, October 13, 2010

Indeksstrukturer til

Ekstern Hukommelse

Page 2: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

AU1983

September1989August

1993January

1994November

M.Sc.

1997January

PhD

2004April

Associate Professor

1969September

1998August

MPII MPII

April

AU

M.Sc.PhD Post Doc Faculty

1994-2006 2007-

AU

Eric Meineche Schmidt

Kurt Mehlhorn

Gerth Stølting Brodal

Page 3: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff
Page 4: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff
Page 5: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Center of Lars Arge, Professor, Centerleader Gerth S. Brodal, Associate Professor 5 Post Docs, 10 PhD students, 4 TAP Total budget for 5 years ca. 60 million DKR

Arge Brodal Mehlhorn MeyerDemaine Indyk

AU MIT

MPI

I

Fran

kfur

t

Page 6: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Cache Oblivious Algorithms

Streaming Algorithms

Algorithm Engineering

I/O Efficient Algorithms

Page 7: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

+

Page 8: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

The problem...

input size

runn

ing

time

Normal algorithm

I/O-efficient algorithm

bottleneck = memory size

Page 9: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Memory Hierarchies

ProcessorL1 L2 A

R

ML3 Disk

bottleneck

increasing access times and memory sizes

CPU

Page 10: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Memory Hierarkiesvs.

Running Time

datastørrelse

køre

tid

L1 RAML2 L3

Page 11: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Memory Access Times

Latency Relative to CPU

Register 0.5 ns 1

L1 cache 0.5 ns 1-2

L2 cache 3 ns 2-7

DRAM 150 ns 80-200

TLB 500+ ns 200-2000

Disk 10 ms 107

Page 12: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Disk Mechanicstrack

magnetic surface

read/write armread/write head

“The difference in speed between modern CPU and disk technologies is analogous to the difference in speed in sharpening a pencil using a sharpener on one’s desk or by taking an airplane to the other side of the world and using a sharpener on someone else’s desk.” (D. Comer)

• I/O is often bottleneck when handling massive datasets • Disk access is 107 times slower than main memory access!• Disk systems try to amortize large access time transferring

large contiguous blocks of data• Need to store and access data to take advantage of blocks !

Page 13: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Internal Memory Index

Page 14: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

B(oing)-Trees Bayer og McCreight (1971)

One node = one disk block

Height O(logB N)

Page 15: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

B-trees -The Basic Searching Structure

SearchesPractice: 4-5 I/Os

....

B

Search path

Internal memory

Repeated searchingPractice: 1-2 I/Os

Page 16: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

The Bad News...

Searching any external memory dictionary (incl. B-trees) requires worst-case

Ω(logB N) I/Os

x x x x xx x?N

≥ (N - B) / (B + 1)

Proof idea:

x x xxx x x

Page 17: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

B-trees

Searches O(logB N) I/Os

....

B

Search path

Internal memory

Updates O(logB N) I/Os

Best possible

?

Page 18: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

B-trees with Buffered Updates

....

d

Brodal and Fagerberg (2003)

B

x xx x

N updates cost

O(N log∙ d N ∙ d / B) I/Os = O(N log∙ B N ∙ 1/εB1-ε)

I/Os

Searches cost

O(logd N) I/Os = O(logB N ∙ 1/ε) I/Os

= Bε

2

2 / √B

Trade-off between search and update times – optimal !

Page 19: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

B-trees with Buffered Updates Brodal and Fagerberg (2003)

Page 20: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

B-trees with Buffered UpdatesExperimental Study

•100.000.000 elements

•Search time basically unchanged with buffers

•100 times faster updates

Hedegaard (2004)

Page 21: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

ProcessorL1 L2 A

R

ML3 Disk

bottleneck

increasing access times and memory sizes

CPU

Assumptions until now : B is known + one level is the bottleneck

Page 22: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Processor R

MAL3L1 L2 Disk

increasing access times and memory sizes

CPU

Cache-Obliviousnes Model

M

B

Algorithm does not know B and M (assume optimal offline cache-replacement strategy)

Frigo, Leiserson, Prokop, Ramanchandran (1999)

Page 23: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

I/O Efficient Scanning

sum = 0for i = 1 to N do sum = sum + A[i]

N

B

A

O(N/B) I/Os

Page 24: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff
Page 25: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

B(oing)-Trees Bayer og McCreight (1971)

One node = one disk block

Height O(logB N)

Page 26: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Recursive Search Tree Layout(Cache-Obliviousness)

Searches require O(logB N) I/Os(small subtrees have √B ≤ size ≤ B, a path traverses at most 2 log∙ B N trees)

Frigo (1999)

Page 27: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Experiments : Binary Tree Layout Brodal, Fagerberg, Jacob (2002)

Page 28: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Searches with Pointer Layout

• van Emde Boas layout wins, followed by the BFS layout van Emde Boas layout

Brodal, Fagerberg, Jacob (2002)

Page 29: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Searches with Implicit Layout

• BFS layout wins due to simplicity and caching of topmost levels• van Emde Boas layout requires quite complex index computations

Brodal, Fagerberg, Jacob (2002)

Page 30: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Searches with Pointer Layout - Beyond Main Memory

• van Emde Boas layout wins, followed by the BFS layout

Brodal, Fagerberg, Jacob (2002)

Page 31: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Optimal Cache-Oblivious Static Index

= van Emde Boas Layout of Complete Binary Tree

Brodal, Fagerberg, Jacob (2002)

Page 32: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Cache-Oblivious Dynamic Index ?

Page 33: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Binary Search Trees Dynamic

• Embed a dynamic tree of small height into a complete tree• Static van Emde Boas layout• Rebuild data structure whenever N doubles or halves

Brodal, Fagerberg, Jacob (2002)

Page 34: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Rebalancing Subtree during InsertionBrodal, Fagerberg, Jacob (2002)Brodal, Fagerberg, Jacob (2002)

Andersson and Lai (1990)

• If an insertion causes non-small height then rebuild subtree at nearest ancestor with sufficient few descendants

• Insertions require amortized time O(log2 N)

Page 35: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Optimal Cache-Oblivious Dynamic IndexBrodal, Fagerberg, Jacob (2002)

• Search O(logB N) I/Os (optimal)

• Updates O(logB N + (log2 N) / B) I/Os

Page 36: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Cache-Oblivious Indexwith Query-Update Trade-off ?

Page 37: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

Cache-Oblivious Dynamic Dictionarieswith Query-Update Trade-off

• Solution matching the I/O complexity of Buffered B-trees

• Searches O(logB N ∙ 1/ε) I/Os

• N updates O(N log∙ B N ∙ 1/εB1-ε) I/Os

Brodal, Demaine, Fineman, Iacono, Langerman, Munro (2010)

Page 38: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

xDict

Insert• Insert into smallest box• When a box reaches capacity, Flush it and Batch-Insert

into the next boxSearch• Search in each x-box• O(logB x) cost is dominated by largest box O(logB N)

221-box 222-box 22lglgN-box…

Brodal, Demaine, Fineman, Iacono, Langerman, Munro (2010)

Page 39: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

size-x input buffer

size-x2 output buffer

size-x3/2 middle buffer

√x-box

√x-box

Upper level: at most x1/2/4 subboxes

Lower level: at most x /4 subboxes

input middle… … output

subboxes stored contiguously in arbitrary

order

Unused (currently empty) subboxes are

preallocated

x-Box (capacity x2)Brodal, Demaine, Fineman, Iacono, Langerman, Munro (2010)

Memory Layout

Batch in

sert

x elements

Flus

h

Page 40: Cache-Oblivious Dynamic Dictionaries with Optimal Update/Query Tradeoff

External Memory Index

....d

B

= Bε

……

• Searches O(logB N ∙ 1/ε) I/Os

• N updates O(N log∙ B N ∙ 1/εB1-ε) I/Os