PhysicsIsFun wrote: |
---|
I tried to insert your tipps into my routine, but the crude test you suggested leads to slightly more computing time: |
if(rx*L>2*R || ry*L>2*R || rz*L>2*R)
4*(R/L)*(R/L)
jonnin wrote: |
---|
multithreading the checks would be nice, its a flat speed up and has no thread complexity issues (you just break the data into say 4 chunks, eg 4 equal lists of sphere locations) and do the same code over the chunks, getting a flat 4x speedup (assuming typical machines have 4 cores, you can mix this up based on your hardware). Since you are not writing anything (the thread functions would presumably just be 4 boolean results on collisions or not) or changing anything during this time, all the race conditions just go away, you don't need mutex or any of that stuff. it literally becomes just 4 lines that look very much like this (actual thread library used changes this very, very slightly, eg it may be create thread instead of begin thread). threadvariable/init code line or two (boilerplate from examples on web); beginthread(function, data1, priority/flags); beginthread(function, data2, priority/flags); beginthread(function, data3, priority/flags); beginthread(function, data4, priority/flags); if you want to take a crack at that idea. Now if you tried to place spheres in threads, that would give you a headache.. you could try to place 2 at the same time that would hit each other but pass the checks because neither is there yet... that sort of thing may be best avoided if you don't have time to get it right. You can still place them 1 by one but check collisions multiples at a time. as for how you do things in C++ ... c++ has a <list> built into the language,but personally I avoid those most of the time in favor of <vectors> unless you absolutely need the ability to insert things in the middle of an ordered group frequently. Whatever you are doing, odds are c++ has a built in container that can do it for you -- containers are done to death in the language/ tools. I thought you were low on time to modify it now, but if you want to do some sort of list or major modifications... let us know if you need help |
lastchance wrote: |
---|
The whole point of the quick test was to avoid lots of multiplies - you've just put a whole lot more in! |
What is all this about ... 4*(R/L)*(R/L) L is being used as a lengthscale throughout. Just work in non-dimensional variables, where L is 1. Or put this in a single variable (diameter_squared?) - I bet the values of R and L don't change after they are first set. |
jonnin wrote: |
---|
sx[0]=abs(pos[u].x-pos[j].x); sy[0]=abs(pos[u].y-pos[j].y); sz[0]=abs(pos[u].z-pos[j].z); sx[1]=1-rx; //periodic boundaries sy[1]=1-ry; sz[1]=1-rz; rx = sx[(sx[0]>0.5)]; ry = sy[(sy[0]>0.5)]; rz = sz[(sz[0]>0.5)]; |
|
|