NAMD
ComputeNonbondedSelf.C
Go to the documentation of this file.
1 
7 #include "ComputeNonbondedSelf.h"
8 #include "ReductionMgr.h"
9 #include "Patch.h"
10 #include "LdbCoordinator.h"
11 #include "Molecule.h"
12 
13 #include "Node.h"
14 #include "SimParameters.h"
15 
16 #include "Parameters.h"
17 #include "LJTable.h"
18 
19 #define MIN_DEBUG_LEVEL 4
20 // #define DEBUGM
21 #include "Debug.h"
22 
24  ComputeNonbondedWorkArrays* _workArrays,
25  int minPartition, int maxPartition, int numPartitions)
26  : ComputePatch(c,pid), workArrays(_workArrays),
27  minPart(minPartition), maxPart(maxPartition), numParts(numPartitions)
28 {
30  if (pressureProfileOn) {
35  } else {
37  pressureProfileData = NULL;
38  }
39  pairlistsValid = 0;
40  pairlistTolerance = 0.;
44 }
45 
46 #ifdef NAMD_AVXTILES
49 
50  if (avxTilesMode) {
51  tileLists.setSimParams(scaling, scale14, c1, c3, switchOn2,
52  knl_fast_grad_table, knl_fast_ener_table,
53  knl_scor_grad_table, knl_scor_ener_table,
54  avx_tiles_eps4_sigma, avx_tiles_eps4_sigma_14,
55  (float *)ljTable->table_val(0,0),
56  ljTable->get_table_dim(), knl_slow_grad_table,
57  knl_slow_ener_table, knl_excl_grad_table,
58  knl_excl_ener_table, avxTilesMode);
59  tileLists.atomUpdate(patch->getTiles(), patch->getTiles());
60  }
61 }
62 #endif
63 
67  // BEGIN LA
69  // END LA
70 
76 }
77 
79 {
80  delete reduction;
82  delete [] pressureProfileData;
83  if (avgPositionBox != NULL) {
85  }
86  // BEGIN LA
87  if (velocityBox != NULL) {
89  }
90  // END LA
91 
92  if (psiSumBox != NULL)
94  if (intRadBox != NULL)
96  if (bornRadBox != NULL)
98  if (dEdaSumBox != NULL)
100  if (dHdrPrefixBox != NULL)
102 }
103 
105 
106  if (patch->flags.doGBIS) {
107  gbisPhase = 1 + (gbisPhase % 3);//1->2->3->1...
108  }
109 
110 #if !(defined(NAMD_CUDA) || defined(NAMD_HIP))
111  if ( patch->flags.doNonbonded && numAtoms ) {
112  return 0; // work to do, enqueue as usual
113  } else {
114 #else
115  {
116 #endif
117 
118  if (patch->flags.doGBIS) {
119  if (gbisPhase == 1) {
120  psiSumBox->skip();
121  intRadBox->skip();
122  if (patch->flags.doNonbonded) return 1;
123  else gbisPhase = 2;
124  }
125  if (gbisPhase == 2) {
126  bornRadBox->skip();
127  dEdaSumBox->skip();
128  if (patch->flags.doNonbonded) return 1;
129  else gbisPhase = 3;
130  }
131  if (gbisPhase == 3) {
132  dHdrPrefixBox->skip();
133  }
134  }
135 
136  // skip all boxes
137  positionBox->skip();
138  forceBox->skip();
140  // BEGIN LA
142  // END LA
143 
145  reduction->submit();
146 
147  if (pressureProfileOn)
149 
150 #if !(defined(NAMD_CUDA) || defined(NAMD_HIP))
151  // Inform load balancer
153 #endif
154 
155  return 1; // no work to do, do not enqueue
156  }
157 }
158 
160 {
161  #ifdef NAMD_AVXTILES
162  if (avxTilesMode) {
163  doForceTiles(p, pExt, r);
164  return;
165  }
166  #endif
167 
168  // Inform load balancer.
169  // I assume no threads will suspend until endWork is called
170  //single phase declarations
171  CompAtom* v;
172  int doEnergy = patch->flags.doEnergy;
173 
174 
175 /*******************************************************************************
176  * Prepare Parameters
177  ******************************************************************************/
178  if (!patch->flags.doGBIS || gbisPhase == 1) {
179 
180 #ifdef TRACE_COMPUTE_OBJECTS
181  double traceObjStartTime = CmiWallTimer();
182 #endif
183 
184  DebugM(2,"doForce() called.\n");
185  DebugM(1,numAtoms << " patch 1 atoms\n");
186  DebugM(3, "NUMATOMSxNUMATOMS = " << numAtoms*numAtoms << "\n");
187 
188  for ( int i = 0; i < reductionDataSize; ++i ) reductionData[i] = 0;
189  if (pressureProfileOn) {
190  int n = pressureProfileAtomTypes;
191  memset(pressureProfileData, 0, 3*n*n*pressureProfileSlabs*sizeof(BigReal));
192  // adjust lattice dimensions to allow constant pressure
193  const Lattice &lattice = patch->lattice;
195  pressureProfileMin = lattice.origin().z - 0.5*lattice.c().z;
196  }
197 
198  plint maxa = (plint)(-1);
199  if ( numAtoms > maxa ) {
200  char estr[1024];
201  sprintf(estr,"patch has %d atoms, maximum allowed is %d",numAtoms,maxa);
202  NAMD_die(estr);
203  }
204 
205  params.offset = 0.;
206  params.offset_f = 0.;
207  params.p[0] = p;
208  params.p[1] = p;
209  params.pExt[0] = pExt;
210  params.pExt[1] = pExt;
211 #ifdef NAMD_KNL
212  CompAtomFlt *pFlt = patch->getCompAtomFlt();
213  params.pFlt[0] = pFlt;
214  params.pFlt[1] = pFlt;
215 #endif
217  // BEGIN LA
219  if (params.doLoweAndersen) {
220  DebugM(4, "opening velocity box\n");
221  v = velocityBox->open();
222  params.v[0] = v;
223  params.v[1] = v;
224  }
225  // END LA
226 #if !(defined(NAMD_CUDA) || defined(NAMD_HIP))
227  params.ff[0] = r->f[Results::nbond_virial];
228  params.ff[1] = r->f[Results::nbond_virial];
229 #endif
230  params.numAtoms[0] = numAtoms;
231  params.numAtoms[1] = numAtoms;
232 
233  // DMK - Atom Separation (water vs. non-water)
234  #if NAMD_SeparateWaters != 0
235  params.numWaterAtoms[0] = numWaterAtoms;
236  params.numWaterAtoms[1] = numWaterAtoms;
237  #endif
238 
241 
245 
247 
249  params.savePairlists = 0;
250  params.usePairlists = 0;
251  if ( patch->flags.savePairlists ) {
252  params.savePairlists = 1;
253  params.usePairlists = 1;
254  } else if ( patch->flags.usePairlists ) {
255  if ( ! pairlistsValid ||
258  } else {
259  params.usePairlists = 1;
260  }
261  }
262  if ( ! params.usePairlists ) {
263  pairlistsValid = 0;
264  }
267  if ( params.savePairlists ) {
268  pairlistsValid = 1;
272  }
273 
274 
275 /*******************************************************************************
276  * Call Nonbonded Functions
277  ******************************************************************************/
278 
279  if (numAtoms) {
281  {
282 #if !(defined(NAMD_CUDA) || defined(NAMD_HIP))
283  params.fullf[0] = r->f[Results::slow_virial];
284  params.fullf[1] = r->f[Results::slow_virial];
285 #endif
286  if ( patch->flags.doMolly ) {
287  if ( doEnergy ) calcSelfEnergy(&params);
288  else calcSelf(&params);
289  CompAtom *p_avg = avgPositionBox->open();
290  params.p[0] = p_avg;
291  params.p[1] = p_avg;
292  if ( doEnergy ) calcSlowSelfEnergy(&params);
293  else calcSlowSelf(&params);
294  avgPositionBox->close(&p_avg);
295  } else if ( patch->flags.maxForceMerged == Results::slow ) {
296  if ( doEnergy ) calcMergeSelfEnergy(&params);
297  else calcMergeSelf(&params);
298  } else {
299  if ( doEnergy ) calcFullSelfEnergy(&params);
300  else calcFullSelf(&params);
301  }
302  }
303  else
304  if ( doEnergy ) calcSelfEnergy(&params);
305  else calcSelf(&params);
306  }//end if atoms
307 
308  // BEGIN LA
309  if (params.doLoweAndersen) {
310  DebugM(4, "closing velocity box\n");
311  velocityBox->close(&v);
312  }
313  // END LA
314  }//end if not gbis
315 
316 /*******************************************************************************
317  * gbis Loop
318 *******************************************************************************/
319 if (patch->flags.doGBIS) {
323  gbisParams.numPatches = 1;//self
326  gbisParams.epsilon_s = simParams->solvent_dielectric;
327  gbisParams.epsilon_p = simParams->dielectric;
328  gbisParams.rho_0 = simParams->coulomb_radius_offset;
329  gbisParams.kappa = simParams->kappa;
330  gbisParams.cutoff = simParams->cutoff;
331  gbisParams.doSmoothing = simParams->switchingActive;
332  gbisParams.a_cut = simParams->alpha_cutoff;
333  gbisParams.delta = simParams->gbis_delta;
334  gbisParams.beta = simParams->gbis_beta;
335  gbisParams.gamma = simParams->gbis_gamma;
336  gbisParams.alpha_max = simParams->alpha_max;
337  gbisParams.cid = cid;
341  gbisParams.doEnergy = doEnergy;
342  gbisParams.fsMax = simParams->fsMax;
343  for (int i = 0; i < numGBISPairlists; i++)
345 
346  //open boxes
347  if (gbisPhase == 1) {
354  } else if (gbisPhase == 2) {
359  } else if (gbisPhase == 3) {
362  }
363 
364  //make call to calculate GBIS
367  }
368 
369  //close boxes
370  if (gbisPhase == 1) {
372  } else if (gbisPhase == 2) {
374  } else if (gbisPhase == 3) {
380  }
381 }// end if doGBIS
382 
383 /*******************************************************************************
384  * Reduction
385 *******************************************************************************/
386  if (!patch->flags.doGBIS || gbisPhase == 3) {
388  if (pressureProfileOn)
390 
391 
392 #ifdef TRACE_COMPUTE_OBJECTS
393  traceUserBracketEvent(TRACE_COMPOBJ_IDOFFSET+cid, traceObjStartTime, CmiWallTimer());
394 #endif
395 
396  reduction->submit();
397  if (pressureProfileOn)
399  }// end not gbis
400 }
401 
402 #ifdef NAMD_AVXTILES
403 void ComputeNonbondedSelf::doForceTiles(CompAtom* p, CompAtomExt* pExt,
404  Results* r)
405 {
406  const int doEnergy = patch->flags.doEnergy;
407  const int doVirial = patch->flags.doVirial;
408  const int doFull = patch->flags.doFullElectrostatics;
409 
410 #ifdef TRACE_COMPUTE_OBJECTS
411  double traceObjStartTime = CmiWallTimer();
412 #endif
413 
414  DebugM(2,"doForceTiles() called.\n");
415  DebugM(1,numAtoms << " patch 1 atoms\n");
416  DebugM(3, "NUMATOMSxNUMATOMS = " << numAtoms*numAtoms << "\n");
417 
418  const Lattice &lattice = patch->lattice;
419  for ( int i = 0; i < reductionDataSize; ++i ) reductionData[i] = 0;
420 
421  plint maxa = (plint)(-1);
422  if ( numAtoms > maxa ) {
423  char estr[1024];
424  sprintf(estr,"patch has %d atoms, maximum allowed is %d",numAtoms,maxa);
425  NAMD_die(estr);
426  }
427 
428  int doList = false;
429  if ( patch->flags.savePairlists ) {
430  doList = 1;
431  pairlistsValid = 1;
433  } else if ( patch->flags.usePairlists ) {
434  if (!pairlistsValid ||
437  pairlistsValid = 0;
438  doList = 1;
439  }
440  } else
441  doList = 1;
442 
443  if (doList) {
444  double plcutoff = cutoff;
446  plcutoff += patch->flags.pairlistTolerance * 2.0;
447  tileLists.updateBuildInfo(patch->flags.step, minPart, maxPart,
448  numParts, plcutoff);
449  }
450 
451  Vector offset(0., 0., 0.);
452  tileLists.updateParams(lattice, offset, cutoff);
453 
454  tileLists.nbForceAVX512(doEnergy, doVirial, doFull, doList);
455 
456  reductionData[exclChecksumIndex] = tileLists.exclusionChecksum();
457  if (doEnergy) {
458  reductionData[vdwEnergyIndex] = tileLists.energyVdw();
459  reductionData[electEnergyIndex] = tileLists.energyElec();
460  if (doFull)
461  reductionData[fullElectEnergyIndex] = tileLists.energySlow();
462  }
463  if (doVirial) {
464  reductionData[virialIndex_XX] = tileLists.virialXX();
465  reductionData[virialIndex_XY] = tileLists.virialXY();
466  reductionData[virialIndex_XZ] = tileLists.virialXZ();
467  reductionData[virialIndex_YX] = tileLists.virialXY();
468  reductionData[virialIndex_YY] = tileLists.virialYY();
469  reductionData[virialIndex_YZ] = tileLists.virialYZ();
470  reductionData[virialIndex_ZX] = tileLists.virialXZ();
471  reductionData[virialIndex_ZY] = tileLists.virialYZ();
472  reductionData[virialIndex_ZZ] = tileLists.virialZZ();
473  if (doFull) {
474  reductionData[fullElectVirialIndex_XX] = tileLists.virialSlowXX();
475  reductionData[fullElectVirialIndex_XY] = tileLists.virialSlowXY();
476  reductionData[fullElectVirialIndex_XZ] = tileLists.virialSlowXZ();
477  reductionData[fullElectVirialIndex_YX] = tileLists.virialSlowXY();
478  reductionData[fullElectVirialIndex_YY] = tileLists.virialSlowYY();
479  reductionData[fullElectVirialIndex_YZ] = tileLists.virialSlowYZ();
480  reductionData[fullElectVirialIndex_ZX] = tileLists.virialSlowXZ();
481  reductionData[fullElectVirialIndex_ZY] = tileLists.virialSlowYZ();
482  reductionData[fullElectVirialIndex_ZZ] = tileLists.virialSlowZZ();
483  }
484  }
485 
486  if (!patch->flags.doGBIS || gbisPhase == 3) {
488 
489 #ifdef TRACE_COMPUTE_OBJECTS
490  traceUserBracketEvent(TRACE_COMPOBJ_IDOFFSET+cid, traceObjStartTime,
491  CmiWallTimer());
492 #endif
493 
494  reduction->submit();
495  } // end not gbis
496 }
497 #endif
static Node * Object()
Definition: Node.h:86
Box< Patch, GBReal > * registerDEdaSumDeposit(Compute *cid)
Definition: Patch.C:203
Pairlists * pairlists
Box< Patch, CompAtom > * avgPositionBox
Box< Patch, CompAtom > * registerAvgPositionPickup(Compute *cid)
Definition: Patch.C:133
CompAtom * p
Definition: ComputePatch.h:37
int sequence(void)
Definition: Compute.h:64
CompAtomExt * pExt
Definition: ComputePatch.h:36
void unregisterAvgPositionPickup(Compute *cid, Box< Patch, CompAtom > **const box)
Definition: Patch.C:139
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
static void submitReductionData(BigReal *, SubmitReduction *)
Parameters * parameters
#define TRACE_COMPOBJ_IDOFFSET
Definition: Compute.h:77
void unregisterPsiSumDeposit(Compute *cid, Box< Patch, GBReal > **const box)
Definition: Patch.C:173
int32 ComputeID
Definition: NamdTypes.h:278
static void(* calcSelf)(nonbonded *)
Lattice & lattice
Definition: Patch.h:127
CompAtom * p[2]
ComputeNonbondedWorkArrays *const workArrays
Patch * patch
Definition: ComputePatch.h:46
Box< Patch, Real > * dHdrPrefixBox
void calcGBIS(nonbonded *params, GBISParamStruct *gbisParams)
Definition: ComputeGBIS.C:261
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
Box< Patch, Results > * forceBox
Definition: ComputePatch.h:51
int savePairlists
Definition: PatchTypes.h:40
BigReal & item(int i)
Definition: ReductionMgr.h:313
GBISParamStruct gbisParams
#define DebugM(x, y)
Definition: Debug.h:75
CompAtom * v[2]
BigReal z
Definition: Vector.h:74
void unregisterDHdrPrefixPickup(Compute *cid, Box< Patch, Real > **const box)
Definition: Patch.C:221
int usePairlists
Definition: PatchTypes.h:39
BigReal * reduction
static void submitPressureProfileData(BigReal *, SubmitReduction *)
static BigReal pressureProfileThickness
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:366
Box< Patch, Real > * registerBornRadPickup(Compute *cid)
Definition: Patch.C:195
LDObjHandle ldObjHandle
Definition: Compute.h:44
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:279
int doLoweAndersen
Definition: PatchTypes.h:27
Box< Patch, GBReal > * dEdaSumBox
SimParameters * simParameters
virtual void atomUpdate()
Definition: ComputePatch.C:78
Flags flags
Definition: Patch.h:128
Box< Patch, GBReal > * registerPsiSumDeposit(Compute *cid)
Definition: Patch.C:163
unsigned short plint
static void(* calcMergeSelfEnergy)(nonbonded *)
Pairlists * gbisStepPairlists[4]
static BigReal pressureProfileMin
SubmitReduction * pressureProfileReduction
Results * r
Definition: ComputePatch.h:38
int doEnergy
Definition: PatchTypes.h:20
int doFullElectrostatics
Definition: PatchTypes.h:23
Box< Patch, Real > * registerIntRadPickup(Compute *cid)
Definition: Patch.C:178
void skipWork(const LDObjHandle &handle)
Force * f[maxNumForces]
Definition: PatchTypes.h:146
int get_table_dim() const
Definition: LJTable.h:44
SubmitReduction * reduction
CompAtomExt * pExt[2]
const TableEntry * table_val(unsigned int i, unsigned int j) const
Definition: LJTable.h:35
PatchID getPatchID() const
Definition: Patch.h:114
ComputeNonbondedSelf(ComputeID c, PatchID pid, ComputeNonbondedWorkArrays *_workArrays, int minPartition=0, int maxPartition=1, int numPartitions=1)
static void(* calcFullSelf)(nonbonded *)
int doNonbonded
Definition: PatchTypes.h:22
void NAMD_die(const char *err_msg)
Definition: common.C:147
static LdbCoordinator * Object()
static void(* calcSlowSelf)(nonbonded *)
BigReal maxAtomMovement
Definition: PatchTypes.h:42
void skip(void)
Definition: Box.h:63
void unregisterBornRadPickup(Compute *cid, Box< Patch, Real > **const box)
Definition: Patch.C:198
static void(* calcSlowSelfEnergy)(nonbonded *)
Box< Patch, Real > * bornRadBox
int gbisPhase
Definition: Compute.h:39
Parameters * parameters
Definition: Node.h:180
Box< Patch, GBReal > * psiSumBox
static void(* calcSelfEnergy)(nonbonded *)
virtual void doForce(CompAtom *p, CompAtomExt *pExt, Results *r)
Box< Patch, Real > * intRadBox
#define simParams
Definition: Output.C:129
virtual void initialize()
Definition: ComputePatch.C:46
Random * rand
Definition: Node.h:175
Box< Patch, CompAtom > * positionBox
Definition: ComputePatch.h:50
void unregisterIntRadPickup(Compute *cid, Box< Patch, Real > **const box)
Definition: Patch.C:181
Box< Patch, Real > * registerDHdrPrefixPickup(Compute *cid)
Definition: Patch.C:217
int doVirial
Definition: PatchTypes.h:21
static const LJTable * ljTable
Box< Patch, CompAtom > * velocityBox
BigReal pairlistTolerance
Definition: PatchTypes.h:41
void unregisterVelocityPickup(Compute *cid, Box< Patch, CompAtom > **const box)
Definition: Patch.C:153
int doGBIS
Definition: PatchTypes.h:29
Pairlists gbisStepPairlists[numGBISPairlists]
void submit(void)
Definition: ReductionMgr.h:324
Force * fullf[2]
int maxForceMerged
Definition: PatchTypes.h:33
BigReal * pressureProfileReduction
Data * open(void)
Definition: Box.h:39
int32 PatchID
Definition: NamdTypes.h:277
static const int numGBISPairlists
BigReal maxGroupRadius
Definition: PatchTypes.h:43
const ComputeID cid
Definition: Compute.h:43
NAMD_HOST_DEVICE Vector origin() const
Definition: Lattice.h:278
void unregisterDEdaSumDeposit(Compute *cid, Box< Patch, GBReal > **const box)
Definition: Patch.C:211
BigReal reductionData[reductionDataSize]
Box< Patch, CompAtom > * registerVelocityPickup(Compute *cid)
Definition: Patch.C:147
void close(Data **const t)
Definition: Box.h:49
int doMolly
Definition: PatchTypes.h:24
ComputeNonbondedWorkArrays * workArrays
static void(* calcMergeSelf)(nonbonded *)
double BigReal
Definition: common.h:123
int step
Definition: PatchTypes.h:16
static void(* calcFullSelfEnergy)(nonbonded *)