1

I 've done some work on my graduation project and achieved several molecule structures + force calculation under Lennard-Jones potential and Coulomb potential + inter-molecular bonding(as in picture)

(http://img17.imageshack.us/img17/3133/simulasyon.png)

All done with Verlet algorithm in a single thread.

The problem is: i am using "calculations table"-array for quick answers to x^(3.5),x^(1.4), (1/x).... because it is very slow to compute with native methods of java. Array - access time is real high so i tried "unsafe()" methods and still very slow (only %10 performance gain).

Tried IntBuffer and DoubleBuffer and still no good.

Program calculates O(n) bond calculations, O(nlog(n)) Lennard-Jones (+ extra Pauli exclusion principle) and O(nlog(n)) Coulomb force calculations. Poor speed at 1500+ particles (and 7000+ bonds) .

I already checked where is the speed bottleneck(it is Lennard Jones + Coulomb). it takes 4 milliseconds for one time-step calculation at 1500 particles. I need it be 1 milliseconds.

Only if i could use arrays as fast as any other language(safe or not).

Also tried replacing divisions with multiplications and hashmaps and lists(same performance with arrays).

Do you know any other way of decreasing the time for calculation per timestep? Thank you. Computer: 2.0 GHz single-core intel, 1.2GB RAM, windows-XP SP-3 and Eclipse Indigo.

12
  • 1
    Interesting question - I have retagged it slightly for you to improve your chances of getting the right people involved. You may want to post some code, in particular a small example showing the (slow) speed of calculation, and the (slow) speed of arrays when you've tried to sort this out. Commented Jun 21, 2012 at 8:13
  • The speed gap between modern processors and memory is much greater than it was 15 years ago. Have you tried just calculating those values instead of using lookup tables? Commented Jun 21, 2012 at 8:17
  • I already tried single-variables for memory test. Single 'final a=...' type variable is at least 5-8 times faster. Accessing to single variables is easy and fast just like any other language. Arrays are problem. I even replaced arrays with local arrays to get some speed but again not enough(%5 increase). I could make 2000000 single variables if 'if' sentences were zero-time computing. Even then 2M single variables would took years to add :). Here is some sample code: Commented Jun 21, 2012 at 8:25
  • 1)Look at each neighbor grid(squares) 2)look at each particle in those grids. 3)Distance 'Math.sqrt(vxvx+vyvy))' is a little slow so i tried 'answer_array[(int)(vxvx+vyvy)]' 4)Get force under the Lennard-Jones and Coulomb potentials '1.0/distance' is slow so i used 'division_array[(int)distance]' then 'Math.pow(x,n)' is slow xxx* is not enough too! i used 'power_n_array[x]' 5)Calculate bonds forces if there are any 'f=k*(balance_distance-distance)' even for this i use 'f=k_matrix[(int)(delta_distance)]' this is fastest i could. 'Array acces time' is 3 units (0.4 units for single) Commented Jun 21, 2012 at 8:40
  • 1
    It would be easier to help if you could post the code somewhere... Commented Jan 19, 2013 at 15:54

1 Answer 1

1

Instead of using a lookup tables, try using Chebyshev polynomials. Remember that you can exponentiate x^k in only ln(k) steps.

It may seem like a lot of operations, but the fact that in can be done without hitting memory (and therefore not affecting the cache) can make it significantly faster than a lookup table.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, cpus today can calculate much faster than its ram fetching data. It was too long ago too. Now I'm using gpgpu which is much easier thn doing cpu-specific optimizations and I could use your suggestion in gpgpu too. Thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.