streets4mpi (parallel programming project) · 2018-04-17 · streets4mpi (parallel programming...

34
Streets4MPI (Parallel Programming Project) Julian Fietkau Joachim Nitschke University of Hamburg April 4th, 2012

Upload: others

Post on 06-Aug-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Streets4MPI(Parallel Programming Project)

Julian FietkauJoachim Nitschke

University of Hamburg

April 4th, 2012

Page 2: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Agenda Julian Fietkau, Joachim Nitschke

Agenda

Introduction

SimulationConceptTraffic loadTraffic jam tolerance

Implementation

Parallelization

Results

Summary

2 / 34

Page 3: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Introduction Julian Fietkau, Joachim Nitschke

Project task, revisited

Decide on a problem that may be solved using parallel processing, andimplement a solution. → Street traffic simulation

Main CaveatRealistic traffic predictions can only be made using an exceedinglydetailed model. This makes things prohibitively complicated.

3 / 34

Page 4: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Introduction Julian Fietkau, Joachim Nitschke

Streets4MPI is here

� We can simulate thousands of cars on the streets of Hamburg:� We use OpenStreetMap data for navigation.� We incorporate shortest-path algorithms.� We model road congestion and its effect on the actual driving speed.� We optimize the road system based on which roads are heavily used

and which one are empty.� We can visualize all of this as dynamic heatmaps.

� Also, we can do most of this in parallel using MPI.

4 / 34

Page 5: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Simulation: Concept Julian Fietkau, Joachim Nitschke

Revision: Discrete macroscopic simulation

� Simulation runs in steps: Traffic load in one step influences thedriver’s behavior in the next step

� Abstract from single cars, traffic lights etc. to daily traffic� Display traffic development over longer time periods and influenceson street network

5 / 34

Page 6: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Simulation: Concept Julian Fietkau, Joachim Nitschke

Street network

6 / 34

Page 7: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Simulation: Concept Julian Fietkau, Joachim Nitschke

Trips

� Representation for a resident’s daily traffic� Shortest path between two nodes

7 / 34

Page 8: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Simulation: Concept Julian Fietkau, Joachim Nitschke

Trips

8 / 34

Page 9: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Simulation: Traffic load Julian Fietkau, Joachim Nitschke

Traffic load: Effect on driving speed

� Heavy traffic slows cars down� How can we calculate the deceleration?� Assumption: Cars keep safe braking distances

⇒ By looking at the braking distance, we calculate the actual speed

Braking distance and actual speedlbraking = lstreet

ntrips− lcar

vactual =√lbraking · abraking · 2

9 / 34

Page 10: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Simulation: Traffic load Julian Fietkau, Joachim Nitschke

Oscillation

� Problem: Drivers show oscillating behavior

10 / 34

Page 11: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Simulation: Traffic jam tolerance Julian Fietkau, Joachim Nitschke

Idea

� Solution: Each driver gets an individual traffic jam tolerance

Traffic jam tolerancevperceived = vactual + (videal − vactual) · ftolerance

� Compromise: We assign a (random) traffic jam tolerance to eachprocess and all its residents� This is because one copy of the street network graph can accomodate

one traffic jam tolerance factor, and each MPI process has its owncopy anyway

11 / 34

Page 12: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Simulation: Traffic jam tolerance Julian Fietkau, Joachim Nitschke

Result

12 / 34

Page 13: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Simulation: Traffic jam tolerance Julian Fietkau, Joachim Nitschke

Improvement: Reworking redundant nodes

� Problem: Redundant nodes are used to model curved streets� Solution: Merge edges

13 / 34

Page 14: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Implementation Julian Fietkau, Joachim Nitschke

Python

� Streets4MPI is written in Python (2.6 compatible)� External modules: imposm.parser, pygraph, mpi4py, PIL

14 / 34

Page 15: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Implementation Julian Fietkau, Joachim Nitschke

OSM parser

� Import data from OpenStreetMap� XML-based semi-structured data format: OSM� May provide additional information: street types/sizes, speedlimits, residential/industrial/commercial zones

15 / 34

Page 16: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Implementation Julian Fietkau, Joachim Nitschke

<?xml version="1.0" encoding="UTF-8"?><osm version="0.6" generator="CGImap 0.0.2"><bounds minlat="54.0889580" minlon="12.2487570" maxlat="54.0913900"

maxlon="12.2524800"/><node id="298884269" lat="54.0901746" lon="12.2482632" user="SvenHRO"

uid="46882" visible="true" version="1" changeset="676636"timestamp="2008-09-21T21:37:45Z"/>

<node id="261728686" lat="54.0906309" lon="12.2441924" user="PikoWinter"uid="36744" visible="true" version="1" changeset="323878"timestamp="2008-05-03T13:39:23Z"/>

...<node id="298884272" lat="54.0901447" lon="12.2516513" user="SvenHRO"

uid="46882" visible="true" version="1" changeset="676636"timestamp="2008-09-21T21:37:45Z"/>

<way id="26659127" user="Masch" uid="55988" visible="true"version="5" changeset="4142606" timestamp="2010-03-16T11:47:08Z"><nd ref="292403538"/><nd ref="298884289"/>...<nd ref="261728686"/><tag k="highway" v="unclassified"/><tag k="name" v="Pastower Straße"/>

</way>...

</osm>

16 / 34

Page 17: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Implementation Julian Fietkau, Joachim Nitschke

Visualization

� Simulation and visualization run independantly� Visualization uses the Python Imaging Library to render the mapand traffic load data to image files

� Supports many different data modes and two color modes(heatmap and grayscale)

17 / 34

Page 18: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM
Page 19: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Parallelization Julian Fietkau, Joachim Nitschke

mpi4py

� Object oriented interface on top of the MPI specifications� Provides all usual MPI routines

communicator = MPI.COMM_WORLDobject = Noneif communicator.Get_rank() == 0:

object = Object()object = communicator.bcast(object, root=0)

� Single program multiple data (mostly)� MPI code contained within our main class

19 / 34

Page 20: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Parallelization Julian Fietkau, Joachim Nitschke

Algorithm

� Each MPI process. . .� . . . generates its own copy of the street network� . . . generates trips for its (equally divided) subset of all residents� . . . gets its own traffic jam resistance� . . . calculates the shortest paths for its residents and the resulting

traffic load� After every simulation step, each process gets sent the traffic loadsfrom all other processes (via mpi.allgather)

� Complete results are saved to disk by process #0

20 / 34

Page 21: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Parallelization Julian Fietkau, Joachim Nitschke

Algorithm: visualization

... MPI

OSM

results

results

results

results

python #0 python #1 python #n

time

iteration 0

iteration 1

iteration 2

iteration 3

iteration 0

iteration 1

iteration 2

iteration 3

iteration 0

iteration 1

iteration 2

iteration 3

exchange traffic data

exchange traffic data

exchange traffic data

21 / 34

Page 22: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Parallelization Julian Fietkau, Joachim Nitschke

Performance (I)

0

500

1000

1500

2000

2500

3000

1 4 8 12 16 0

25

50

75

100

tota

l ti

me [

s]

effi

ciency

[%

]

# of processes

Run times of Streets4MPI (Stellingen dataset, 1000 residents, 50 simulation steps)

total timeefficiency

22 / 34

Page 23: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Parallelization Julian Fietkau, Joachim Nitschke

Performance (II)

0

200

400

600

800

1000

1200

1 4 8 12 16 0

25

50

75

100

tota

l ti

me [

s]

effi

ciency

[%

]

# of processes

Run times of Streets4MPI (Stellingen dataset, 100 residents, 200 simulation steps)

total timeefficiency

23 / 34

Page 24: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Parallelization Julian Fietkau, Joachim Nitschke

Weaknesses

� Some activities (e.g. initial I/O, road construction simulation) arenot easily parallelized using our current model

� Disk activity by process #0 makes it drag behind and leave otherswaiting for synchronization

� Shortest path calculation is not optimal for the distributed case

24 / 34

Page 25: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Parallelization Julian Fietkau, Joachim Nitschke

Improvement: Shortest path revisited

� Highest calculation costs are due to the shortest path calculations� Current implementation: Dijkstra’s algorithm

� Complexity: O(n2nodes)� Executed ∼ nresidents

nprocessestimes

� Static shortest path vs. dynamic shortest path

25 / 34

Page 26: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Parallelization Julian Fietkau, Joachim Nitschke

Dynamic shortest path

� Idea: Calculate shortest paths once and update them only whenthe edge weights change

� Performance gain through local influence of changes

26 / 34

Page 27: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Parallelization Julian Fietkau, Joachim Nitschke

Dynamic shortest path: Increasing a weight

+𝚫w

27 / 34

Page 28: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Parallelization Julian Fietkau, Joachim Nitschke

Dynamic shortest path: Decreasing a weight

-𝚫w

28 / 34

Page 29: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Results Julian Fietkau, Joachim Nitschke

Simulation speed-up results

� Results are mostly satisfactory, but could very likely be improved� There are constant time elements not yet parallelized� It bears mentioning that using the current model (traffic jamresistance per process) increases simulation quality with number ofprocesses, so real efficiency is slightly better than measured

29 / 34

Page 30: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Results Julian Fietkau, Joachim Nitschke

Project Goals

� Simulation working and producing nontrivial results� Parallel processing in Python working� Visualization working� Further work needed: better parallelization(?), documentation

30 / 34

Page 31: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Summary Julian Fietkau, Joachim Nitschke

Most Important Points

� Simple traffic simulation� Macro level with congestion analysis, street development,visualization

� MPI on Python

31 / 34

Page 32: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Miscellaneous: Literature Julian Fietkau, Joachim Nitschke

Literature

Weber, B.; MÃŒller, P.; Wonka, P.; Gross, M.:Interactive Geometric Simulation of 4D CitiesIn: EUROGRAPHICS 28 (2009), Nr. 2

Chandy, K.M.; Misra, J.:Distributed computation on graphs: Shortest path algorithmsIn: Commun. ACM, vol. 25, no. 11, pp. 833 – 837, Nov. 1982

Antonio, J. K.; Huang, G. M.; Tsai, W. K.:A fast distributed shortest path algorithm for a class of hierar-chically clustered data networksIn: IEEE Trans. Comput., vol. 41, pp. 710 – 724, June 1992

32 / 34

Page 33: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Miscellaneous: Weblinks Julian Fietkau, Joachim Nitschke

Weblinks

Project websitehttp://jfietkau.github.com/Streets4MPI/ (some time soon)

GitHub repositoryhttp://github.com/jfietkau/Streets4MPI (available right now!)

Project wikihttp://pwiki.julian-fietkau.de/ (might go offline soon-ish)

33 / 34

Page 34: Streets4MPI (Parallel Programming Project) · 2018-04-17 · Streets4MPI (Parallel Programming Project) Author: Julian Fietkau Joachim Nitschke Created Date: 4/4/2012 1:16:01 PM

Miscellaneous: Download and Usage Julian Fietkau, Joachim Nitschke

Download and Usage

These slides are published under the CC-BY-SA 3.0 license.All pictures and illustrations not created by Streets4MPIare based on content from the OpenClipArt Project.

Download these slides and give feedback:

http://www.julian-fietkau.de/streets4mpi_final

34 / 34