Parallel Prefix Computation Advanced Algorithms & Data Structures Lecture Theme 14 Prof. Dr. Th. Ottmann Summer Semester 2006.

Slides:



Advertisements
Similar presentations
Parallel List Ranking Advanced Algorithms & Data Structures Lecture Theme 17 Prof. Dr. Th. Ottmann Summer Semester 2006.
Advertisements

Trees Chapter 11.
Advanced Topics in Algorithms and Data Structures
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Lecture 3: Parallel Algorithm Design
SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.
Binary Trees Chapter 6. Linked Lists Suck By now you realize that the title to this slide is true… By now you realize that the title to this slide is.
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,
CS 171: Introduction to Computer Science II
Advanced Topics in Algorithms and Data Structures 1 Rooting a tree For doing any tree computation, we need to know the parent p ( v ) for each node v.
Lecture 5: Linear Time Sorting Shang-Hua Teng. Sorting Input: Array A[1...n], of elements in arbitrary order; array size n Output: Array A[1...n] of the.
CS 253: Algorithms Chapter 8 Sorting in Linear Time Credit: Dr. George Bebis.
More sorting algorithms: Heap sort & Radix sort. Heap Data Structure and Heap Sort (Chapter 7.6)
Advanced Topics in Algorithms and Data Structures 1 Lecture 4 : Accelerated Cascading and Parallel List Ranking We will first discuss a technique called.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
CSE621/JKim Lec4.1 9/20/99 CSE621 Parallel Algorithms Lecture 4 Matrix Operation September 20, 1999.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
Accelerated Cascading Advanced Algorithms & Data Structures Lecture Theme 16 Prof. Dr. Th. Ottmann Summer Semester 2006.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 9 Tuesday, 11/20/01 Parallel Algorithms Chapters 28,
Tree Traversal. Traversal Algorithms preorder inorder postorder.
Parallel Merging Advanced Algorithms & Data Structures Lecture Theme 15 Prof. Dr. Th. Ottmann Summer Semester 2006.
CPSC 411, Fall 2008: Set 2 1 CPSC 311 Analysis of Algorithms Sorting Lower Bound Prof. Jennifer Welch Fall 2009.
Lecture 5: Master Theorem and Linear Time Sorting
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
Lecture 6: Point Location Computational Geometry Prof. Dr. Th. Ottmann 1 Point Location 1.Trapezoidal decomposition. 2.A search structure. 3.Randomized,
Advanced Topics in Algorithms and Data Structures Page 1 An overview of lecture 3 A simple parallel algorithm for computing parallel prefix. A parallel.
Sorting Lower Bound Andreas Klappenecker based on slides by Prof. Welch 1.
Chapter 10 Search Structures Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures.
Advanced Topics in Algorithms and Data Structures 1 Two parallel list ranking algorithms An O (log n ) time and O ( n log n ) work list ranking algorithm.
CSC 2300 Data Structures & Algorithms February 6, 2007 Chapter 4. Trees.
Advanced Topics in Algorithms and Data Structures 1 An example.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The trees.
Fundamental Structures of Computer Science March 02, 2006 Ananda Guna Binomial Heaps.
Sorting Algorithms (Part II) Slightly modified definition of the sorting problem: input: A collection of n data items where data item a i has a key, k.
CS 3610 Midterm Review.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Trees CSC 172 SPRING 2002 LECTURE 14. Lists We have seen lists: public class Node { Object data; Node next; } 
Tree A connected graph that contains no simple circuits is called a tree. Because a tree cannot have a simple circuit, a tree cannot contain multiple.
Binary Trees 2 Overview Trees. Terminology. Traversal of Binary Trees. Expression Trees. Binary Search Trees.
Lecture 8 Tree.
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
 Rooted tree and binary tree  Theorem 5.19: A full binary tree with t leaves contains i=t-1 internal vertices.
5.5.3 Rooted tree and binary tree  Definition 25: A directed graph is a directed tree if the graph is a tree in the underlying undirected graph.  Definition.
TREES. What is a tree ? An Abstract Data Type which emulates a tree structure with a set of linked nodes The nodes within a tree are organized in a hierarchical.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 9.
Data Structures TREES.
IS 2610: Data Structures Recursion, Divide and conquer Dynamic programming, Feb 2, 2004.
Trees By P.Naga Srinivasu M.tech,(MBA). Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines.
Discrete Mathematics Chapter 5 Trees.
Lecture 15 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
CMSC 341 Introduction to Trees. 2/21/20062 Tree ADT Tree definition –A tree is a set of nodes which may be empty –If not empty, then there is a distinguished.
More Trees Discrete Structures (CS 173)
Data Structures Azhar Maqsood School of Electrical Engineering and Computer Sciences (SEECS-NUST) Binary Trees.
Lecture 7: Searching a Tree Neil Ghani University of Strathclyde.
Hello Everyone!!! 1. Tree And Graphs 2 Features of Trees  Tree Nodes Each node have 0 or more children A node have must one parent  Binary tree Tree.
Data Structures and Algorithms
Recursive Objects (Part 4)
12. Graphs and Trees 2 Summary
Tree.
Section 8.1 Trees.
Advanced Algorithms Analysis and Design
Abstract Data Structures
Week nine-ten: Trees Trees.
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Chapter 20: Binary Trees.
Presentation transcript:

Parallel Prefix Computation Advanced Algorithms & Data Structures Lecture Theme 14 Prof. Dr. Th. Ottmann Summer Semester 2006

2 Overview A simple parallel algorithm for computing parallel prefix. A parallel merging algorithm

3 We are given an ordered set A of n elements and a binary associative operator . We have to compute the ordered set Definition of prefix computation

4 For example, if  is + and the input is the ordered set {5, 3, -6, 2, 7, 10, -2, 8} then the output is {5, 8, 2, 4, 11, 21, 19, 27} Prefix sum can be computed in O ( n ) time sequentially. An example of prefix computation

5 First Pass For every internal node of the tree, compute the sum of all the leaves in its subtree in a bottom-up fashion. sum [ v ] := sum [ L [ v ]] + sum [ R [ v ]] Using a binary tree

6 for d = 0 to log n – 1 do for i = 0 to n – 1 by 2 d+1 do in parallel a [ i + 2 d ] := a [ i + 2 d - 1] + a [ i + 2 d+1 - 1] In our example, n = 8, hence the outer loop iterates 3 times, d = 0, 1, 2. Parallel prefix computation

7 d = 0: In this case, the increments of 2 d+1 will be in terms of 2 elements. for i = 0, a [ ] := a [ ] + a [ ] or, a [1] := a [0] + a [1] When d= 0

8 First Pass For every internal node of the tree, compute the sum of all the leaves in its subtree in a bottom-up fashion. sum [ v ] := sum [ L [ v ]] + sum [ R [ v ]] Using a binary tree

9 d = 1: In this case, the increments of 2 d+1 will be in terms of 4 elements. for i = 0, a [ ] := a [ ] + a [ ] or, a [3] := a [1] + a [3] for i = 4, a [ ] := a [ ] + a [ ] or, a [7] := a [5] + a [7] When d = 1

10 blue: no change from last iteration. magenta: changed in the current iteration. The First Pass

11 Second Pass The idea in the second pass is to do a topdown computation to generate all the prefix sums. We use the notation pre [ v ] to denote the prefix sum at every node. The Second Pass

12 pre [ root ] := 0, the identity element for the  operation, since we are considering the  operation. If the operation is max, the identity element will be - . Computation in the second phase

13 pre [ L[v] ] := pre [ v ] pre [ R[v] ] := sum [ L[v] ] + pre [ v ] Second phase (continued)

14 Example of second phase pre[L[v]] := pre[v] pre[R[v]] := sum[L[v]] + pre[v]

15 for d = (log n – 1) downto 0 do for i = 0 to n – 1 by 2 d+1 do in parallel temp := a [ i + 2 d - 1] a [ i + 2 d - 1] := a [ i + 2 d+1 - 1] (left child) a [ i + 2 d ] := temp + a [ i + 2 d+1 - 1] (right child) a[7] is set to 0 Parallel prefix computation

16 We consider the case d = 2 and i = 0 temp := a [ ] := a [ 3 ] a [ ] := a [ ] or, a [ 3 ] := a [ 7 ] a [ ] := temp + a [ ] or, a [ 7 ] := a [ 3 ] + a [ 7 ] Parallel prefix computation

17 blue: no change from last iteration. magenta: left child. brown: right child. Parallel prefix computation

18 All the prefix sums except the last one are now in the leaves of the tree from left to right. The prefix sums have to be shifted one position to the left. Also, the last prefix sum (the sum of all the elements) should be inserted at the last leaf. The complexity is O (log n ) time and O ( n ) processors. Exercise: Reduce the processor complexity to O ( n / log n ). Parallel prefix computation

19 Vertex x precedes vertex y if x appears before y in the preorder (depth first) traversal of the tree. Lemma: After the second pass, each vertex of the tree contains the sum of all the leaf values that precede it. Proof: The proof is inductive starting from the root. Proof of correctness

20 Inductive hypothesis: If a parent has the correct sum, both children must have the correct sum. Base case: This is true for the root since the root does not have any node preceding it. Proof of correctness

21 Left child: The left child L [ v ] of vertex v has exactly the same leaves preceding it as the vertex itself. Proof of correctness

22 These are the leaves in the region A for vertex L [ v ]. Hence for L [ v ], we can copy pre ( v ) as the parent’s prefix sum is correct from the inductive hypothesis. Proof of correctness

23 Right child: The right child of v has two sets of leaves preceding it. The leaves preceding the parent (region A ) for R [ v ] The leaves preceding L [ v ] (region B ). pre ( v ) is correct from the inductive hypothesis. Hence, pre ( R [ v ]) := pre ( v ) + sum ( L [ v ]). Proof of correctness