-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnnb.cpp
More file actions
60 lines (48 loc) · 1.31 KB
/
Copy pathnnb.cpp
File metadata and controls
60 lines (48 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// List the particles those will be active
// according to the no of nearest neighbors
void neborlist(int npa, int np, double **r,
double bl, double rcld2, int *nnb)
{
int i,j,tn,n;
double ds2,dx,dy,dz;
static double ***g;
static int k=0,mt,dim,**nbl;
if(k==0){
dim=3;
mt=omp_get_max_threads();
g=(double***)calloc(mt,sizeof(double**));
nbl=(int**)calloc(mt,sizeof(int*));
for(i=0;i<mt;i++){
g[i]=(double**)calloc(np,sizeof(double*));
nbl[i]=(int*)calloc(npa,sizeof(int));
for(j=0;j<np;j++) g[i][j]=(double*)calloc(dim,sizeof(double));
}
k++;
}
// Copy data to each slave thread and initialization
for(i=0;i<mt;i++){
for(j=0;j<np;j++){
if(j<npa) nbl[i][j] = 0;
for(n=0;n<dim;n++) g[i][j][n] = r[j][n];
}
}
#pragma omp parallel for firstprivate(npa,np,bl,rcld2)\
private(j,tn,dx,dy,dz,ds2) schedule(dynamic,1)
for(i=npa;i<np;i++){
tn=omp_get_thread_num();
for(j=0;j<np;j++){
if(i!=j){
dx = g[tn][i][0] - g[tn][j][0];
dy = g[tn][i][1] - g[tn][j][1];
dz = g[tn][i][2] - g[tn][j][2];
dx-=bl*rint(dx/bl);
dy-=bl*rint(dy/bl);
dz-=bl*rint(dz/bl);
ds2 = dx*dx + dy*dy + dz*dz;
if(ds2<=rcld2) nbl[tn][i-npa] += 1;
}
}
}
// Collect data from all the threads and copy into the array
for(i=npa;i<np;i++)for(j=0;j<mt;j++) nnb[i-npa] += nbl[j][i-npa];
}