~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to src/KOKKOS/pair_buck_kokkos.cpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ----------------------------------------------------------------------
 
2
   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
 
3
   http://lammps.sandia.gov, Sandia National Laboratories
 
4
   Steve Plimpton, sjplimp@sandia.gov
 
5
 
 
6
   Copyright (2003) Sandia Corporation.  Under the terms of Contract
 
7
   DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
 
8
   certain rights in this software.  This software is distributed under
 
9
   the GNU General Public License.
 
10
 
 
11
   See the README file in the top-level LAMMPS directory.
 
12
------------------------------------------------------------------------- */
 
13
 
 
14
/* ----------------------------------------------------------------------
 
15
   Contributing author: Stan Moore (SNL)
 
16
------------------------------------------------------------------------- */
 
17
 
 
18
#include "math.h"
 
19
#include "stdio.h"
 
20
#include "stdlib.h"
 
21
#include "string.h"
 
22
#include "pair_buck_kokkos.h"
 
23
#include "kokkos.h"
 
24
#include "atom_kokkos.h"
 
25
#include "comm.h"
 
26
#include "force.h"
 
27
#include "neighbor.h"
 
28
#include "neigh_list.h"
 
29
#include "neigh_request.h"
 
30
#include "update.h"
 
31
#include "integrate.h"
 
32
#include "respa.h"
 
33
#include "math_const.h"
 
34
#include "memory.h"
 
35
#include "error.h"
 
36
#include "atom_masks.h"
 
37
 
 
38
using namespace LAMMPS_NS;
 
39
using namespace MathConst;
 
40
 
 
41
#define KOKKOS_CUDA_MAX_THREADS 256
 
42
#define KOKKOS_CUDA_MIN_BLOCKS 8
 
43
 
 
44
/* ---------------------------------------------------------------------- */
 
45
 
 
46
template<class DeviceType>
 
47
PairBuckKokkos<DeviceType>::PairBuckKokkos(LAMMPS *lmp) : PairBuck(lmp)
 
48
{
 
49
  respa_enable = 0;
 
50
 
 
51
  atomKK = (AtomKokkos *) atom;
 
52
  execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
 
53
  datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK;
 
54
  datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK;
 
55
  cutsq = NULL;
 
56
}
 
57
 
 
58
/* ---------------------------------------------------------------------- */
 
59
 
 
60
template<class DeviceType>
 
61
PairBuckKokkos<DeviceType>::~PairBuckKokkos()
 
62
{
 
63
  if (!copymode) {
 
64
    memory->destroy_kokkos(k_eatom,eatom);
 
65
    memory->destroy_kokkos(k_vatom,vatom);
 
66
    k_cutsq = DAT::tdual_ffloat_2d();
 
67
    memory->sfree(cutsq);
 
68
    eatom = NULL;
 
69
    vatom = NULL;
 
70
    cutsq = NULL;
 
71
  }
 
72
}
 
73
 
 
74
/* ---------------------------------------------------------------------- */
 
75
 
 
76
template<class DeviceType>
 
77
void PairBuckKokkos<DeviceType>::compute(int eflag_in, int vflag_in)
 
78
{
 
79
  eflag = eflag_in;
 
80
  vflag = vflag_in;
 
81
 
 
82
  if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1;
 
83
 
 
84
  if (eflag || vflag) ev_setup(eflag,vflag);
 
85
  else evflag = vflag_fdotr = 0;
 
86
 
 
87
  // reallocate per-atom arrays if necessary
 
88
 
 
89
  if (eflag_atom) {
 
90
    memory->destroy_kokkos(k_eatom,eatom);
 
91
    memory->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom");
 
92
    d_eatom = k_eatom.view<DeviceType>();
 
93
  }
 
94
  if (vflag_atom) {
 
95
    memory->destroy_kokkos(k_vatom,vatom);
 
96
    memory->create_kokkos(k_vatom,vatom,maxvatom,6,"pair:vatom");
 
97
    d_vatom = k_vatom.view<DeviceType>();
 
98
  }
 
99
 
 
100
  atomKK->sync(execution_space,datamask_read);
 
101
  k_cutsq.template sync<DeviceType>();
 
102
  k_params.template sync<DeviceType>();
 
103
  if (eflag || vflag) atomKK->modified(execution_space,datamask_modify);
 
104
  else atomKK->modified(execution_space,F_MASK);
 
105
 
 
106
  x = atomKK->k_x.view<DeviceType>();
 
107
  c_x = atomKK->k_x.view<DeviceType>();
 
108
  f = atomKK->k_f.view<DeviceType>();
 
109
  type = atomKK->k_type.view<DeviceType>();
 
110
  tag = atomKK->k_tag.view<DeviceType>();
 
111
  nlocal = atom->nlocal;
 
112
  nall = atom->nlocal + atom->nghost;
 
113
  newton_pair = force->newton_pair;
 
114
  special_lj[0] = force->special_lj[0];
 
115
  special_lj[1] = force->special_lj[1];
 
116
  special_lj[2] = force->special_lj[2];
 
117
  special_lj[3] = force->special_lj[3];
 
118
 
 
119
  // loop over neighbors of my atoms
 
120
 
 
121
  copymode = 1;
 
122
  EV_FLOAT ev = pair_compute<PairBuckKokkos<DeviceType>,void >(this,(NeighListKokkos<DeviceType>*)list);
 
123
  DeviceType::fence();
 
124
 
 
125
  if (eflag_global) eng_vdwl += ev.evdwl;
 
126
  if (vflag_global) {
 
127
    virial[0] += ev.v[0];
 
128
    virial[1] += ev.v[1];
 
129
    virial[2] += ev.v[2];
 
130
    virial[3] += ev.v[3];
 
131
    virial[4] += ev.v[4];
 
132
    virial[5] += ev.v[5];
 
133
  }
 
134
 
 
135
  if (vflag_fdotr) pair_virial_fdotr_compute(this);
 
136
 
 
137
  if (eflag_atom) {
 
138
    k_eatom.template modify<DeviceType>();
 
139
    k_eatom.template sync<LMPHostType>();
 
140
  }
 
141
 
 
142
  if (vflag_atom) {
 
143
    k_vatom.template modify<DeviceType>();
 
144
    k_vatom.template sync<LMPHostType>();
 
145
  }
 
146
 
 
147
  copymode = 0;
 
148
}
 
149
 
 
150
template<class DeviceType>
 
151
template<bool STACKPARAMS, class Specialisation>
 
152
KOKKOS_INLINE_FUNCTION
 
153
F_FLOAT PairBuckKokkos<DeviceType>::
 
154
compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const {
 
155
  (void) i;
 
156
  (void) j;
 
157
  const F_FLOAT r2inv = 1.0/rsq;
 
158
  const F_FLOAT r6inv = r2inv*r2inv*r2inv;
 
159
  const F_FLOAT r = sqrt(rsq);
 
160
  const F_FLOAT rexp = exp(-r*(STACKPARAMS?m_params[itype][jtype].rhoinv:params(itype,jtype).rhoinv));
 
161
 
 
162
  const F_FLOAT forcebuck =
 
163
     (STACKPARAMS?m_params[itype][jtype].buck1:params(itype,jtype).buck1)*r*rexp -
 
164
     (STACKPARAMS?m_params[itype][jtype].buck2:params(itype,jtype).buck2)*r6inv;
 
165
 
 
166
  return forcebuck*r2inv;
 
167
}
 
168
 
 
169
template<class DeviceType>
 
170
template<bool STACKPARAMS, class Specialisation>
 
171
KOKKOS_INLINE_FUNCTION
 
172
F_FLOAT PairBuckKokkos<DeviceType>::
 
173
compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const {
 
174
  (void) i;
 
175
  (void) j;
 
176
  const F_FLOAT r2inv = 1.0/rsq;
 
177
  const F_FLOAT r6inv = r2inv*r2inv*r2inv;
 
178
  const F_FLOAT r = sqrt(rsq);
 
179
  const F_FLOAT rexp = exp(-r*(STACKPARAMS?m_params[itype][jtype].rhoinv:params(itype,jtype).rhoinv));
 
180
 
 
181
 
 
182
  return (STACKPARAMS?m_params[itype][jtype].a:params(itype,jtype).a)*rexp -
 
183
                (STACKPARAMS?m_params[itype][jtype].c:params(itype,jtype).c)*r6inv -
 
184
                (STACKPARAMS?m_params[itype][jtype].offset:params(itype,jtype).offset);
 
185
}
 
186
 
 
187
/* ----------------------------------------------------------------------
 
188
   allocate all arrays
 
189
------------------------------------------------------------------------- */
 
190
 
 
191
template<class DeviceType>
 
192
void PairBuckKokkos<DeviceType>::allocate()
 
193
{
 
194
  PairBuck::allocate();
 
195
 
 
196
  int n = atom->ntypes;
 
197
  memory->destroy(cutsq);
 
198
  memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq");
 
199
  d_cutsq = k_cutsq.template view<DeviceType>();
 
200
  k_params = Kokkos::DualView<params_buck**,Kokkos::LayoutRight,DeviceType>("PairBuck::params",n+1,n+1);
 
201
  params = k_params.d_view;
 
202
}
 
203
 
 
204
/* ----------------------------------------------------------------------
 
205
   init specific to this pair style
 
206
------------------------------------------------------------------------- */
 
207
 
 
208
template<class DeviceType>
 
209
void PairBuckKokkos<DeviceType>::init_style()
 
210
{
 
211
  PairBuck::init_style();
 
212
 
 
213
  // error if rRESPA with inner levels
 
214
 
 
215
  if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) {
 
216
    int respa = 0;
 
217
    if (((Respa *) update->integrate)->level_inner >= 0) respa = 1;
 
218
    if (((Respa *) update->integrate)->level_middle >= 0) respa = 2;
 
219
    if (respa) 
 
220
      error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle");
 
221
  }
 
222
 
 
223
  // irequest = neigh request made by parent class
 
224
 
 
225
  neighflag = lmp->kokkos->neighflag;
 
226
  int irequest = neighbor->nrequest - 1;
 
227
 
 
228
  neighbor->requests[irequest]->
 
229
    kokkos_host = Kokkos::Impl::is_same<DeviceType,LMPHostType>::value &&
 
230
    !Kokkos::Impl::is_same<DeviceType,LMPDeviceType>::value;
 
231
  neighbor->requests[irequest]->
 
232
    kokkos_device = Kokkos::Impl::is_same<DeviceType,LMPDeviceType>::value;
 
233
 
 
234
  if (neighflag == FULL) {
 
235
    neighbor->requests[irequest]->full = 1;
 
236
    neighbor->requests[irequest]->half = 0;
 
237
    neighbor->requests[irequest]->full_cluster = 0;
 
238
  } else if (neighflag == HALF || neighflag == HALFTHREAD) {
 
239
    neighbor->requests[irequest]->full = 0;
 
240
    neighbor->requests[irequest]->half = 1;
 
241
    neighbor->requests[irequest]->full_cluster = 0;
 
242
  } else if (neighflag == N2) {
 
243
    neighbor->requests[irequest]->full = 0;
 
244
    neighbor->requests[irequest]->half = 0;
 
245
    neighbor->requests[irequest]->full_cluster = 0;
 
246
  } else if (neighflag == FULLCLUSTER) {
 
247
    neighbor->requests[irequest]->full_cluster = 1;
 
248
    neighbor->requests[irequest]->full = 1;
 
249
    neighbor->requests[irequest]->half = 0;
 
250
  } else {
 
251
    error->all(FLERR,"Cannot use chosen neighbor list style with buck/kk");
 
252
  }
 
253
}
 
254
 
 
255
/* ----------------------------------------------------------------------
 
256
   init for one type pair i,j and corresponding j,i
 
257
------------------------------------------------------------------------- */
 
258
 
 
259
template<class DeviceType>
 
260
double PairBuckKokkos<DeviceType>::init_one(int i, int j)
 
261
{
 
262
  double cutone = PairBuck::init_one(i,j);
 
263
 
 
264
  k_params.h_view(i,j).a = a[i][j];
 
265
  k_params.h_view(i,j).c = c[i][j];
 
266
  k_params.h_view(i,j).rhoinv = rhoinv[i][j];
 
267
  k_params.h_view(i,j).buck1 = buck1[i][j];
 
268
  k_params.h_view(i,j).buck2 = buck2[i][j];
 
269
  k_params.h_view(i,j).offset = offset[i][j];
 
270
  k_params.h_view(i,j).cutsq = cutone*cutone;
 
271
  k_params.h_view(j,i) = k_params.h_view(i,j);
 
272
  if(i<MAX_TYPES_STACKPARAMS+1 && j<MAX_TYPES_STACKPARAMS+1) {
 
273
    m_params[i][j] = m_params[j][i] = k_params.h_view(i,j);
 
274
    m_cutsq[j][i] = m_cutsq[i][j] = cutone*cutone;
 
275
  }
 
276
  k_cutsq.h_view(i,j) = cutone*cutone;
 
277
  k_cutsq.template modify<LMPHostType>();
 
278
  k_params.template modify<LMPHostType>();
 
279
 
 
280
  return cutone;
 
281
}
 
282
 
 
283
template class PairBuckKokkos<LMPDeviceType>;
 
284
#ifdef KOKKOS_HAVE_CUDA
 
285
template class PairBuckKokkos<LMPHostType>;
 
286
#endif
 
 
b'\\ No newline at end of file'