English 字幕

← Parallel Merge - Intro to Parallel Programming


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

  1. If you recall from earlier in this unit, the way that we compacted an array of
  2. input elements was to compute the address for each of the input elements to be written into the output array,
  3. and then we would scatter these input elements using these scatter addresses into the output array.
  4. We've computed, for instance, that element 21 would be scattered by address 5 into output location 5.
  5. We're going to have the same goal here with merge, but we're going to use a different algorithm,
  6. and our algorithm is going to rely on both of the input arrays being sorted.
  7. So let's take a little bit of a closer look.
  8. So, mentally, we're going to think about assigning 1 thread per input element in each of the 2 sorted lists.
  9. So in this example, we're going to merge 2 sorted sequences of 4 elements each,
  10. so we would launch 8 threads, each of which would be responsible for 1 input element.
  11. So the goal of each thread is, just like the compact example,
  12. to calculate the position of its element in the final list and then scatter that element there.
  13. So, to start with, let's figure out what we are trying to do.
  14. What we're going to ask you to do is fill in the scatter addresses for these 2 sorts.
  15. This is a very useful and common thing that you need to be able to do as you're building a parallel algorithm,
  16. understanding the scatter pattern that will let you get to the final answer.
  17. Since you're going to generate a dense sorted list of 8 elements,
  18. the scatter addresses in these 8 boxes are going to be the numbers from 0 to 7.