chapter 10 parallel algorithmsac.informatik.uni-freiburg.de/.../pdf/10_parallel_p3_ann.pdfparallel...
TRANSCRIPT
Chapter 10
Parallel Algorithms
Algorithm TheoryWS 2017/18
Fabian Kuhn
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)
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
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
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
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:
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โฆ
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.
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
Algorithm Theory, WS 2017/18 Fabian Kuhn 10
Reducing the number of colors
Assume that we start with a coloring with colors 0,โฆ , ๐ฅ โ 1
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
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)
Algorithm Theory, WS 2017/18 Fabian Kuhn 13
Distributed Coloring
Algorithm Theory, WS 2017/18 Fabian Kuhn 14
Distributed Coloring