chapter 10 parallel algorithmsac.informatik.uni-freiburg.de/.../pdf/10_parallel_p3_ann.pdfparallel...

14
Chapter 10 Parallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn

Upload: others

Post on 19-Jul-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Chapter 10

Parallel Algorithms

Algorithm TheoryWS 2017/18

Fabian Kuhn

Page 2: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 2

Computing Prefix Sums

Theorem: Given a sequence ๐‘Ž1, โ€ฆ , ๐‘Ž๐‘› of ๐‘› values, all prefix sums ๐‘ ๐‘– = ๐‘Ž1โจโ‹ฏโจ๐‘Ž๐‘– (for 1 โ‰ค ๐‘– โ‰ค ๐‘›) can be computed in time ๐‘‚(log ๐‘›)using ๐‘‚ ฮค๐‘› log ๐‘› processors on an EREW PRAM.

Proof:

โ€ข Computing the sums of all sub-trees can be done in parallel in time ๐‘‚ log ๐‘› using ๐‘‚ ๐‘› total operations.

โ€ข The same is true for the top-down step to compute the ๐‘Ÿ(๐‘ฃ)

โ€ข The theorem then follows from Brentโ€™s theorem:

๐‘‡1 = ๐‘‚ ๐‘› , ๐‘‡โˆž = ๐‘‚ log ๐‘› โŸน ๐‘‡๐‘ < ๐‘‡โˆž +๐‘‡1๐‘

Remark: This can be adapted to other parallel models and to different ways of storing the value (e.g., array or list)

Page 3: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 3

Prefix Sums in Linked Lists

Given: Linked list ๐ฟ of length ๐‘› in the following way

โ€ข Elements are in an array ๐ด of length ๐‘› in an unordered way

โ€ข Each array element ๐ด ๐‘– also contains a next pointer

โ€ข Pointer ๐‘“๐‘–๐‘Ÿ๐‘ ๐‘ก to the first element of the list

Goal: Compute all prefix sums w.r.t. to the order given by the list

Page 4: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 4

2-Ruling Set of a Linked List

Given a linked list, select a subset of the entries such that

โ€ข No two neighboring entries are selected

โ€ข For every entry that is not selected, either the predecessor or the successor is selectedโ€“ i.e., between two consecutive selected entries there are at least one

and at most two unselected entries

โ€ข We will see that a 2-ruling set of a linked list can be computed efficiently in parallel

Page 5: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 5

Using 2-Ruling Sets to Get Prefix Sums

Observations:

โ€ข To compute the prefix sums of an array/list of numbers, we need a binary tree such that the numbers are at the leaves and an in-order traversal of the tree gives the right order

โ€ข The algorithm can be generalized to non-binary trees

Page 6: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 6

Using 2-Ruling Sets to Get Prefix Sums

Lemma: If a 2-Ruling Set of a list of length ๐‘ can be computed in parallel with ๐‘ค ๐‘ work and ๐‘‘ ๐‘ depth, all prefix sums of a list of length ๐‘› can be computed in parallel with

โ€ข Work ๐‘‚ ๐‘ค ๐‘› + ๐‘ค ฮค๐‘› 2 + ๐‘ค ฮค๐‘› 4 +โ‹ฏ+ ๐‘ค 1

โ€ข Depth ๐‘‚ ๐‘‘ ๐‘› + ๐‘‘ ฮค๐‘› 2 + ๐‘‘ ฮค๐‘› 4 +โ‹ฏ+ ๐‘‘ 1

Proof Sketch:

Page 7: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 7

Prefix Sums in Linked Lists

Log-Star Function:

โ€ข For ๐‘– โ‰ฅ 1: log2(๐‘–)๐‘ฅ = log2 log2

๐‘–โˆ’1๐‘ฅ , and log2

0๐‘ฅ = ๐‘ฅ

โ€ข For ๐‘ฅ > 2: logโˆ— ๐‘ฅ โ‰” min ๐‘– โˆถ log(๐‘–) ๐‘ฅ โ‰ค 2 , for ๐‘ฅ โ‰ค 2: logโˆ— ๐‘ฅ โ‰” 1

Lemma: A 2-ruling set of a linked list of length ๐‘› can be computed in parallel with work ๐‘‚ ๐‘› โ‹… logโˆ— ๐‘› and span ๐‘‚ logโˆ— ๐‘› .

โ€ข i.e., in time ๐‘‚ logโˆ— ๐‘› using ๐‘‚(๐‘›) processorsโ€“ We will first see how to apply this and prove it afterwardsโ€ฆ

Page 8: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 8

Prefix Sums in Linked Lists

Lemma: A 2-ruling set of a linked list of length ๐‘› can be computed in parallel with work ๐‘‚ ๐‘› โ‹… logโˆ— ๐‘› and span ๐‘‚ logโˆ— ๐‘› .

Theorem: All prefix sums of a linked list of length ๐‘› can be computed in parallel with total work ๐‘‚ ๐‘› โ‹… logโˆ— ๐‘› and span ๐‘‚ log ๐‘› โ‹… logโˆ— ๐‘› .

โ€ข i.e., in time ๐‘‚ log ๐‘› โ‹… logโˆ— ๐‘› using ๐‘‚ ฮค๐‘› log ๐‘› processors.

Page 9: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 9

Computing 2-Ruling Sets

โ€ข Instead of computing a 2-ruling set, we first compute a coloring of the list:โ€“ each list element gets a color s.t. adjacent elements get different colors

โ€ข Each element initially has a unique log ๐‘›-bit label in 1,โ€ฆ ,๐‘โ€“ can be interpreted as an initial coloring with ๐‘ colors

Algorithm runs in phases:

โ€ข Each phase: compute new coloring with smaller number of colors

We will show that

โ€ข #phases to get to ๐‘‚ 1 colors is ๐‘‚ logโˆ— ๐‘›

โ€ข each phase has ๐‘‚(๐‘›) work and ๐‘‚ 1 depth

Page 10: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 10

Reducing the number of colors

Assume that we start with a coloring with colors 0,โ€ฆ , ๐‘ฅ โˆ’ 1

Page 11: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 11

From a Coloring to a 2-Ruling Set

Assume that we are given a coloring with colors 0,โ€ฆ , 5

Page 12: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 12

Prefix Sums in Linked Lists

Lemma: A 2-ruling set of a linked list of length ๐‘› can be computed in parallel with work ๐‘‚ ๐‘› โ‹… logโˆ— ๐‘› and span ๐‘‚ logโˆ— ๐‘› .

Theorem: All prefix sums of a linked list of length ๐‘› can be computed in parallel with total work ๐‘‚ ๐‘› โ‹… logโˆ— ๐‘› and span ๐‘‚ log ๐‘› โ‹… logโˆ— ๐‘› .

โ€ข i.e., in time ๐‘‚ log ๐‘› โ‹… logโˆ— ๐‘› using ๐‘‚ ฮค๐‘› log ๐‘› processors.

List Ranking Problem: Compute the rank of each element of a linked list (rank: position in the list)

Page 13: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 13

Distributed Coloring

Page 14: Chapter 10 Parallel Algorithmsac.informatik.uni-freiburg.de/.../pdf/10_Parallel_p3_ann.pdfParallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS 2017/18 Fabian

Algorithm Theory, WS 2017/18 Fabian Kuhn 14

Distributed Coloring