PandA-2024.02
md_kernel_test.c
Go to the documentation of this file.
1 #include "md.h"
2 
4  TYPE position_x[nAtoms],
5  TYPE position_y[nAtoms],
6  TYPE position_z[nAtoms],
7  int i,
8  int j)
9 {
10  TYPE delx, dely, delz, r2inv;
11  delx = position_x[i] - position_x[j];
12  dely = position_y[i] - position_y[j];
13  delz = position_z[i] - position_z[j];
14  r2inv = delx * delx + dely * dely + delz * delz;
15  return r2inv;
16 }
17 
18 inline void insertInOrder(TYPE currDist[maxNeighbors],
19  int currList[maxNeighbors],
20  int j,
21  TYPE distIJ)
22 {
23  int dist, pos, currList_t;
24  TYPE currMax, currDist_t;
25  pos = maxNeighbors - 1;
26  currMax = currDist[pos];
27  if (distIJ > currMax){
28  return;
29  }
30  for (dist = pos; dist > 0; dist--){
31  if (distIJ < currDist[dist]){
32  currDist[dist] = currDist[dist - 1];
33  currList[dist] = currList[pos - 1];
34  }
35  else{
36  break;
37  }
38  pos--;
39  }
40  currDist[dist] = distIJ;
41  currList[dist] = j;
42 }
43 
44 int buildNeighborList(TYPE position_x[nAtoms],
45  TYPE position_y[nAtoms],
46  TYPE position_z[nAtoms],
47  int NL[nAtoms][maxNeighbors]
48  )
49 {
50  int totalPairs, i, j, k;
51  totalPairs = 0;
52  TYPE distIJ;
53  for (i = 0; i < nAtoms; i++){
54  int currList[maxNeighbors];
55  TYPE currDist[maxNeighbors];
56  for(k=0; k<maxNeighbors; k++){
57  currList[k] = 0;
58  currDist[k] = 999999999;
59  }
60  for (j = 0; j < maxNeighbors; j++){
61  if (i == j){
62  continue;
63  }
64  distIJ = distance(position_x, position_y, position_z, i, j);
65  currList[j] = j;
66  currDist[j] = distIJ;
67  }
68  totalPairs += populateNeighborList(currDist, currList, i, NL);
69  }
70  return totalPairs;
71 }
72 
74  int currList[maxNeighbors],
75  const int i,
76  int NL[nAtoms][maxNeighbors])
77 {
78  int idx, validPairs, distanceIter, neighborIter;
79  idx = 0; validPairs = 0;
80  for (neighborIter = 0; neighborIter < maxNeighbors; neighborIter++){
81  NL[i][neighborIter] = currList[neighborIter];
82  validPairs++;
83  }
84  return validPairs;
85 }
86 
87 int main(){
88  printf("here");
89  int i, iter, j, totalPairs;
90  iter = 0;
91 
92  srand(8650341L);
93 
94  printf("here");
95  TYPE position_x[nAtoms];
96  TYPE position_y[nAtoms];
97  TYPE position_z[nAtoms];
98  TYPE force_x[nAtoms];
99  TYPE force_y[nAtoms];
100  TYPE force_z[nAtoms];
102  int neighborList[size];
103 
104  printf("here");
105  for (i = 0; i < nAtoms; i++)
106  {
107  position_x[i] = rand();
108  position_y[i] = rand();
109  position_z[i] = rand();
110  force_x[i] = rand();
111  force_y[i] = rand();
112  force_z[i] = rand();
113  }
114 
115 
116  printf("here");
117  for(i=0; i<nAtoms; i++){
118  for(j = 0; j < maxNeighbors; ++j){
119  NL[i][j] = 0;
120  }
121  }
122  printf("here");
123  totalPairs = buildNeighborList(position_x, position_y, position_z, NL);
124 
125  for(i=0; i<nAtoms; i++){
126  for(j = 0; j < maxNeighbors; ++j)
127  neighborList[i*maxNeighbors + j] = NL[i][j];
128  }
129 
130  //Function Call
131  for(iter = 0; iter< MAX_ITERATION; iter++) {
132  md_kernel(force_x, force_y, force_z, position_x, position_y, position_z, neighborList);
133  }
134  return 0;
135 }
136 
int main()
void insertInOrder(TYPE currDist[maxNeighbors], int currList[maxNeighbors], int j, TYPE distIJ)
#define NL
Definition: 2mm.h:45
#define maxNeighbors
Definition: md.h:16
#define TYPE
Definition: backprop.h:21
int buildNeighborList(TYPE position_x[nAtoms], TYPE position_y[nAtoms], TYPE position_z[nAtoms], int NL[nAtoms][maxNeighbors])
static const uint32_t k[]
Definition: sha-256.c:22
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 MAX_ITERATION
Definition: gemm.h:27
#define L
Definition: spmv.h:13
#define nAtoms
Definition: md.h:9
int populateNeighborList(TYPE currDist[maxNeighbors], int currList[maxNeighbors], const int i, int NL[nAtoms][maxNeighbors])
TYPE distance(TYPE position_x[nAtoms], TYPE position_y[nAtoms], TYPE position_z[nAtoms], int i, int j)
Definition: md_kernel_test.c:3

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