PandA-2024.02
md.c
Go to the documentation of this file.
1 /*
2 Implemenataion based on:
3 A. Danalis, G. Marin, C. McCurdy, J. S. Meredith, P. C. Roth, K. Spafford, V. Tipparaju, and J. S. Vetter.
4 The scalable heterogeneous computing (shoc) benchmark suite.
5 In Proceedings of the 3rd Workshop on General-Purpose Computation on Graphics Processing Units, 2010.
6 */
7 
8 #include "md.h"
9 
10 void md_kernel(TYPE force_x[nAtoms],
11  TYPE force_y[nAtoms],
12  TYPE force_z[nAtoms],
13  TYPE position_x[nAtoms],
14  TYPE position_y[nAtoms],
15  TYPE position_z[nAtoms],
16  int32_t NL[nAtoms*maxNeighbors])
17 {
18  TYPE delx, dely, delz, r2inv;
19  TYPE r6inv, potential, force, j_x, j_y, j_z;
20  TYPE i_x, i_y, i_z, fx, fy, fz;
21 
22  int32_t i, j, jidx;
23 
24 loop_i : for (i = 0; i < nAtoms; i++){
25  i_x = position_x[i];
26  i_y = position_y[i];
27  i_z = position_z[i];
28  fx = 0;
29  fy = 0;
30  fz = 0;
31 loop_j : for( j = 0; j < maxNeighbors; j++){
32  // Get neighbor
33  jidx = NL[i*maxNeighbors + j];
34  // Look up x,y,z positions
35  j_x = position_x[jidx];
36  j_y = position_y[jidx];
37  j_z = position_z[jidx];
38  // Calc distance
39  delx = i_x - j_x;
40  dely = i_y - j_y;
41  delz = i_z - j_z;
42  r2inv = 1.0/( delx*delx + dely*dely + delz*delz );
43  // Assume no cutoff and aways account for all nodes in area
44  r6inv = r2inv * r2inv * r2inv;
45  potential = r6inv*(lj1*r6inv - lj2);
46  // Sum changes in force
47  force = r2inv*potential;
48  fx += delx * force;
49  fy += dely * force;
50  fz += delz * force;
51  }
52  //Update forces after all neighbors accounted for.
53  force_x[i] = fx;
54  force_y[i] = fy;
55  force_z[i] = fz;
56  //printf("dF=%lf,%lf,%lf\n", fx, fy, fz);
57  }
58 }
#define NL
Definition: 2mm.h:45
#define maxNeighbors
Definition: md.h:16
#define TYPE
Definition: backprop.h:21
#define lj1
Definition: md.h:20
void md_kernel(TYPE force_x[nAtoms], TYPE force_y[nAtoms], TYPE force_z[nAtoms], TYPE position_x[nAtoms], TYPE position_y[nAtoms], TYPE position_z[nAtoms], int32_t NL[nAtoms *maxNeighbors])
Definition: md.c:10
#define nAtoms
Definition: md.h:9
#define lj2
Definition: md.h:21

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13