1 // clang-format off
2 /* ----------------------------------------------------------------------
3 LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
4 https://www.lammps.org/, Sandia National Laboratories
5 Steve Plimpton, sjplimp@sandia.gov
6
7 This software is distributed under the GNU General Public License.
8
9 See the README file in the top-level LAMMPS directory.
10 ------------------------------------------------------------------------- */
11
12 /* ----------------------------------------------------------------------
13 Contributing author: Axel Kohlmeyer (Temple U)
14 ------------------------------------------------------------------------- */
15
16 #include "omp_compat.h"
17 #include "pair_coul_cut_omp.h"
18 #include <cmath>
19 #include "atom.h"
20 #include "comm.h"
21 #include "force.h"
22 #include "neigh_list.h"
23
24
25 #include "suffix.h"
26 using namespace LAMMPS_NS;
27
28 /* ---------------------------------------------------------------------- */
29
PairCoulCutOMP(LAMMPS * lmp)30 PairCoulCutOMP::PairCoulCutOMP(LAMMPS *lmp) :
31 PairCoulCut(lmp), ThrOMP(lmp, THR_PAIR)
32 {
33 suffix_flag |= Suffix::OMP;
34 respa_enable = 0;
35 }
36
37 /* ---------------------------------------------------------------------- */
38
compute(int eflag,int vflag)39 void PairCoulCutOMP::compute(int eflag, int vflag)
40 {
41 ev_init(eflag,vflag);
42
43 const int nall = atom->nlocal + atom->nghost;
44 const int nthreads = comm->nthreads;
45 const int inum = list->inum;
46
47 #if defined(_OPENMP)
48 #pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(eflag,vflag)
49 #endif
50 {
51 int ifrom, ito, tid;
52
53 loop_setup_thr(ifrom, ito, tid, inum, nthreads);
54 ThrData *thr = fix->get_thr(tid);
55 thr->timer(Timer::START);
56 ev_setup_thr(eflag, vflag, nall, eatom, vatom, nullptr, thr);
57
58 if (evflag) {
59 if (eflag) {
60 if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr);
61 else eval<1,1,0>(ifrom, ito, thr);
62 } else {
63 if (force->newton_pair) eval<1,0,1>(ifrom, ito, thr);
64 else eval<1,0,0>(ifrom, ito, thr);
65 }
66 } else {
67 if (force->newton_pair) eval<0,0,1>(ifrom, ito, thr);
68 else eval<0,0,0>(ifrom, ito, thr);
69 }
70
71 thr->timer(Timer::PAIR);
72 reduce_thr(this, eflag, vflag, thr);
73 } // end of omp parallel region
74 }
75
76 /* ---------------------------------------------------------------------- */
77
78 template <int EVFLAG, int EFLAG, int NEWTON_PAIR>
eval(int iifrom,int iito,ThrData * const thr)79 void PairCoulCutOMP::eval(int iifrom, int iito, ThrData * const thr)
80 {
81 int i,j,ii,jj,jnum,itype,jtype;
82 double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,ecoul,fpair;
83 double rsq,r2inv,rinv,forcecoul,factor_coul;
84 int *ilist,*jlist,*numneigh,**firstneigh;
85
86 ecoul = 0.0;
87
88 const dbl3_t * _noalias const x = (dbl3_t *) atom->x[0];
89 dbl3_t * _noalias const f = (dbl3_t *) thr->get_f()[0];
90 const double * _noalias const q = atom->q;
91 const int * _noalias const type = atom->type;
92 const int nlocal = atom->nlocal;
93 const double * _noalias const special_coul = force->special_coul;
94 const double qqrd2e = force->qqrd2e;
95 double fxtmp,fytmp,fztmp;
96
97 ilist = list->ilist;
98 numneigh = list->numneigh;
99 firstneigh = list->firstneigh;
100
101 // loop over neighbors of my atoms
102
103 for (ii = iifrom; ii < iito; ++ii) {
104
105 i = ilist[ii];
106 qtmp = q[i];
107 xtmp = x[i].x;
108 ytmp = x[i].y;
109 ztmp = x[i].z;
110 itype = type[i];
111 jlist = firstneigh[i];
112 jnum = numneigh[i];
113 fxtmp=fytmp=fztmp=0.0;
114
115 for (jj = 0; jj < jnum; jj++) {
116 j = jlist[jj];
117 factor_coul = special_coul[sbmask(j)];
118 j &= NEIGHMASK;
119
120 delx = xtmp - x[j].x;
121 dely = ytmp - x[j].y;
122 delz = ztmp - x[j].z;
123 rsq = delx*delx + dely*dely + delz*delz;
124 jtype = type[j];
125
126 if (rsq < cutsq[itype][jtype]) {
127 r2inv = 1.0/rsq;
128 rinv = sqrt(r2inv);
129 forcecoul = qqrd2e * scale[itype][jtype] * qtmp*q[j]*rinv;
130 fpair = factor_coul*forcecoul * r2inv;
131
132 fxtmp += delx*fpair;
133 fytmp += dely*fpair;
134 fztmp += delz*fpair;
135 if (NEWTON_PAIR || j < nlocal) {
136 f[j].x -= delx*fpair;
137 f[j].y -= dely*fpair;
138 f[j].z -= delz*fpair;
139 }
140
141 if (EFLAG)
142 ecoul = factor_coul * qqrd2e * scale[itype][jtype] * qtmp*q[j]*rinv;
143
144 if (EVFLAG) ev_tally_thr(this, i,j,nlocal,NEWTON_PAIR,
145 0.0,ecoul,fpair,delx,dely,delz,thr);
146 }
147 }
148 f[i].x += fxtmp;
149 f[i].y += fytmp;
150 f[i].z += fztmp;
151 }
152 }
153
154 /* ---------------------------------------------------------------------- */
155
memory_usage()156 double PairCoulCutOMP::memory_usage()
157 {
158 double bytes = memory_usage_thr();
159 bytes += PairCoulCut::memory_usage();
160
161 return bytes;
162 }
163