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

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

of 14

  • date post

    19-Jul-2020
  • Category

    Documents

  • view

    0
  • download

    0

Embed Size (px)

Transcript of Chapter 10 Parallel Parallel Algorithms Algorithm Theory WS 2017/18 Fabian Kuhn Algorithm Theory, WS

  • Chapter 10

    Parallel Algorithms

    Algorithm Theory WS 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