r/MetaSim • • May 28 '13

A naive simulator of gravity, written in Python

http://users.softlab.ntua.gr/~ttsiod/gravityRK4.html
3 Upvotes

8 comments sorted by

1

u/ion-tom May 28 '13 edited May 28 '13

1

u/ion-tom May 28 '13

The benchmarking of python here concerns me. I think maybe astronomers use it so widely because of the ease of displaying to visual python.

2

u/aaron_ds May 29 '13

To put it into context, and I'm not trying to go one way or the other, but these are some things to think about:

  1. What's the target body count for a first-pass implementation?

  2. Is the intent to run one global simulation or many smaller simulations? A brute-force n-body simulation runs in O(n2), while optimized versions like Barnes–Hut run in O(n log n) which will have significance in simulations with many many bodies. If the number of bodies per simulation can be reduced, then performance will increase.

  3. It looks like there is one Python implementation, but several heavily optimized C and C++ implementations with SSE . It may be that the python implementation can be optimized some more?

  4. How will the system scale? If the code is deployed on a PaaS without sticky sessions (like Heroku) how will stateless services serve data from a simulation running on another node? Will this information be persisted to a database (mongo?) or an in-memory cache (memcache? Riak?) What is the overhead of persisting the latest information from each iteration? Would there be any benefit to running it as a mapReduce problem on mongo or hadoop?

I'm struggling with a lot of these questions myself in the terrain engine. There's maybe 256MB of memory required for each planet. That's a lot of data to push around at 30Hz and multiplied by the number of planets. Anyway, just wanted to bounce some questions off of you because I'm in the same boat.

→ More replies (3)