English subtitles

← How To Implement Dense N-Body as Simply As Possible - Intro to Parallel Programming

Get Embed Code
2 Languages

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

  1. So let's start by looking at how we might implement this as simply as possible,
  2. and we're going to begin by thinking about this computation as working on an N by N matrix.
  3. The N bodies on the X-axis here are the source of each force,
  4. and the N bodies on the Y-axis here are the destination of each force.
  5. The source and destination objects are the same objects, of course.
  6. This is just how we're organizing the computation.
  7. So the matrix element at the position X,Y
  8. represents the force that source element X exerts on destination element Y,
  9. and what we want to do is calculate the total amount of force
  10. from all source objects on each destination object.
  11. This formulation of the problem exhibits a lot of parallelism.
  12. Each of the N-squared forces can be computed in parallel.
  13. We just load the parameters of the source and destination thread to do one particular computation,
  14. and compute the force, say, using gravitational attraction.
  15. This requires specifying parameters for each object.
  16. For gravity, this would be, say, the mass and the position, X, Y, Z.
  17. Then each object, say object Y, must add up all N forces that act on it.
  18. Then, we have to calculate N reductions of N forces also in parallel.
  19. Since we want to run this computation on tens to hundreds of thousands, maybe even millions of elements,
  20. we can see that we have a lot of parallelism to exploit.
  21. In this case, the computation would be very straightforward.
  22. We will now see that if we run it in this way, we would be making poor use of our memory bandwidth,
  23. so if we assume that all of our N-squared force computations running in parallel must go to global memory,
  24. how many times must we fetch each element as a function of N?