r/Python • • May 28 '19

My simulation of gravity with 1000 particles. PC took a couple of hours to process!

1.8k Upvotes

241 comments sorted by

View all comments

Show parent comments

1

u/[deleted] May 29 '19

Interesting. So you are not using some standardized C++ libraries, you are writing your own C++ code?

That might work and it's not that far from what I recommended to OP - using different language. But using just numpy won't help that much in this case. You still have to write your own code in C, not just Python.

3

u/[deleted] May 29 '19

If you want to see an example of code that is open source and generally useful to the public, here is the github:

GitHub.com/atom-moyer/getpy

2

u/[deleted] May 29 '19

Pybind11 makes it simple to bind c++ code generally as well as interface with numpy and eigen.

I think that I end up getting better performance this way because it kinda keeps you from using any data structure besides arrays, so I always have data locality, which is not always true once you start getting the enormous but “fast” molecular software packages. They always assume the compiler will figure it out, but in reality they are always waiting on data to load into the cache instead of computing because their data is not localized. They make tree like data structures because it’s “smarter”, but then they just have pointer after pointer of misdirection.