Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Merrills Linear-Complexity BFS on GPUs Part1 - Intro to Parallel Programming

Get Embed Code
2 Languages

Showing Revision 4 created 05/24/2016 by Udacity Robot.

  1. So in the discussion on graphs, I made the following statement; let me quote myself.
  2. "If we had a graph that was just a linear chain, the last node would be node N minus 1.
  3. "The linear chain is very hard to paralyze.
  4. If we're doing a BFS here, it's going to take us order of N steps to get to the end of the graph."
  5. Let me state this problem another way.
  6. I have N nodes in a linear chain,
  7. and each node knows the ID of the next node in the chain.
  8. This is just a simple link list.
  9. What is the algorithm for each node, every node finding the end of the list?
  10. And so of course we can solve this in N steps.
  11. Let's say that each node has a next pointer, and I've shown those in blue,
  12. that points to the next node in the chain, and the last node has next equals null.
  13. Now we don't want to change the next pointers at all, or else we'll lose the structure of our lists.
  14. So we're going to assume they're read only.
  15. So we're also going to store a second pointer per node that we can change.
  16. For historical purposes, we'll call this pointer chum,
  17. and we're going to designate it in red.
  18. And at the end of the algorithm, we want each node's chum pointer to point to the last node in the chain.
  19. So the straightforward algorithm is on each iteration on each node,
  20. set chum to chum to next until we reach a node where next is null.
  21. So we'll start off by making all chum pointers point to their own nodes.
  22. That's how we are going to initialize them, and again, on each iteration, we will set chum to the next pointer.
  23. So on the first iteration it's going to look like this, so now we're going to do another iteration,
  24. so for any particular node, we look for chum and then next.
  25. So on the second iteration, it's going to look like this, and so on, and so on.
  26. So on each iteration, the length of the chum pointer is going to be 1 more than it was on the iteration before.
  27. So the question is--the important question is, can we do better?
  28. And it turns out the answer is yes,
  29. and this algorithm described by Danny Hillis and Guy Steele in 1986,
  30. not discovered by them but described very nicely,
  31. is so cool that it's one of the reasons that I decided to do parallel computing in the first place.
  32. So let's analyze the complexity of the algorithm that we just described.
  33. Clearly a serial processor can do this computation in N steps in order of N work.
  34. How about the parallel processor?
  35. We know that it takes N steps; how much work?
  36. Your choices are order of N, N log N, N square root of N, or N-squared.