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 ( patch->flags.doFullDispersion ) {
297  if ( doEnergy ) calcMergeDispSelfEnergy(&params);
298  else calcMergeDispSelf(&params);
299  } else {
300  if ( doEnergy ) calcMergeSelfEnergy(&params);
301  else calcMergeSelf(&params);
302  }
303  } else {
304  if ( patch->flags.doFullDispersion ) {
305  if ( doEnergy ) calcFullDispSelfEnergy(&params);
306  else calcFullDispSelf(&params);
307  } else {
308  if ( doEnergy ) calcFullSelfEnergy(&params);
309  else calcFullSelf(&params);
310  }
311  }
312  } else {
313  if ( patch->flags.doFullDispersion ) {
314  if ( doEnergy ) calcDispSelfEnergy(&params);
315  else calcDispSelf(&params);
316  } else {
317  if ( doEnergy ) calcSelfEnergy(&params);
318  else calcSelf(&params);
319  }
320  }//end force calculation calls
321  }//end if atoms
322 
323  // BEGIN LA
324  if (params.doLoweAndersen) {
325  DebugM(4, "closing velocity box\n");
326  velocityBox->close(&v);
327  }
328  // END LA
329  }//end if not gbis
330 
331 /*******************************************************************************
332  * gbis Loop
333 *******************************************************************************/
334 if (patch->flags.doGBIS) {
338  gbisParams.numPatches = 1;//self
341  gbisParams.epsilon_s = simParams->solvent_dielectric;
342  gbisParams.epsilon_p = simParams->dielectric;
343  gbisParams.rho_0 = simParams->coulomb_radius_offset;
344  gbisParams.kappa = simParams->kappa;
345  gbisParams.cutoff = simParams->cutoff;
346  gbisParams.doSmoothing = simParams->switchingActive;
347  gbisParams.a_cut = simParams->alpha_cutoff;
348  gbisParams.delta = simParams->gbis_delta;
349  gbisParams.beta = simParams->gbis_beta;
350  gbisParams.gamma = simParams->gbis_gamma;
351  gbisParams.alpha_max = simParams->alpha_max;
352  gbisParams.cid = cid;
356  gbisParams.doEnergy = doEnergy;
357  gbisParams.fsMax = simParams->fsMax;
358  for (int i = 0; i < numGBISPairlists; i++)
360 
361  //open boxes
362  if (gbisPhase == 1) {
369  } else if (gbisPhase == 2) {
374  } else if (gbisPhase == 3) {
377  }
378 
379  //make call to calculate GBIS
382  }
383 
384  //close boxes
385  if (gbisPhase == 1) {
387  } else if (gbisPhase == 2) {
389  } else if (gbisPhase == 3) {
395  }
396 }// end if doGBIS
397 
398 /*******************************************************************************
399  * Reduction
400 *******************************************************************************/
401  if (!patch->flags.doGBIS || gbisPhase == 3) {
403  if (pressureProfileOn)
405 
406 
407 #ifdef TRACE_COMPUTE_OBJECTS
408  traceUserBracketEvent(TRACE_COMPOBJ_IDOFFSET+cid, traceObjStartTime, CmiWallTimer());
409 #endif
410 
411  reduction->submit();
412  if (pressureProfileOn)
414  }// end not gbis
415 }
416 
417 #ifdef NAMD_AVXTILES
418 void ComputeNonbondedSelf::doForceTiles(CompAtom* p, CompAtomExt* pExt,
419  Results* r)
420 {
421  const int doEnergy = patch->flags.doEnergy;
422  const int doVirial = patch->flags.doVirial;
423  const int doFull = patch->flags.doFullElectrostatics;
424 
425 #ifdef TRACE_COMPUTE_OBJECTS
426  double traceObjStartTime = CmiWallTimer();
427 #endif
428 
429  DebugM(2,"doForceTiles() called.\n");
430  DebugM(1,numAtoms << " patch 1 atoms\n");
431  DebugM(3, "NUMATOMSxNUMATOMS = " << numAtoms*numAtoms << "\n");
432 
433  const Lattice &lattice = patch->lattice;
434  for ( int i = 0; i < reductionDataSize; ++i ) reductionData[i] = 0;
435 
436  plint maxa = (plint)(-1);
437  if ( numAtoms > maxa ) {
438  char estr[1024];
439  sprintf(estr,"patch has %d atoms, maximum allowed is %d",numAtoms,maxa);
440  NAMD_die(estr);
441  }
442 
443  int doList = false;
444  if ( patch->flags.savePairlists ) {
445  doList = 1;
446  pairlistsValid = 1;
448  } else if ( patch->flags.usePairlists ) {
449  if (!pairlistsValid ||
452  pairlistsValid = 0;
453  doList = 1;
454  }
455  } else
456  doList = 1;
457 
458  if (doList) {
459  double plcutoff = cutoff;
461  plcutoff += patch->flags.pairlistTolerance * 2.0;
462  tileLists.updateBuildInfo(patch->flags.step, minPart, maxPart,
463  numParts, plcutoff);
464  }
465 
466  Vector offset(0., 0., 0.);
467  tileLists.updateParams(lattice, offset, cutoff);
468 
469  tileLists.nbForceAVX512(doEnergy, doVirial, doFull, doList);
470 
471  reductionData[exclChecksumIndex] = tileLists.exclusionChecksum();
472  if (doEnergy) {
473  reductionData[vdwEnergyIndex] = tileLists.energyVdw();
474  reductionData[electEnergyIndex] = tileLists.energyElec();
475  if (doFull)
476  reductionData[fullElectEnergyIndex] = tileLists.energySlow();
477  }
478  if (doVirial) {
479  reductionData[virialIndex_XX] = tileLists.virialXX();
480  reductionData[virialIndex_XY] = tileLists.virialXY();
481  reductionData[virialIndex_XZ] = tileLists.virialXZ();
482  reductionData[virialIndex_YX] = tileLists.virialXY();
483  reductionData[virialIndex_YY] = tileLists.virialYY();
484  reductionData[virialIndex_YZ] = tileLists.virialYZ();
485  reductionData[virialIndex_ZX] = tileLists.virialXZ();
486  reductionData[virialIndex_ZY] = tileLists.virialYZ();
487  reductionData[virialIndex_ZZ] = tileLists.virialZZ();
488  if (doFull) {
489  reductionData[fullElectVirialIndex_XX] = tileLists.virialSlowXX();
490  reductionData[fullElectVirialIndex_XY] = tileLists.virialSlowXY();
491  reductionData[fullElectVirialIndex_XZ] = tileLists.virialSlowXZ();
492  reductionData[fullElectVirialIndex_YX] = tileLists.virialSlowXY();
493  reductionData[fullElectVirialIndex_YY] = tileLists.virialSlowYY();
494  reductionData[fullElectVirialIndex_YZ] = tileLists.virialSlowYZ();
495  reductionData[fullElectVirialIndex_ZX] = tileLists.virialSlowXZ();
496  reductionData[fullElectVirialIndex_ZY] = tileLists.virialSlowYZ();
497  reductionData[fullElectVirialIndex_ZZ] = tileLists.virialSlowZZ();
498  }
499  }
500 
501  if (!patch->flags.doGBIS || gbisPhase == 3) {
503 
504 #ifdef TRACE_COMPUTE_OBJECTS
505  traceUserBracketEvent(TRACE_COMPOBJ_IDOFFSET+cid, traceObjStartTime,
506  CmiWallTimer());
507 #endif
508 
509  reduction->submit();
510  } // end not gbis
511 }
512 #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
static void(* calcMergeDispSelfEnergy)(nonbonded *)
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:288
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
virtual void submit(void)=0
SimParameters * simParameters
Definition: Node.h:181
Box< Patch, Results > * forceBox
Definition: ComputePatch.h:51
int savePairlists
Definition: PatchTypes.h:41
BigReal & item(int i)
Definition: ReductionMgr.h:336
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:40
BigReal * reduction
static void submitPressureProfileData(BigReal *, SubmitReduction *)
static BigReal pressureProfileThickness
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:368
Box< Patch, Real > * registerBornRadPickup(Compute *cid)
Definition: Patch.C:195
LDObjHandle ldObjHandle
Definition: Compute.h:44
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:290
static void(* calcFullDispSelfEnergy)(nonbonded *)
int doLoweAndersen
Definition: PatchTypes.h:28
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:150
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(* calcDispSelfEnergy)(nonbonded *)
static void(* calcFullSelf)(nonbonded *)
int doNonbonded
Definition: PatchTypes.h:22
void NAMD_die(const char *err_msg)
Definition: common.C:148
static LdbCoordinator * Object()
static void(* calcSlowSelf)(nonbonded *)
static void(* calcMergeDispSelf)(nonbonded *)
BigReal maxAtomMovement
Definition: PatchTypes.h:43
static void(* calcDispSelf)(nonbonded *)
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:131
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:42
void unregisterVelocityPickup(Compute *cid, Box< Patch, CompAtom > **const box)
Definition: Patch.C:153
int doGBIS
Definition: PatchTypes.h:30
int doFullDispersion
Definition: PatchTypes.h:24
Pairlists gbisStepPairlists[numGBISPairlists]
Force * fullf[2]
int maxForceMerged
Definition: PatchTypes.h:34
BigReal * pressureProfileReduction
static void(* calcFullDispSelf)(nonbonded *)
Data * open(void)
Definition: Box.h:39
int32 PatchID
Definition: NamdTypes.h:287
static const int numGBISPairlists
BigReal maxGroupRadius
Definition: PatchTypes.h:44
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:25
ComputeNonbondedWorkArrays * workArrays
static void(* calcMergeSelf)(nonbonded *)
double BigReal
Definition: common.h:123
int step
Definition: PatchTypes.h:16
static void(* calcFullSelfEnergy)(nonbonded *)