How can I optimise my N-body Simulation code further?

Click For Summary
The discussion centers on optimizing a brute force O(N^2) N-body simulation code written in Python, which currently struggles with performance despite using Cython and MPI. The simulation calculates gravitational interactions for large numbers of bodies (10k - 30k) through direct summation of forces at each timestep. Participants suggest that the problem may be better suited for programming forums rather than homework discussions. There is also a recommendation to share the code directly in the forum for more targeted advice. The focus remains on finding further optimization strategies for the existing code.
Chaoyi Zhang
Messages
1
Reaction score
0

Homework Statement


I wrote a brute force O(N^2) N-body code in python and I am not happy with its performance despite the fact that I have cythonised the calculation heavy parts as well as implemented MPI. I am currently out of ideas for how to optimise it further, can I get some advice please?
Edit: the code solve gravitational systems with very large N (10k - 30k) bodies by calculating the trajectories of all the bodies. By brute force, I mean direct summation, summing the force from each particle at each timestep, moving the particles then repeating the process.
Here's a link to my code: https://1drv.ms/f/s!Aks13DdO4pS0jAfWncIFbjg07HpR

calc2.pyx is the acceleration and leapfrog integration calculation written with cython

Nbtest_2.py runs the simulation

setup_calc2.py cythonises calc2.pyx

Homework Equations

The Attempt at a Solution

 
Last edited:
Physics news on Phys.org
Welcome to the PF. :smile:

Is this really homework? Seems like it would fit better in the Programming forums...

Also, I didn't click into your code, but if it isn't too large, you can use the code tags to post your code here at the PF. Like this but without the spaces inside the brackets:

[ code=Python ]
<< insert your code here >>
[ /code ]
 

Similar threads

  • · Replies 19 ·
Replies
19
Views
4K
Replies
6
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
Replies
7
Views
7K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
2K
Replies
12
Views
5K