alphalinux.org high-perf list (1998-2001)
 help / color / mirror / Atom feed
* Re:  Force calculation with neighbourlist
@ 1999-03-08  9:08 Erik Lindahl
  0 siblings, 0 replies; 4+ messages in thread
From: Erik Lindahl @ 1999-03-08  9:08 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1054 bytes --]

Hi,

Thanks for all the input.

I've done some test and it seems like vectorizing sqrt is

the way to go.

I'll probably have a try at rewriting it in assembly too -

are there any good/bad things to consider ;-)

For example, it seems like a good idea to unroll the loop

by treating 4 or so elements in each round. But if there

are not enough registers to do this, what's the best alternative:

1) Only treat 2 elements in each round

2) Use the stack

3) Split it in several loops

   (i.e. first do 1/sqrt, then update forces)

The code will also make use of a table that is quite a bit larger than

the one in Goto's implementation - is this a good idea or will it

just trash the cache by competing with other data?

(Are there any things to think of to avoid cache trashing in assembly code?)

Regards,

Erik

---------------------------------------------------------------------

Erik Lindahl, MSc        	erik@theophys.kth.se

Theoretical Physics, Royal Institute of Technology, STOCKHOLM, SWEDEN

Phone: +46 8 7907172     Fax: +46 8 104879

^ permalink raw reply	[flat|nested] 4+ messages in thread
* Force calculation with neighbourlist
@ 1999-03-04 19:43 Erik Lindahl
  1999-03-04 21:04 ` Joachim Wesner
  1999-03-04 21:42 ` Joachim Wesner
  0 siblings, 2 replies; 4+ messages in thread
From: Erik Lindahl @ 1999-03-04 19:43 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3090 bytes --]

Hi,

I said the other day that I'd share a piece of code with you -

I'd be thrilled if you could come up with any ideas to speed it up :-)

The routine below is an inner loop in a molecular dynamics program.

It is called from C (that's why some indices might be one unit off) with

vectors of coordinates and charges and a list of indices ("neighbours")

for which we want to calculate the coulomb interaction.

This code is called once for each atom every timestep. A typical

system might contain 30000 atoms and each particle has a couple of

hundred of the others as neighbours.

(But if A is a neigbour of B, B is not one of A)

The routine uses a table-driven inverse square root routine

(more or less the same algorithm as Goto's). One idea might be to

implement the whole routine in assembly to avoid loading/unloading

the table. Or should I store values in an array and call a vectorized

sqrti?

Looking forward to any comments!

Regards,

Erik

Parameters:

ix,iy,iz and qi is the position and charge of "this" particle.

pos and charge are the vectors with all positions and charges.

jjnr is the list of neighbours, and nj the size of it.

faction,fip and Vc is the reaction force, "this" force and total

potential.

----code----

     subroutine FORCOUL(ix,iy,iz,qi,pos,nj,

     $     jjnr,charge,faction,fip,Vc)

      real      ix,iy,iz,qi,Vc

      real      pos(*),charge(*),faction(*),fip(3)

      integer*4 nj,jjnr(*)

      integer   k,jnr,j3

      real      invsqrt

      real      fX,fY,fZ

      real      rijX,rijY,rijZ

      real      fijscal,rsq,vijcoul,vctot

      real      rinv1,rinv2

      real      fjx,fjy,fjz

      real      tx,ty,tz

      fX    = 0

      fY    = 0

      fZ    = 0

      vctot = 0

      do k=1,nj

         jnr         = jjnr(k)+1

         j3          = 3*jnr-2

         fjx         = faction(j3)

         fjy         = faction(j3+1)

         fjz         = faction(j3+2)

         rijX        = ix - pos(j3)

         rijY        = iy - pos(j3+1)

         rijZ        = iz - pos(j3+2)

         rsq         = (rijX*rijX)+(rijY*rijY)+(rijZ*rijZ)

         rinv1       = invsqrt(rsq)

         vijcoul     = qi*charge(jnr)*rinv1

         rinv2       = rinv1*rinv1

         vctot       = vctot+vijcoul

         fijscal     = vijcoul*rinv2

         tx       = rijX*fijscal

         ty       = rijY*fijscal

         tz       = rijZ*fijscal

         fX       = fX+tx

         fY       = fY+ty

         fZ       = fZ+tz

         faction(j3)   = fjx-tx

         faction(j3+1) = fjy-ty

         faction(j3+2) = fjz-tz

      end do

      fip(1) = fX

      fip(2) = fY

      fip(3) = fZ

      Vc     = Vc+vctot

      return

      end

----end code----

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-03-08  9:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-03-08  9:08 Force calculation with neighbourlist Erik Lindahl
  -- strict thread matches above, loose matches on Subject: below --
1999-03-04 19:43 Erik Lindahl
1999-03-04 21:04 ` Joachim Wesner
1999-03-04 21:42 ` Joachim Wesner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox