Got a YouTube account?

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

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

• 4 Followers
• 24 Lines

Get Embed Code x Embed video Use the following code to embed this video. See our usage guide for more details on embedding. Paste this in your document somewhere (closest to the closing body tag is preferable): ```<script type="text/javascript" src='https://amara.org/embedder-iframe'></script> ``` Paste this inside your HTML body, where you want to include the widget: ```<div class="amara-embed" data-url="http://www.youtube.com/watch?v=PX9z8qc5Z8Y" data-team="udacity"></div> ``` 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?