From: Erik Lindahl <erik@theophys.kth.se>
Subject: Force calculation with neighbourlist
Date: Thu, 04 Mar 1999 20:43:57 +0100 [thread overview]
Message-ID: <36DEE27D.C293552A@theophys.kth.se> (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----
next reply other threads:[~1999-03-04 19:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-03-04 19:43 Erik Lindahl [this message]
1999-03-04 21:04 ` Force calculation with neighbourlist Joachim Wesner
1999-03-04 21:42 ` Joachim Wesner
-- strict thread matches above, loose matches on Subject: below --
1999-03-08 9:08 Erik Lindahl
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox