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 ( doEnergy ) calcFullSelfEnergy(&params);
305  else calcFullSelf(&params);
306  }
307  }
308  else
309  if ( doEnergy ) calcSelfEnergy(&params);
310  else calcSelf(&params);
311  }//end if atoms
312 
313  // BEGIN LA
314  if (params.doLoweAndersen) {
315  DebugM(4, "closing velocity box\n");
316  velocityBox->close(&v);
317  }
318  // END LA
319  }//end if not gbis
320 
321 /*******************************************************************************
322  * gbis Loop
323 *******************************************************************************/
324 if (patch->flags.doGBIS) {
328  gbisParams.numPatches = 1;//self
331  gbisParams.epsilon_s = simParams->solvent_dielectric;
332  gbisParams.epsilon_p = simParams->dielectric;
333  gbisParams.rho_0 = simParams->coulomb_radius_offset;
334  gbisParams.kappa = simParams->kappa;
335  gbisParams.cutoff = simParams->cutoff;
336  gbisParams.doSmoothing = simParams->switchingActive;
337  gbisParams.a_cut = simParams->alpha_cutoff;
338  gbisParams.delta = simParams->gbis_delta;
339  gbisParams.beta = simParams->gbis_beta;
340  gbisParams.gamma = simParams->gbis_gamma;
341  gbisParams.alpha_max = simParams->alpha_max;
342  gbisParams.cid = cid;
346  gbisParams.doEnergy = doEnergy;
347  gbisParams.fsMax = simParams->fsMax;
348  for (int i = 0; i < numGBISPairlists; i++)
350 
351  //open boxes
352  if (gbisPhase == 1) {
359  } else if (gbisPhase == 2) {
364  } else if (gbisPhase == 3) {
367  }
368 
369  //make call to calculate GBIS
372  }
373 
374  //close boxes
375  if (gbisPhase == 1) {
377  } else if (gbisPhase == 2) {
379  } else if (gbisPhase == 3) {
385  }
386 }// end if doGBIS
387 
388 /*******************************************************************************
389  * Reduction
390 *******************************************************************************/
391  if (!patch->flags.doGBIS || gbisPhase == 3) {
393  if (pressureProfileOn)
395 
396 
397 #ifdef TRACE_COMPUTE_OBJECTS
398  traceUserBracketEvent(TRACE_COMPOBJ_IDOFFSET+cid, traceObjStartTime, CmiWallTimer());
399 #endif
400 
401  reduction->submit();
402  if (pressureProfileOn)
404  }// end not gbis
405 }
406 
407 #ifdef NAMD_AVXTILES
408 void ComputeNonbondedSelf::doForceTiles(CompAtom* p, CompAtomExt* pExt,
409  Results* r)
410 {
411  const int doEnergy = patch->flags.doEnergy;
412  const int doVirial = patch->flags.doVirial;
413  const int doFull = patch->flags.doFullElectrostatics;
414 
415 #ifdef TRACE_COMPUTE_OBJECTS
416  double traceObjStartTime = CmiWallTimer();
417 #endif
418 
419  DebugM(2,"doForceTiles() called.\n");
420  DebugM(1,numAtoms << " patch 1 atoms\n");
421  DebugM(3, "NUMATOMSxNUMATOMS = " << numAtoms*numAtoms << "\n");
422 
423  const Lattice &lattice = patch->lattice;
424  for ( int i = 0; i < reductionDataSize; ++i ) reductionData[i] = 0;
425 
426  plint maxa = (plint)(-1);
427  if ( numAtoms > maxa ) {
428  char estr[1024];
429  sprintf(estr,"patch has %d atoms, maximum allowed is %d",numAtoms,maxa);
430  NAMD_die(estr);
431  }
432 
433  int doList = false;
434  if ( patch->flags.savePairlists ) {
435  doList = 1;
436  pairlistsValid = 1;
438  } else if ( patch->flags.usePairlists ) {
439  if (!pairlistsValid ||
442  pairlistsValid = 0;
443  doList = 1;
444  }
445  } else
446  doList = 1;
447 
448  if (doList) {
449  double plcutoff = cutoff;
451  plcutoff += patch->flags.pairlistTolerance * 2.0;
452  tileLists.updateBuildInfo(patch->flags.step, minPart, maxPart,
453  numParts, plcutoff);
454  }
455 
456  Vector offset(0., 0., 0.);
457  tileLists.updateParams(lattice, offset, cutoff);
458 
459  tileLists.nbForceAVX512(doEnergy, doVirial, doFull, doList);
460 
461  reductionData[exclChecksumIndex] = tileLists.exclusionChecksum();
462  if (doEnergy) {
463  reductionData[vdwEnergyIndex] = tileLists.energyVdw();
464  reductionData[electEnergyIndex] = tileLists.energyElec();
465  if (doFull)
466  reductionData[fullElectEnergyIndex] = tileLists.energySlow();
467  }
468  if (doVirial) {
469  reductionData[virialIndex_XX] = tileLists.virialXX();
470  reductionData[virialIndex_XY] = tileLists.virialXY();
471  reductionData[virialIndex_XZ] = tileLists.virialXZ();
472  reductionData[virialIndex_YX] = tileLists.virialXY();
473  reductionData[virialIndex_YY] = tileLists.virialYY();
474  reductionData[virialIndex_YZ] = tileLists.virialYZ();
475  reductionData[virialIndex_ZX] = tileLists.virialXZ();
476  reductionData[virialIndex_ZY] = tileLists.virialYZ();
477  reductionData[virialIndex_ZZ] = tileLists.virialZZ();
478  if (doFull) {
479  reductionData[fullElectVirialIndex_XX] = tileLists.virialSlowXX();
480  reductionData[fullElectVirialIndex_XY] = tileLists.virialSlowXY();
481  reductionData[fullElectVirialIndex_XZ] = tileLists.virialSlowXZ();
482  reductionData[fullElectVirialIndex_YX] = tileLists.virialSlowXY();
483  reductionData[fullElectVirialIndex_YY] = tileLists.virialSlowYY();
484  reductionData[fullElectVirialIndex_YZ] = tileLists.virialSlowYZ();
485  reductionData[fullElectVirialIndex_ZX] = tileLists.virialSlowXZ();
486  reductionData[fullElectVirialIndex_ZY] = tileLists.virialSlowYZ();
487  reductionData[fullElectVirialIndex_ZZ] = tileLists.virialSlowZZ();
488  }
489  }
490 
491  if (!patch->flags.doGBIS || gbisPhase == 3) {
493 
494 #ifdef TRACE_COMPUTE_OBJECTS
495  traceUserBracketEvent(TRACE_COMPOBJ_IDOFFSET+cid, traceObjStartTime,
496  CmiWallTimer());
497 #endif
498 
499  reduction->submit();
500  } // end not gbis
501 }
502 #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
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(* 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 *)
static void(* calcMergeDispSelf)(nonbonded *)
BigReal maxAtomMovement
Definition: PatchTypes.h:43
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
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 *)