This commit is contained in:
Evghenii
2014-01-30 14:49:38 +01:00
parent 5e37370618
commit cedf4bccf4
2 changed files with 21 additions and 18 deletions

View File

@@ -2,7 +2,7 @@ PROG=nbody
ISPC_SRC=nbody.ispc ISPC_SRC=nbody.ispc
#CU_SRC=nbody.cu #CU_SRC=nbody.cu
CXX_SRC=nbody.cpp CXX_SRC=nbody.cpp
PTXCC_REGMAX=128 PTXCC_REGMAX=64
LLVM_GPU=1 LLVM_GPU=1
NVVM_GPU=1 NVVM_GPU=1

View File

@@ -87,24 +87,27 @@ void computeForces(
real iaccy = 0; real iaccy = 0;
real iaccz = 0; real iaccz = 0;
real igpot = 0; real igpot = 0;
for (uniform int j = 0; j < nbodies; j++) for (uniform int j = 0; j < nbodies; j += 1)
{ {
const real jposx = posx[j]; #define STEP(jk) {\
const real jposy = posy[j]; const real jposx = posx[j+jk]; \
const real jposz = posz[j]; const real jposy = posy[j+jk]; \
const real jmass = mass[j]; const real jposz = posz[j+jk]; \
const real dx = jposx - iposx; const real jmass = mass[j+jk]; \
const real dy = jposy - iposy; const real dx = jposx - iposx; \
const real dz = jposz - iposz; const real dy = jposy - iposy; \
const real r2 = dx*dx + dy*dy + dz*dz; const real dz = jposz - iposz; \
const real rinv = r2 > 0.0d ? rsqrt((float)r2) : 0; const real r2 = dx*dx + dy*dy + dz*dz; \
const real mrinv = -jmass * rinv; const real rinv = r2 > 0.0d ? rsqrt((float)r2) : 0; \
const real mrinv3 = mrinv * rinv*rinv; const real mrinv = -jmass * rinv; \
const real mrinv3 = mrinv * rinv*rinv; \
iaccx += mrinv3 * dx; \
iaccy += mrinv3 * dy; iaccx += mrinv3 * dx; \
iaccz += mrinv3 * dz; iaccy += mrinv3 * dy; \
igpot += mrinv; iaccz += mrinv3 * dz; \
igpot += mrinv; \
}
STEP(0)
} }
accx[i] = iaccx; accx[i] = iaccx;
accy[i] = iaccy; accy[i] = iaccy;