Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf ·...

53
Algorithm Engineering for Large Data Sets Roman Dementiev Institute for Theoretical Computer Science, Algorithmics II University of Karlsruhe Department 1: Algorithms and Complexity Max-Planck-Institut für Informatik 1 Dec 2006 Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 1/39

Transcript of Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf ·...

Page 1: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Algorithm Engineering for Large Data Sets

Roman Dementiev

Institute for Theoretical Computer Science, Algorithmics IIUniversity of Karlsruhe

Department 1: Algorithms and ComplexityMax-Planck-Institut für Informatik

1 Dec 2006

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 1/39

Page 2: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Outline

1 Introduction

2 Experimental Parallel Disk System

3 The STXXL Library

4 Engineering Algorithms for Large Graphs

5 Engineering Large Suffix Array Construction

6 Porting Algorithms to External Memory

7 Summary

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 2/39

Page 3: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Large Data Sets

Where they come fromGeographic information systems: GoogleEarth, NASA’s World Wind

Computer graphics: visualize huge scenes

Billing systems: phone calls, traffic

Analyze huge networks: Internet, phone call graph

Text collections: , , etc.

How to process themBuy a TByte main memory? impossible

Buy many computers (a cluster)? expensive

Here: how to process very large data sets cost-efficiently

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 3/39

Page 4: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Large Data Sets

Where they come fromGeographic information systems: GoogleEarth, NASA’s World Wind

Computer graphics: visualize huge scenes

Billing systems: phone calls, traffic

Analyze huge networks: Internet, phone call graph

Text collections: , , etc.

How to process them

Buy a TByte main memory? impossible

Buy many computers (a cluster)? expensive

Here: how to process very large data sets cost-efficiently

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 3/39

Page 5: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

RAM Model vs. Real Computer

A straightforward solutionUse small main memorykeep data on cheap disks, “unlimited” virtual memoryTheory: should work (von Neumann (RAM) model)I Unit cost memory accessI No locality of reference

ALUO(1) registers

1 word = O(log n) bits

large memoryfreely programmable

Practice: terrible performanceI Random hard disk accesses are 106 slower

than main memory accessesI Strong locality of reference

⇒ I/O is the bottleneck

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 4/39

Page 6: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

The Parallel Disk Model (PDM)

[Vitter&Shriver’1994]

ParametersInput size N

Memory size M � N

Block size B

The number of disks D

PerformanceMinimize the number of I/O steps

In an I/O step try transfer D blocks

Minimize the number of CPUinstructions

�������������������������������������������������

�������������������������������������������������

�������������������������������������������������

�������������������������������������������������

M

CPU

DB

...1 2 D

I/O-efficient algorithms ≡ external memory algorithms

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 5/39

Page 7: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Engineering Parallel Disk Systems

PCI−Busses

Controller

Channels

2x Xeon

2x64x66 Mb/s

4 Threads

E7500 128

400x64 Mb/s

MB/s4x2x100

8x80GBMB/s

Chipset

Intel

8x45

RAMDDR1 GB

ChallengesCheap case for ≥ 8 hard disks

Many fast PCI slots for ATA controllers (no bus bottlenecks)

Wide Parallel ATA cables worsen airflow (later system use Serial ATA)

File system scalability: very large files

⇒ 375 MB/s (≈ 98% of the peak) for about 3000 Euro in 2002

⇒ Other systems: 10 disks = 640 MB/s, 4 disks = 214 MB/s

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 6/39

Page 8: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

The STXXL Library

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 7/39

Page 9: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

I/O-Efficient Software Libraries

AdvantagesAbstract away the technical details of I/O

Provide implementation of basic I/O-eff. algorithms and data structures

⇒ Boost algorithm engineering

Existing LibrariesTPIE: many (geometric) search data structures

LEDA-SM: extension of LEDA (discontinued)

+ Good demonstrations of the external memory concepts

– Do not implement many features that speed up I/O-efficient algorithms

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 8/39

Page 10: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

I/O-Efficient Software Libraries

AdvantagesAbstract away the technical details of I/O

Provide implementation of basic I/O-eff. algorithms and data structures

⇒ Boost algorithm engineering

Existing LibrariesTPIE: many (geometric) search data structures

LEDA-SM: extension of LEDA (discontinued)

+ Good demonstrations of the external memory concepts

– Do not implement many features that speed up I/O-efficient algorithms

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 8/39

Page 11: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

The STXXL Library

STL – C++ Standard Template Library, implements basic containers(maps, sets, priority queues, etc.) and algorithms (quicksort, mergesort,selection, etc.)

STXXL : Standard Template Library for XXL Data Setshttp://stxxl.sourceforge.net

containers and algorithms that can process huge volumes of data thatonly fit on disks (I/O-efficient)I Compatible with STLI Performance–oriented

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 9/39

Page 12: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

STXXL Features

Dementiev, Kettner, SandersSTXXL: The Standard Template Library for Extra Large Data Sets.ESA 2005, 13th Annual European Symposium on Algorithms

Transparent parallel disk support

Handles very large problems (up to petabytes)

Pipelining saves many I/Os

Explicitly overlaps I/O and computationAvoids superfluous copyingI in OS I/O subsystem and the library itself

Compatible with STL – C++ Standard Template LibraryI Short development timesI Reuse of STL code (e.g. selection alg.)

�������������������������������������������������

�������������������������������������������������

�������������������������������������������������

�������������������������������������������������

M

CPU

DB

...1 2 D

����������������������������������������������������

����������������������������������������������������

������������������������������������������

������������������������������������������

������������������������������������������

������������������������������������������

SC

AN

SO

RT

SC

AN

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 10/39

Page 13: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

STXXL Design

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

�������������������������������������������������������������������������������������������������������������������������������������������������������������������������

�������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

TX

XL

S

files, I/O requests, disk queues,

block prefetcher, buffered block writer

completion handlers

Block management (BM) layertyped block, block manager, buffered streams,

Containers:

STL−user layervector, stack, set

priority_queue, mapsort, for_each, merge

Pipelined sorting,zero−I/O scanning

Streaming layer

Algorithms:

Operating System

Applications

Asynchronous I/O primitives (AIO) layer

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 11/39

Page 14: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

STXXL Design: AIO Layer

Hides details of async. I/O(portability, user-friendly)

Implementations forLinux/MacOSX/BSD/Solarisand Windows systems

Asynchrony provided byPOSIX threads or BoostThreads

Unbuffered I/O support:more control over I/O

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

files, I/O requests, disk queues,

completion handlers

Asynchronous I/O primitives (AIO) layer

block prefetcher, buffered block writer

Block management (BM) layertyped block, block manager, buffered streams,

Containers:

STL−user layervector, stack, set

priority_queue, mapsort, for_each, merge

Pipelined sorting,zero−I/O scanning

Streaming layer

Algorithms:

Applications

Operating System

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 12/39

Page 15: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

STXXL Design: BM Layer

Block abstraction

Parallel disk model

(Randomized) striping andcycling

Parallel disk buffered writingand optimal prefetching[Hutchinson&Sanders&Vitter01]

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

files, I/O requests, disk queues,

completion handlers

Operating System

Asynchronous I/O primitives (AIO) layer

block prefetcher, buffered block writer

Block management (BM) layertyped block, block manager, buffered streams,

Containers:

STL−user layervector, stack, set

priority_queue, mapsort, for_each, merge

Pipelined sorting,zero−I/O scanning

Streaming layer

Algorithms:

Applications

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 13/39

Page 16: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

STXXL User Layers

STL-user layer: compatiblewith STL, vector, stack,queue, deque, priority queue,map, sorting, scanning

Streaming layer:programming with pipelining

�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

files, I/O requests, disk queues,

block prefetcher, buffered block writer

completion handlers

Block management (BM) layertyped block, block manager, buffered streams,

Operating System

Asynchronous I/O primitives (AIO) layer

Containers:

STL−user layervector, stack, set

priority_queue, mapsort, for_each, merge

Pipelined sorting,zero−I/O scanning

Streaming layer

Algorithms:

Applications

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 14/39

Page 17: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Streaming Layer and Pipelining

�������������������������������������������������

�������������������������������������������������

�������������������������������������������������

�������������������������������������������������

�������������������������������������������������

�������������������������������������������������

DATA DATA

DATA

SCAN

SORT

SCAN

EM algorithm ⇒ data flow through a DAG

Feed output data stream directly to theconsumer algorithm

A new iterator-like interface for EM algorithms

Basic pipelined implementations (file, sortingnodes, etc.) provided by STXXL

Saves many I/Os (factor 2–3) in many EMalgorithms

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 15/39

Page 18: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Parallel Disk Sorting: an Important Part of STXXL

Sorting is the core routine of almost every I/O-eff. algorithm.

We engineer a parallel disk sorting algorithm and implementation whichguarantees:

1 Optimal I/O volume sort(N) = O(

NDB logM/B

NB

)2 Almost perfect overlapping of I/O and computation

Dementiev and SandersAsynchronous Parallel Disk Sorting.SPAA 2003, 15th ACM Symposium on Parallelism in Algorithms andArchitectures

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 16/39

Page 19: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

I/O-Efficient Multiway Merge Sort

The Algorithm1 Sort input chunks of size Θ(M) (aka runs)2 Θ(M/B)-way merge runs until only one sorted run left

⇒ O(

NB logM/B

NM

)I/Os

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 17/39

Page 20: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

I/O-Efficient Multiway Merge Sort

The Challenges1 Overlapping of I/O and computation:

running time ≈max(IOtime(N),CPUtime(N))

2 Disk balancing: IOtime(N)≈ O

(NB logM/B

NM

D

)

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 18/39

Page 21: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Run Formation: Easy

Two threads cooperate to build k runs of size M/2:

post a read request for runs 1 and 2thread A: | thread B:for r:=1 to k do | for r:=1 to k-2 do

wait until | wait untilrun r is read | run r is written

sort run r | post a read for run r+2post a write for run r |

computebound case

I/Obound case

sort

read

time

control flow in thread A

sort

read

write

1

1

1

2

2

3

2

3

3

4

4

4

...

...

...

k−1

k−1

k−1

k

k

k

control flow in thread B

1 2

2

2

1

1

3

3

3

4

4

4

k−1

k−1

k−1

k

k

k

...

...

...write

Stripe data over the disks

TRF (N) =max(2Tsort(

M2 ) N

M ,TIO(N))+Tstartup

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 19/39

Page 22: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

External Multiway Merging

The smallest element of a block is a trigger

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 20/39

Page 23: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Overlaping I/O and Merging

Prediction of delay between issuing two reads is not easy:

Solution (sketch)1 Integrate k +3D overlap buffers2 Special I/O thread strategy

≥ DB elements in write buffer ⇒ output step< DB elements in write buffer AND D overlap buffers avail. ⇒ input step

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 21/39

Page 24: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Overlaping I/O and Merging

Prediction of delay between issuing two reads is not easy:

Solution (sketch)1 Integrate k +3D overlap buffers2 Special I/O thread strategy

≥ DB elements in write buffer ⇒ output step< DB elements in write buffer AND D overlap buffers avail. ⇒ input step

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 21/39

Page 25: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Overlaping I/O and Merging

Prediction of delay between issuing two reads is not easy:

Solution (sketch)1 Integrate k +3D overlap buffers2 Special I/O thread strategy

≥ DB elements in write buffer ⇒ output step< DB elements in write buffer AND D overlap buffers avail. ⇒ input step

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 21/39

Page 26: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Disk Scheduling

Use randomized striping allocation [Vitter&Hutchinson’2001]

Prefetch buffer of m = O(D) blocks: In almost every input step,(1−O(D/m))D blocks from prefetch sequence δ can be fetched[Dementiev&Sanders’2003]

ResultFor any ε , m = Θ(D/ε)prefetch buffers, merging ksequences with a total N ′

elements can beimplemented in timemax( 2LN ′

(1−ε)DB ,τN ′)+Tstartup,where L is the time to read ofwrite a block and τ is thetime to merge an element

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 22/39

Page 27: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Disk Scheduling

Use randomized striping allocation [Vitter&Hutchinson’2001]

Prefetch buffer of m = O(D) blocks: In almost every input step,(1−O(D/m))D blocks from prefetch sequence δ can be fetched[Dementiev&Sanders’2003]

ResultFor any ε , m = Θ(D/ε)prefetch buffers, merging ksequences with a total N ′

elements can beimplemented in timemax( 2LN ′

(1−ε)DB ,τN ′)+Tstartup,where L is the time to read ofwrite a block and τ is thetime to merge an element

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 22/39

Page 28: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

STXXL Performance: Sorting

2GHz Xeon, 1GByte RAM, 2 GByte input, 32-bit keysruns of size 256 MByte, g++ 3.2

0

100

200

300

400

500

600

700

800

16 32 64 128 256 512 1024

sort

tim

e [s

]

element size [byte]

LEDA-SMTPIE<stxxl> comparison based

Single diskI/O bandwidth of 45.4 MB/s

= 95% of peak bandwidth of the disk

0

50

100

150

200

16 32 64 128 256 512 1024so

rt ti

me

[s]

element size [byte]

LEDA-SM Soft-RAIDTPIE Soft-RAID<stxxl> Soft-RAID<stxxl>

Eight disksI/O bandwidth of 315 MB/s

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 23/39

Page 29: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Sorting Performance: I/O Bottleneck DisappearsChanging element size

0

50

100

150

200

250

300

350

400

16 32 64 128 256 512 1024

time

[s]

element size [byte]

run formationmergingI/O wait in merge phaseI/O wait in run formation phase

16 GByte input, 32-bit keys, D = 8,runs of size 256 MByte, g++ 3.2

elem. size ≥ 64 ⇒ merging is I/Obound

elem. size ≥ 128 ⇒ run formationis I/O bound

For small elements I/O is not thebottleneck

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 24/39

Page 30: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

STXXL Performance

All other STXXL algorithms and data structures are benchmarked in thethesis against LEDA-SM, TPIE and Berkley DB (B-tree)

STXXL implementations outperform or compete with the opponents

0

500

1000

1500

2000

2500

3000

232230228226224222220

ns p

er o

pera

tion

n

LEDA-SM insertLEDA-SM delete

Stxxl insertStxxl delete

0

10

20

30

40

50

60

232230228226224222220

byte

s pe

r op

erat

ion

n

LEDA-SM insertLEDA-SM delete

Stxxl insertStxxl delete

0

500

1000

1500

2000

2500

232230228226224222220

ns p

er o

pera

tion

n

LEDA-SMStxxl

0

10

20

30

40

50

232230228226224222220

byte

s pe

r op

erat

ion

n

LEDA-SMStxxl

0

100

200

300

400

500

600

700

234232230228226224222220

ns p

er o

pera

tion

n

Stxxl insert D=1Stxxl insert D=2Stxxl insert D=4

0

50

100

150

200

250

234232230228226224222220

ns p

er o

pera

tion

n

Stxxl delete D=1Stxxl delete D=2Stxxl delete D=4

0

100

200

300

400

500

234232230228226224222220

ns p

er o

pera

tion

n

Stxxl intermixed D=1Stxxl intermixed D=2Stxxl intermixed D=4

0

1

2

3

4

5

229228227226225224223

µs p

er in

put r

ecor

d

n

BDB btreeTPIE btreestxxl::map

0

5000

10000

15000

20000

25000

30000

229228227226225224223

µs p

er in

sert

ion

n

BDB btreeTPIE btreestxxl::map

0

2000

4000

6000

8000

10000

12000

14000

16000

18000

229228227226225224223

µs p

er lo

cate

n

BDB btreeTPIE btreestxxl::map

0

2

4

6

8

10

12

14

229228227226225224223

µs p

er s

cann

ed r

ecor

d

n

BDB btreeTPIE btreestxxl::map

0

0.5

1

1.5

2

2.5

3

229228227226225224223

over

use

fact

or

n

BDB btreestxxl::map

0

5000

10000

15000

20000

25000

229228227226225224223

µs p

er d

elet

ion

n

BDB btreeTPIE btreestxxl::map

0

5

10

15

20

25

30

35

40

45

50

55

60

65

70

STXXL gs2 32 insert

STXXL n 32 insert

LEDA-SM 32 insert

TPIE mmap 32 insert

TPIE ufs 32 insert

MB

yte/s

0

5

10

15

20

25

30

35

40

45

50

55

STXXL gs2 32 delete

STXXL n 32 delete

LEDA-SM 32 delete

TPIE mmap 32 delete

TPIE ufs 32 delete

MB

yte/s

0

5

10

15

20

25

30

35

40

45

50

55

60

STXXL gs2 4 insert

STXXL n 4 insert

LEDA-SM 4 insert

TPIE mmap 4 insert

TPIE ufs 4 insert

MB

yte

/s

0

5

10

15

20

25

30

35

40

45

50

55

STXXL gs2 4 delete

STXXL n 4 delete

LEDA-SM 4 delete

TPIE mmap 4 delete

TPIE ufs 4 deleteMB

yte/s

0

25

50

75

100

125

150

175

200

225

250

275

D=1 gs2 4 insert

D=1 gs2 32 insert

D=2 gs2 4 insert

D=2 gs2 32 insert

D=4 gs2 4 insert

D=4 gs2 32 insert

MB

yte/s

0

10

20

30

40

50

60

70

80

90

100

110

120

130

140

150

160

170

D=1 gs2 4 delete

D=1 gs2 32 delete

D=2 gs2 4 delete

D=2 gs2 32 delete

D=4 gs2 4 delete

D=4 gs2 32 delete

MB

yte/s

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 25/39

Page 31: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Engineering Algorithms for Large Graphs

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 26/39

Page 32: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Engineering an I/O-efficient MST Algorithm

4

2

3

1

792

5

ChallengeCan we compute Minimum Spanning Trees (Forests) for really hugegraphs?

Dementiev, Sanders, Schultes, and SibeynEngineering an External Memory Minimum Spanning Tree Algorithm.TCS 2004: 3rd IFIP International Conference on Theoretical ComputerScience

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 27/39

Page 33: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

A Practical ApproachSketch of the algorithm

1 Reduce the node set V merging nodesand finding some MST edges until|V |= O(M)

2 Run Kruskal’s algorithm keeping forestsin internal memory (Union-Find)

u v...

relink

relink

outputsweep line

Two implementation variantsNode reduction using stxxl::priority_queue: very simple, only12 lines of C++/STXXL code, CPU-bound

Bucket version: based on stxxl::stacks, linear internal work

ResultsComputed MSTs for 100 GByte graphs in 8 hours on a PC

Only 2–5 times slower than a good internal algorithm

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 28/39

Page 34: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

A Practical ApproachSketch of the algorithm

1 Reduce the node set V merging nodesand finding some MST edges until|V |= O(M)

2 Run Kruskal’s algorithm keeping forestsin internal memory (Union-Find)

u v...

relink

relink

outputsweep line

Two implementation variantsNode reduction using stxxl::priority_queue: very simple, only12 lines of C++/STXXL code, CPU-bound

Bucket version: based on stxxl::stacks, linear internal work

ResultsComputed MSTs for 100 GByte graphs in 8 hours on a PC

Only 2–5 times slower than a good internal algorithm

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 28/39

Page 35: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

A Practical ApproachSketch of the algorithm

1 Reduce the node set V merging nodesand finding some MST edges until|V |= O(M)

2 Run Kruskal’s algorithm keeping forestsin internal memory (Union-Find)

u v...

relink

relink

outputsweep line

Two implementation variantsNode reduction using stxxl::priority_queue: very simple, only12 lines of C++/STXXL code, CPU-bound

Bucket version: based on stxxl::stacks, linear internal work

ResultsComputed MSTs for 100 GByte graphs in 8 hours on a PC

Only 2–5 times slower than a good internal algorithm

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 28/39

Page 36: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

I/O-Efficient Breadth First Search

Ajwani, Dementiev and MeyerA Computational Study of External-Memory BFS Algorithms.SODA 2006, ACM Symposium on Discrete Algorithms

0

1

1

2

3

3

4

4

4

5

i−1 i

Study two I/O-efficient BFS algorithms(MunagalaRanade and MehlhornMeyer)

Use STXXL pipelining

Results

BFS of a real huge WWW crawl graph (130 ·106 nodes, 1.4 ·109 edges)in about 2 hours on a PC

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 29/39

Page 37: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

I/O-Efficient Breadth First Search

Ajwani, Dementiev and MeyerA Computational Study of External-Memory BFS Algorithms.SODA 2006, ACM Symposium on Discrete Algorithms

0

1

1

2

3

3

4

4

4

5

i−1 i

Study two I/O-efficient BFS algorithms(MunagalaRanade and MehlhornMeyer)

Use STXXL pipelining

Results

BFS of a real huge WWW crawl graph (130 ·106 nodes, 1.4 ·109 edges)in about 2 hours on a PC

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 29/39

Page 38: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

I/O-Efficient Breadth First Search

Ajwani, Dementiev and MeyerA Computational Study of External-Memory BFS Algorithms.SODA 2006, ACM Symposium on Discrete Algorithms

0

1

1

2

3

3

4

4

4

5

i−1 i

Study two I/O-efficient BFS algorithms(MunagalaRanade and MehlhornMeyer)

Use STXXL pipelining

Results

BFS of a real huge WWW crawl graph (130 ·106 nodes, 1.4 ·109 edges)in about 2 hours on a PC

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 29/39

Page 39: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Engineering Algorithms for Large Graphs

In the thesisMaximal Independent Set

Connected Components and Spanning Trees

Listing All Triangles

(Heuristics for) Graph Coloring

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 30/39

Page 40: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Engineering LargeSuffix Array Construction

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 31/39

Page 41: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Engineering Large Suffix Array Construction

Suffix Array: SA[i] is the starting pos of the i-th smallest suffix of input S

Example:S = [b,a,n,a,n,a]SA = [5,3,1,0,4,2]

Applications: full-text index, compression

aanaananabananananana

banana

Our WorkDesign, implement, evaluate several new I/O-efficient algorithms

Apply pipelining to external memory suffix array construction

Dementiev, Kärkkäinen, Mehnert, SandersBetter External Memory Suffix Array Construction.JEA and ALENEX05: Algorithm Engineering and Experiments

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 32/39

Page 42: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Engineering Large Suffix Array Construction

Suffix Array: SA[i] is the starting pos of the i-th smallest suffix of input S

Example:S = [b,a,n,a,n,a]SA = [5,3,1,0,4,2]

Applications: full-text index, compression

aanaananabananananana

banana

Our WorkDesign, implement, evaluate several new I/O-efficient algorithms

Apply pipelining to external memory suffix array construction

Dementiev, Kärkkäinen, Mehnert, SandersBetter External Memory Suffix Array Construction.JEA and ALENEX05: Algorithm Engineering and Experiments

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 32/39

Page 43: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Engineering Large Suffix Array Construction 2

Considered algorithmsDoubling, a-Tupling (quadrupling), doubling+discarding,quadrupling+discarding, difference cover (DC3 aka Skew, I/O-optimal)

Input instances: random and real worldConcatenation of a random string (make heuristics look bad)

Gutenberg text collection (≈ 3 GBytes)

Human genome (small alphabet, ≈ 3 GBytes)

HTML (text + tags, ≈ 4 GBytes)

(C++) source code (≈ 500 MBytes)

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 33/39

Page 44: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Engineering Large Suffix Array Construction 3

ResultsPipelining saves a factor of 3 in I/O volume⇒ a speedup of 1.9-2.4 for D = 1

Optimal DC3 outperforms all opponents on all inputsSuffix array of a 4 GByte input can be computed in a few hours on a PCwith a small main memory⇒ Very price-efficient

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 34/39

Page 45: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Porting Algorithms to External Memory

Replace few underlying non-I/O-efficient algorithms by correspondingI/O-efficient versions

We have applied this technique obtaining algorithms for

Bipartiteness test (aka 2-coloring): O(sort(|E |+ |V |)) I/Os

5-Coloring Planar Graphs: O(sort(|E |+ |V |)) I/Os

Finding 1/2-Approximation of Maximum Weighted Matching:O(sort(|E |+ |V |)) I/Os

Finding Perfect Matchings in Bipartite Multigraphs:O(sort(|E |+ |V |) log2(|E |)) I/Os

⇒ Can be easily implemented with STXXL

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 35/39

Page 46: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Summary

Engineering from the bottom to the top:many disks CPU-bound look atinternal algorithms,RAID-0 suboptimal

Pipelining to save I/Os, overlap I/Oand computation, easy to use library,abstraction, rapid prototyping

Controlled unbuffered asynchronousI/O, scalable file systems

Bottleneck-free hardwareI/O-subsystem with parallel disks

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 36/39

Page 47: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Summary

Engineering from the bottom to the top:many disks CPU-bound look atinternal algorithms,RAID-0 suboptimal

Pipelining to save I/Os, overlap I/Oand computation, easy to use library,abstraction, rapid prototyping

Controlled unbuffered asynchronousI/O, scalable file systems

Bottleneck-free hardwareI/O-subsystem with parallel disks

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 36/39

Page 48: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Summary

Engineering from the bottom to the top:many disks CPU-bound look atinternal algorithms,RAID-0 suboptimal

Pipelining to save I/Os, overlap I/Oand computation, easy to use library,abstraction, rapid prototyping

Controlled unbuffered asynchronousI/O, scalable file systems

Bottleneck-free hardwareI/O-subsystem with parallel disks

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 36/39

Page 49: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Summary

Engineering from the bottom to the top:many disks CPU-bound look atinternal algorithms,RAID-0 suboptimal

Pipelining to save I/Os, overlap I/Oand computation, easy to use library,abstraction, rapid prototyping

Controlled unbuffered asynchronousI/O, scalable file systems

Bottleneck-free hardwareI/O-subsystem with parallel disks

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 36/39

Page 50: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Conclusion

The STXXL library

high-performance (parallel disks, pipelining, overlapping of I/O andcomputation)

easy to use (STL-compatible)

STXXL applications: solve very large problem instances externally using a lowcost hardware in record time

⇒ Price-efficient

OutlookPossible efficiency improvements:I pipelining+overlappingI parallel processing (Multi-Core STL)I pipelining+task-based parallelism

Submit to the BOOST libraries

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 37/39

Page 51: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Conclusion

The STXXL library

high-performance (parallel disks, pipelining, overlapping of I/O andcomputation)

easy to use (STL-compatible)

STXXL applications: solve very large problem instances externally using a lowcost hardware in record time

⇒ Price-efficient

OutlookPossible efficiency improvements:I pipelining+overlappingI parallel processing (Multi-Core STL)I pipelining+task-based parallelism

Submit to the BOOST libraries

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 37/39

Page 52: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Active STXXL Users We Know About

1 University of Karlsruhe, Germany (text processing, graph algorithms, practical courses)

2 Max-Planck-Institut für Informatik, Germany (graph algorithms)

3 University of Rome “La Sapienza”, Italy (connected components)

4 University of Texas at Austin, USA (Gaussian elimination)

5 Bitplane AG, Switzerland (visualization and analysis of 3D and 4D microscopic images)

6 Philips Research, The Netherlands (differential cryptographic analysis)

7 Dalhousie University, Canada (N-gram extraction)

8 Florida State University, USA (construction of Voronoi diagrams)

9 Montefiore Institute, Belgium (big sparse matrices)

10 University of British Columbia, Canada (topology analysis of large networks)

11 Bayes Forecast, Spain (statistics and time series analysis)

12 Indian Institute of Science in Bangalore, India (suffix array construction)

13 Rensselaer Polytechnic University, USA (suffix array construction)

14 Institut français du pèrole, France (analysis of seismic files)

15 Northumbria University, UK (search trees)

16 University of Trento, Italy (text compression)

17 Norwegian University of Science and Technology in Trondheim, Norway (suffix array construction)

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 38/39

Page 53: Algorithm Engineering for Large Data Setsalgo2.iti.kit.edu/dementiev/files/defense_slides.pdf · Outline 1 Introduction 2 Experimental Parallel Disk System 3 The STXXL Library 4 Engineering

Final Slide

Thank you for your attention!

Roman Dementiev (Uni Karlsruhe & MPI-INF) Algorithm Engineering for Large Data Sets 1 Dec 2006 39/39