I'm working on a (c++, opengl) project where I need to have lots of particles which influence eachother, if I'm correct this is called a nbody problem. Does someone knows what solutions there are for algorithms like this.
I know the barnes hut algorithm and maybe I can peek around openCL, though I'm not just wondering if you maybe used other solutions.
The code which I'll create will have lots of:
for(int i = 0; i < num_particles; ++i) {
for(int j = i+1, j < num_particles; ++j)
dist = distance(particles[i],particles[j]);
if(dist > limit) {....}
}
}
Kind regards, Pollux
Kd-trees are ideal for finding all objects (particles in this case) at a maximum distance. If the tree is balanced look ups are O(log n)
.
This is where data structures like Octrees come in handy. They can reduce your O(N^2)
loops to O(N*log(N))
, at the expense of losing a tiny bit of accuracy.
If you want to have a HUGE computation power on lot of quite simple bodies - get interested in nvidia CUDA and doing your work on GPU shader units. This can give you more performance even comparing to quad-core CPUs with multithreading
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With