1 / 69

Caching Parallel Computational Models Other Topics in Algorithms Wednesday, August 13 th

Caching Parallel Computational Models Other Topics in Algorithms Wednesday, August 13 th. Announcements. PS#6 due tonight at midnight Winners of the Competition: Shir Aharon Rasoul Kabirzadeh Alice Yeh & Marie Feng Extra Office Hours on Thursday & Friday

Download Presentation

Caching Parallel Computational Models Other Topics in Algorithms Wednesday, August 13 th

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Caching Parallel Computational Models Other Topics in Algorithms Wednesday, August 13th

  2. Announcements • PS#6 due tonight at midnight • Winners of the Competition: • ShirAharon • RasoulKabirzadeh • Alice Yeh & Marie Feng • Extra Office Hours on Thursday & Friday • Semih: Th 10am-12pm (Gates 424) • Billy: Friday 1pm-5pm (Gates B24) • Mike: Th 3pm-5pm (Gates B24) • Yiming: Fr: 5pm-7pm (Gates B24)

  3. Outline For Today • Caching • Other Algorithms & Algorithmic Techniques Beyond CS 161 • Parallel Algorithms (Finding Min, Bellman-Ford) • Linear Programming • Other Topics & Classes

  4. Alan Turing: Father of Computer Science

  5. Computer Science Studies the powers of machines. Fundamental Question CS asks: What is “computable” by machines? Turing, along with Church and Godel, was the person who made computation something we can mathematically study.

  6. Turing’s Answer To What Computation Is (1936) “On Computable Numbers, with an Application to the Entscheidungsproblem”: “We may compare a man in the process of computing a real number to a machine which is only capable of a finite number of conditions”

  7. Turing’s Answer To What Computation Is Computing is normally done by writing certain symbols on paper.We may suppose this paper is divided into squares like a child's arithmetic book. The behavior of the computer at any moment is determined by the symbols which he is observing, and his " state of mind " at that moment. We may suppose that there is a bound B to the number of symbols or squares which the computer can observe at one moment. If he wishes to observe more, he must use successive observations. We will also suppose that the number of states of mind which need be taken into account is finite.

  8. Turing’s Answer To What Computation Is Let us imagine the operations performed by the computer to be split up into "simple operations" which are so elementary that it is not easy to imagine them further divided. Every such operation consists of some change of the physical system consisting of the computer and his tape.… We may suppose that in a simple operation not more than one symbol is altered.

  9. Turing’s Answer To What Computation Is Besides these changes of symbols, the simple operations must include changes to the observed squares.… I think it is reasonable to suppose that they can only be squares whose distance from the closest of the immediately previously observed squares does not exceed a certain fixed amount.

  10. The Turing Machine It’s paradoxical that as humans in our quest to understand what machines can do, we have been studying an abstract machine that in essence imitates a human being.

  11. Church-Turing Thesis Central Dogma of Computer Science: **Whatever is computable is computable by the Turing machine.** There is no proof of this claim.

  12. Turing In Defense Of His Claim: “All arguments which can be given are bound to be, fundamentally, appeals to intuition, and for this reason rather unsatisfactory mathematically. The arguments which I shall use are of three kinds. (a) A direct appeal to intuition. (b) A proof of the equivalence of two definitions (in case the new definition has a greater intuitive appeal). (c) Giving examples of large classes of numbers which are computable.”

  13. Algorithm = Turing Machine When we say there is an algorithm computing shortest paths of a graph in O(mlog(n)) times we really mean: There is a Turing Machine that computes the shortest paths of a graph in O(mlog(n)) operations.

  14. Turing Machine Is A Very Powerful Machine • CS tries to understand the limits of TM. • We limit/extend TM and try to understand what can be computed by it. • Limit the # times it’s head is allowed to move left/right and it changes states to poly-time. => poly-time algs • What if the machine had access to a random source => randomized algorithms. • What if there were multiple heads on the tape => parallel algorithms • Limit the length of its tape. => space-efficient algs • What if the head was only allowed to move right => streaming algorithms • …

  15. Outline For Today • Caching • Other Algorithms & Algorithmic Techniques Beyond CS 161 • Parallel Algorithms (Finding Min, Bellman-Ford) • Linear Programming • Other Topics & Classes

  16. Online Algorithms • Takes as input a possibly infinite stream. • At each point in time t make a decision based on • what has been seen so far • but without knowing the rest of the input • Type of Optimality Analysis: Competitive Ratio • “Worst” (Cost of online algorithm)/(Cost of OPT) ratios against any input stream • Where OPT is the best solution possible if we knew the entire input in advance

  17. Caching O.w (miss), send request to disk, put the page into cache. Q: Which page to evict? If page is in cache (hit) reply directly from cache Slow Disk

  18. Caching Input: N pages in disk, and stream of infinite page requests. Online Algorithm: Decide which page to evict from cache when it’s full and there’s a miss. Goal: minimize the number of misses. Idea: LRU: Remove the Least Recently Used page

  19. LRU with k = 3 miss

  20. LRU with k = 3

  21. LRU with k = 3 miss

  22. LRU with k = 3

  23. LRU with k = 3 miss

  24. LRU with k = 3

  25. LRU with k = 3 hit

  26. LRU with k = 3 miss

  27. LRU with k = 3

  28. LRU with k = 3 miss

  29. LRU with k = 3

  30. LRU with k = 3 miss

  31. LRU with k = 3

  32. LRU with k = 3 hit

  33. LRU with k = 3 miss

  34. LRU with k = 3 so and so forth…

  35. Competitive Ratio Claim Claim: If the optimal sequence of choices for a size-h cache causes m misses. Then, for the same sequence of requests, LRU for a size-k cache causes misses Interpretation: If LRU had twice as much cache size as an algorithm OPT that knew the future, it would have at most twice the misses of OPT. Note will prove the claim for

  36. Proof of Competitive Ratio Recursively break the sequence of inputs into phases. Let t be the time when we see the (k+1)st different request. Phase 1: a1 … at-1 Let t` be the time we see the (k+1)st different element starting from at Phase 2: at … at’-1

  37. Proof of Competitive Ratio Phase 4 Phase 3 Phase 2 Phase 1 By construction, each phase has k distinct requests. Q: At most how many misses does LRU have in each phase? A: k b/c even if it evicted everything in the k+1st item, it would have at most k misses. k=3

  38. Proof of Competitive Ratio Phase 4 Phase 3 Phase 2 Phase 1 Q: What’s the minimum misses that any size-h cache must have in any phase? A: k-h b/c k distinct items will be in the cache at different points during the phase, so at least k-h of them must trigger misses. Therefore the CR: k/k-h Q.E.D.

  39. Outline For Today • Caching • Other Algorithms & Algorithmic Techniques Beyond CS 161 • Parallel Algorithms (Finding Min, Bellman-Ford) • Linear Programming • Other Topics & Classes

  40. Parallel Algorithms • Question: Which problems are parallelizable, which are inherently sequential? • Parallelizable: Connected components, sorting, selection, many computational geometry problems all have parallel algorithms • (Believed To Be) Inherently Sequential (P-complete): • DFS • Horn-satisfiability • Conway’s Game of Life, and others.

  41. 2 Common Computational Models • Model 1: Shared Memory (PRAM): Memory … CPU2 CPUk CPU1 Single Machine • Each Time Step, each processor: • Can read a location of memory • Can write to a location of memory • Q: How much time does it take to solve a computational problem with polynomial # processors?

  42. Example 1: Finding the min in an array Memory … CPU(1,3) CPU(4, 5) CPU(1,2) • There are n(n-1) processors, one for each pair (i, j) • Initially allocate an array of size n all 0 • Step 1: Each cpu(i, j) compares i and j • If i < j, then write 1 to j o.w. write 1 to location i • Step 2: return the item whose output memory location is 0

  43. Example 1: Finding the min in an array Memory … CPU(1,3) CPU(4, 5) CPU(1,2)

  44. Model 2: Distributed Memory Input Partition1 Input Partitionk Input Partition2 Machine 2 Machine 1 Machine k • Each machine • performs local computation • send/receives messages to/from other machines • can be synchronouslyor asynchronously • Q: How much communication is necessary? • Q: How many synchronizations is necessary?

  45. Recap: Bellman-Ford ∀ v, and for i={1, …, n} P(v, i): shortest s ⤳ v path with ≤ i edges (or null) L(v, i): w(P(v, i)) (and +∞ for null paths) L(v, i-1) L(v, i) = min minu: ∃(u,v)∈E : L(u, i-1) + c(u,v)

  46. Example: Distributed Bellman-Ford 5 A C 3 -6 -1 D E 2 2 F B

  47. Example: Distributed Bellman-Ford 5 A 0 ∞ C 3 -6 -1 ∞ ∞ D E 2 2 ∞ ∞ F B

  48. Example: Distributed Bellman-Ford 5 A 0 5 C 3 -6 -1 ∞ ∞ D E 2 2 ∞ ∞ F B

  49. Example: Distributed Bellman-Ford 5 A 0 5 C 3 -6 -1 ∞ 8 D E 2 2 7 -1 F B

  50. Example: Distributed Bellman-Ford 5 A 0 5 C 3 -6 -1 1 8 D E 2 2 7 -1 F B

More Related