Got a YouTube account?

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

English subtitles

← Serial Implementation of Scan - Intro to Parallel Programming

Get Embed Code
2 Languages

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

  1. So let's turn to what implementations of scan look like,
  2. and we're going to start off with the straightforward serial implementation.
  3. So here's a serial implementation of inclusive scan. So let me tell you how this works.
  4. We start off by initializing an accumulator variable
  5. that's going to sum our partial results to the identity element.
  6. And then we're going to loop through all the elements in our input array 1 at a time.
  7. So at each step we're going to do 2 things.
  8. The 1st thing we're going to do is we're going to take the current value of the accumulator
  9. and we're going to apply the operation to it with the current element.
  10. So this could be any binary associative operator--plus, times, max, min, and so on.
  11. And we're going to store that value back in the accumulator.
  12. Then we're going to set the output element at this particular position
  13. equal to the accumulator, then move on to the next element.
  14. Now, what we've just defined is an inclusive scan.
  15. What we'd like you to do as a quiz is to convert this code to exclusive scan.
  16. And this is fairly straightforward, so why don't you give it a shot.