NAMD
ComputeNonbondedUtil.h
Go to the documentation of this file.
1 
7 /*
8  Common operations for ComputeNonbonded classes
9 */
10 
11 #ifndef COMPUTENONBONDEDUTIL_H
12 #define COMPUTENONBONDEDUTIL_H
13 
14 #include "NamdTypes.h"
15 #include "ReductionMgr.h"
16 #include "Molecule.h"
17 
18 class LJTable;
19 class Molecule;
20 class Random;
21 
22 #ifdef NAMD_CUDA
24 void register_cuda_compute_pair(ComputeID c, PatchID pid[], int t[]);
26 #endif
27 #ifdef NAMD_MIC
28 void register_mic_compute_self(ComputeID c, PatchID pid, int part, int numParts);
29 void register_mic_compute_pair(ComputeID c, PatchID pid[], int t[], int part, int numParts);
30 void unregister_mic_compute(ComputeID c);
31 #endif
32 
33 typedef unsigned short plint;
34 
35 class Pairlists {
36  enum {initsize = 10};
37  plint *data;
38  int curpos;
39  int size;
40  Pairlists(const Pairlists&) { ; }
41  Pairlists& operator=(const Pairlists&) { return *this; }
42 public:
43  Pairlists() : size(initsize) { data = new plint[initsize]; }
44  ~Pairlists() { delete [] data; }
45  plint *newlist(int max_size) { // get a new list w/ room for max_size
46  int reqnewsize = curpos + max_size + 1;
47  int newsize = size;
48  while ( newsize < reqnewsize ) { newsize += newsize >> 1; }
49  if ( newsize > size ) {
50  plint *newdata = new plint[newsize];
51  CmiMemcpy(newdata,data,curpos*sizeof(plint));
52  delete [] data;
53  data = newdata;
54  size = newsize;
55  }
56  return &data[curpos+1];
57  }
58 
59  // don't specify size if previous allocation should have extra space
60  plint *newlist() { // get a new list assuming already allocated
61  return &data[curpos+1];
62  }
63 
64  void newsize(int list_size) { // set the size of the last list gotten
65  data[curpos] = list_size;
66  curpos += list_size + 1;
67  }
68  void reset() { curpos = 0; } // go back to the beginning
69  void nextlist(plint **list, int *list_size) { // get next list and size
70  *list = &data[curpos+1];
71  curpos += ( *list_size = data[curpos] ) + 1;
72  }
73  int getSize() { return size; }
74 
75  void addIndex() { // assume space for index already allocated
76  curpos++;
77  }
78  void setIndexValue(plint i) { // assume no newsize since addIndex
79  data[curpos-1] = i;
80  }
81 
83  return data[curpos++];
84  }
85 
86 };
87 
88 #define NBWORKARRAYSINIT(ARRAYS) \
89  ComputeNonbondedWorkArrays* const computeNonbondedWorkArrays = ARRAYS;
90 
91 #ifdef __INTEL_COMPILER
92 #define NBWORKARRAY(TYPE,NAME,SIZE) \
93  computeNonbondedWorkArrays->NAME.resize(SIZE); \
94  TYPE * const NAME = computeNonbondedWorkArrays->NAME.begin(); \
95  __assume_aligned(NAME,64);
96 #else
97 #define NBWORKARRAY(TYPE,NAME,SIZE) \
98  computeNonbondedWorkArrays->NAME.resize(SIZE); \
99  TYPE * const NAME = computeNonbondedWorkArrays->NAME.begin();
100 #endif
101 
103 public:
106 #ifdef NAMD_KNL
107  ResizeArray<float> r2list_f;
108  ResizeArray<float> xlist;
109  ResizeArray<float> ylist;
110  ResizeArray<float> zlist;
111 #endif
112 
113  // DMK - Atom Sort
114  // NOTE : TODO : For pair nonbonded compute objects, these arrays are needed
115  // for the atom sorting code. However, grouplist and fixglist will not be
116  // used if these arrays are so they could overlap in memory. TODO: Find a
117  // way to allow them to use the same memory. For now, it's not much memory
118  // so just keep them separate because of the type differences. I haven't
119  // looked through all the details yet, but could probably just use the
120  // larger type and cast the pointer type as needed for the other one to
121  // ensure there is enough memory in both cases.
122  #if NAMD_ComputeNonbonded_SortAtoms != 0
126  #endif
127 
133 
134  // n = normal, x = excluded, m = modified
135  // A[1-4] = alchemical partition 1-4
150 
155 };
156 
157 //struct sent to CalcGBIS
159  int cid;
160  int patchID[2];
161  int sequence;
163  int doGBIS;
185  int doEnergy;
188 };
189 
190 // function arguments
191 struct nonbonded {
192  CompAtom* p[2];
193 #ifdef NAMD_KNL
194  CompAtomFlt *pFlt[2];
195 #endif
197  // BEGIN LA
198  CompAtom* v[2];
199  // END LA
200  Force* ff[2];
201  // for full electrostatics
202  Force* fullf [2];
203 
204  int numAtoms[2];
205 
208 
209  // DMK - Atom Separation (water vs. non-water)
210  #if NAMD_SeparateWaters != 0
211  int numWaterAtoms[2];
212  #endif
213 
216 
220 
222 
228 
229  // BEGIN LA
231  // END LA
232 
233  int minPart;
234  int maxPart;
235  int numParts;
236  int step;
237 
238  #if NAMD_ComputeNonbonded_SortAtoms != 0
240  #endif
241 };
242 
244 
245 public:
246 
249  static void select(void);
250 
251  static void (*calcPair)(nonbonded *);
253  static void (*calcSelf)(nonbonded *);
255 
260 
265 
270 
271  // Below modified by JLai -- Look at bottom 3rd line
275 //sd-db
279 //sd-de
280  TENSOR(virialIndex), TENSOR(fullElectVirialIndex),
281  VECTOR(pairVDWForceIndex), VECTOR(pairElectForceIndex),
285 
286  static Bool commOnly;
288  static Bool qmForcesOn ;
289  static BigReal cutoff;
290  static BigReal cutoff2;
291  static float cutoff2_f;
293  static const LJTable* ljTable;
294  static const Molecule* mol;
296  static int rowsize;
297  static int columnsize;
298  static int r2_delta_exp;
310  static BigReal *r2_table;
311  static int table_length;
312  #if defined(NAMD_MIC)
313  static BigReal *mic_table_base_ptr; // DMK - NOTE : Duplicate but, use so that nothing breaks if the ordering of sub-arrays changes
314  static int mic_table_n;
315  static int mic_table_n_16;
316  #endif
317 
318  #ifdef NAMD_AVXTILES
319  // 0 - Tiles mode disabled
320  // 1 - C1 switching, arithmetic LJ w/ no user specified mix values
321  // 2 - C1 switching with LJTable lookup for parameters
322  // 3 - Interpolation supporting any switch options (including none)
323  static int avxTilesMode;
324  // Additional tiles data structures for explicit LJ mixing in force calc
325  static float *avx_tiles_eps4_sigma;
326  static float *avx_tiles_eps4_sigma_14;
327  #endif
328 
329  #if defined(NAMD_KNL) || defined(NAMD_AVXTILES)
330  // Table interpolation is truncated at 1/r > KNL_TABLE_MAX_R_1
331  // KNL_TABLE_MAX_R_1 must be at least 1.f
332  // KNL_TABLE_FACTOR = floor(KNL_TABLE_SIZE / KNL_TABLE_MAX_R_1)
333  // Sanity checks for preprocessor defines are in ComputeNonbondedUtil.C
334  // For Tiles build, increase KNL_TABLE_MAX_R_1 for excluded/modified
335  #define KNL_TABLE_SIZE (4693+2)
336  #define KNL_TABLE_MAX_R_1 1.15f
337  #define KNL_TABLE_FACTOR (4080+2)
338  static float *knl_table_alloc;
339  static float *knl_fast_ener_table;
340  static float *knl_fast_grad_table;
341  static float *knl_scor_ener_table;
342  static float *knl_scor_grad_table;
343  static float *knl_slow_ener_table;
344  static float *knl_slow_grad_table;
345  static float *knl_excl_ener_table;
346  static float *knl_excl_grad_table;
347  #ifdef NAMD_KNL
348  static float *knl_corr_ener_table;
349  static float *knl_corr_grad_table;
350  #endif
351  #endif
352  static BigReal scaling;
353  static BigReal scale14;
357  static BigReal v_vdwa;
358  static BigReal v_vdwb;
359  static BigReal k_vdwa;
360  static BigReal k_vdwb;
363  static float v_vdwa_f;
364  static float v_vdwb_f;
365  static float k_vdwa_f;
366  static float k_vdwb_f;
367  static float cutoff_3_f;
368  static float cutoff_6_f;
369  static float switchOn_f;
370  static float A6_f;
371  static float B6_f;
372  static float C6_f;
373  static float A12_f;
374  static float B12_f;
375  static float C12_f;
376  static BigReal c0;
377  static BigReal c1;
378  static BigReal c3;
379  static BigReal c5;
380  static BigReal c6;
381  static BigReal c7;
382  static BigReal c8;
383  // static BigReal d0;
384 //sd-db
385  static Bool alchFepOn;
387  static Bool alchWCAOn;
391 //sd-de
392  static Bool lesOn;
393  static int lesFactor;
395 
397 
400 
406 
407  static Bool accelMDOn;
408 
410 
411  // for particle mesh Ewald
414 
415  // need macros for preprocessor
416  #define VDW_SWITCH_MODE_ENERGY 0
417  #define VDW_SWITCH_MODE_MARTINI 1
418  #define VDW_SWITCH_MODE_FORCE 2
419  static int vdw_switch_mode;
420 
421  // Ported by JLai -- JE - Go
422  static Bool goGroPair;
423  static Bool goForcesOn;
424  static int goMethod; //6.3.11
425  // End of port -- JL
426 
427  // for simplifying some common functions
428  inline static BigReal square( const BigReal &x,
429  const BigReal &y,
430  const BigReal &z)
431  {
432  return(x*x+y*y+z*z);
433  }
434 
435  static void calc_error(nonbonded *);
436 
437  static void calc_pair(nonbonded *);
438  static void calc_pair_energy(nonbonded *);
439  static void calc_pair_fullelect(nonbonded *);
440  static void calc_pair_energy_fullelect(nonbonded *);
441  static void calc_pair_merge_fullelect(nonbonded *);
443  static void calc_pair_slow_fullelect(nonbonded *);
445 
446  static void calc_self(nonbonded *);
447  static void calc_self_energy(nonbonded *);
448  static void calc_self_fullelect(nonbonded *);
449  static void calc_self_energy_fullelect(nonbonded *);
450  static void calc_self_merge_fullelect(nonbonded *);
452  static void calc_self_slow_fullelect(nonbonded *);
454 
455 //alchemical fep calcualtion
456  static void calc_pair_energy_fep(nonbonded *);
460  static void calc_self_energy_fep (nonbonded *);
464 
465  static void calc_pair_energy_ti(nonbonded *);
466  static void calc_pair_ti(nonbonded *);
468  static void calc_pair_fullelect_ti (nonbonded *);
470  static void calc_pair_merge_fullelect_ti (nonbonded *);
472  static void calc_pair_slow_fullelect_ti (nonbonded *);
473  static void calc_self_energy_ti (nonbonded *);
474  static void calc_self_ti (nonbonded *);
476  static void calc_self_fullelect_ti (nonbonded *);
478  static void calc_self_merge_fullelect_ti (nonbonded *);
480  static void calc_self_slow_fullelect_ti (nonbonded *);
481 
482 //locally enhanced sampling calcualtion
483  static void calc_pair_les(nonbonded *);
484  static void calc_pair_energy_les(nonbonded *);
485  static void calc_pair_fullelect_les (nonbonded *);
489  static void calc_pair_slow_fullelect_les (nonbonded *);
491  static void calc_self_les (nonbonded *);
492  static void calc_self_energy_les (nonbonded *);
493  static void calc_self_fullelect_les (nonbonded *);
497  static void calc_self_slow_fullelect_les (nonbonded *);
499 
500 //pair interaction calcualtion
501  static void calc_pair_energy_int(nonbonded *);
504  static void calc_self_energy_int (nonbonded *);
507 
508 //pressure profile calcualtion
509  static void calc_pair_pprof(nonbonded *);
510  static void calc_pair_energy_pprof(nonbonded *);
511  static void calc_pair_fullelect_pprof(nonbonded *);
517  static void calc_self_pprof(nonbonded *);
518  static void calc_self_energy_pprof(nonbonded *);
519  static void calc_self_fullelect_pprof (nonbonded *);
525 
526  //tabulated potential nonbonded calcs
527  static void calc_pair_tabener(nonbonded *);
528  static void calc_pair_energy_tabener(nonbonded *);
529  static void calc_pair_fullelect_tabener(nonbonded *);
535  static void calc_self_tabener(nonbonded *);
536  static void calc_self_energy_tabener(nonbonded *);
537  static void calc_self_fullelect_tabener (nonbonded *);
543 
544  //Go forces nonbonded calcs
545  static void calc_pair_go(nonbonded *);
546  static void calc_pair_energy_go(nonbonded *);
547  static void calc_pair_fullelect_go(nonbonded *);
551  static void calc_pair_slow_fullelect_go(nonbonded *);
553  static void calc_self_go(nonbonded *);
554  static void calc_self_energy_go(nonbonded *);
555  static void calc_self_fullelect_go(nonbonded *);
559  static void calc_self_slow_fullelect_go(nonbonded *);
561 
562  void calcGBIS(nonbonded *params, GBISParamStruct *gbisParams);
563 };
564 
565 #endif
566 
ResizeArray< plint > pairlistmA3
ResizeArray< BigReal > p_0_sortValues
Pairlists * pairlists
static void calc_pair_fullelect_pprof(nonbonded *)
static BigReal * fast_table
static void calc_pair_energy_merge_fullelect_tabener(nonbonded *)
static void calc_self_energy_go(nonbonded *)
static void calc_self_energy_merge_fullelect_ti(nonbonded *)
static BigReal * scor_table
static void calc_pair_les(nonbonded *)
static void calc_self_energy_slow_fullelect_fep(nonbonded *)
static void calc_pair_merge_fullelect(nonbonded *)
static void calc_self_energy_merge_fullelect_int(nonbonded *)
static void calc_self_energy_slow_fullelect(nonbonded *)
ResizeArray< SortEntry > atomSort_0_sortValues__
void unregister_cuda_compute(ComputeID c)
static void calc_self_energy_merge_fullelect_tabener(nonbonded *)
static void calc_self_energy_slow_fullelect_ti(nonbonded *)
static void calc_self_energy_fullelect_int(nonbonded *)
static void submitReductionData(BigReal *, SubmitReduction *)
Parameters * parameters
static void calc_self_ti(nonbonded *)
static void calc_self_fullelect_pprof(nonbonded *)
int ComputeID
Definition: NamdTypes.h:183
static void calc_self_tabener(nonbonded *)
static void calc_self_energy_fullelect(nonbonded *)
static void calc_pair_slow_fullelect_ti(nonbonded *)
static void(* calcSelf)(nonbonded *)
static __global__ void(const patch_pair *patch_pairs, const atom *atoms, const atom_param *atom_params, const int *vdw_types, unsigned int *plist, float4 *tmpforces, float4 *slow_tmpforces, float4 *forces, float4 *slow_forces, float *tmpvirials, float *slow_tmpvirials, float *virials, float *slow_virials, unsigned int *global_counters, int *force_ready_queue, const unsigned int *overflow_exclusions, const int npatches, const int block_begin, const int total_block_count, int *block_order, exclmask *exclmasks, const int lj_table_size, const float3 lata, const float3 latb, const float3 latc, const float cutoff2, const float plcutoff2, const int doSlow)
static void calc_pair_merge_fullelect_tabener(nonbonded *)
static BigReal square(const BigReal &x, const BigReal &y, const BigReal &z)
ResizeArray< plint > pairlistnA3
CompAtom * p[2]
static void calc_self_les(nonbonded *)
void calcGBIS(nonbonded *params, GBISParamStruct *gbisParams)
Definition: ComputeGBIS.C:261
Definition: Vector.h:64
static void calc_pair_merge_fullelect_go(nonbonded *)
static void calc_pair_slow_fullelect_pprof(nonbonded *)
static void calc_pair_energy_merge_fullelect(nonbonded *)
static const Molecule * mol
static void calc_pair_energy_fullelect_fep(nonbonded *)
static void calc_self_energy_fullelect_pprof(nonbonded *)
float Real
Definition: common.h:109
static void calc_self_energy_fullelect_les(nonbonded *)
static void calc_self_energy_fullelect_ti(nonbonded *)
CompAtom * v[2]
static void calc_self_fullelect(nonbonded *)
static void calc_self_energy_ti(nonbonded *)
static BigReal * vdwa_table
static void calc_self_energy_int(nonbonded *)
BigReal * reduction
static void submitPressureProfileData(BigReal *, SubmitReduction *)
static BigReal pressureProfileThickness
static void calc_pair_slow_fullelect(nonbonded *)
static void calc_pair(nonbonded *)
static void calc_self_go(nonbonded *)
static void(* calcMergePair)(nonbonded *)
static void calc_pair_energy_tabener(nonbonded *)
static void calc_self_slow_fullelect_pprof(nonbonded *)
static void calc_pair_energy_slow_fullelect_go(nonbonded *)
static void calc_self_energy_merge_fullelect_fep(nonbonded *)
ResizeArray< plint > pairlistxA2
static void(* calcMergePairEnergy)(nonbonded *)
static void calc_pair_energy_go(nonbonded *)
static void calc_pair_merge_fullelect_ti(nonbonded *)
SimParameters * simParameters
static BigReal * full_table
static void calc_pair_merge_fullelect_les(nonbonded *)
ResizeArray< plint > pairlistnA1
static void calc_pair_slow_fullelect_go(nonbonded *)
static void calc_pair_energy_merge_fullelect_fep(nonbonded *)
static void(* calcSlowPairEnergy)(nonbonded *)
void register_cuda_compute_self(ComputeID c, PatchID pid)
ResizeArray< plint > pairlistm
ResizeArray< plint > pairlistnA0
ResizeArray< plint > pairlistxA1
static void(* calcPair)(nonbonded *)
static void(* calcSlowPair)(nonbonded *)
ResizeArray< BigReal > r2list
static void calc_pair_energy_fullelect_go(nonbonded *)
ResizeArray< plint > pairlistxA4
unsigned short plint
static void calc_pair_energy_slow_fullelect_tabener(nonbonded *)
Definition: Random.h:37
plint getIndexValue()
void nextlist(plint **list, int *list_size)
static void calc_self_slow_fullelect(nonbonded *)
static void calc_self_energy_les(nonbonded *)
static void calc_pair_energy_fep(nonbonded *)
static void(* calcMergeSelfEnergy)(nonbonded *)
static void calc_pair_tabener(nonbonded *)
ResizeArray< plint > pairlistxA3
static void calc_pair_energy_pprof(nonbonded *)
static BigReal * table_noshort
Pairlists * gbisStepPairlists[4]
static void calc_self_energy_slow_fullelect_tabener(nonbonded *)
static void calc_self_energy_fullelect_tabener(nonbonded *)
static void calc_pair_energy_int(nonbonded *)
static BigReal pressureProfileMin
ResizeArray< plint > pairlistmA2
static void calc_self_slow_fullelect_tabener(nonbonded *)
static void calc_pair_energy_slow_fullelect_les(nonbonded *)
static void calc_pair_energy_ti(nonbonded *)
static void calc_pair_energy_slow_fullelect_fep(nonbonded *)
static void calc_self_slow_fullelect_ti(nonbonded *)
static void calc_pair_slow_fullelect_les(nonbonded *)
ResizeArray< plint > pairlistx
static void calc_pair_fullelect_ti(nonbonded *)
static void calc_pair_energy(nonbonded *)
static BigReal * table_ener
gridSize z
int Bool
Definition: common.h:133
static void calc_pair_pprof(nonbonded *)
static void calc_pair_energy_fullelect_ti(nonbonded *)
static void calc_self_energy_merge_fullelect_les(nonbonded *)
static void calc_self_slow_fullelect_go(nonbonded *)
static void calc_pair_energy_merge_fullelect_go(nonbonded *)
CompAtomExt * pExt[2]
static void calc_error(nonbonded *)
ResizeArray< plint > pairlistnAlch
static void calc_self_energy_fullelect_go(nonbonded *)
int PatchID
Definition: NamdTypes.h:182
static void calc_self_fullelect_tabener(nonbonded *)
static void(* calcFullSelf)(nonbonded *)
ResizeArray< plint > pairlistnA2
static void calc_self_merge_fullelect_ti(nonbonded *)
static void(* calcSlowSelf)(nonbonded *)
static void calc_self_fullelect_les(nonbonded *)
static void calc_self_merge_fullelect_go(nonbonded *)
plint * newlist()
static void calc_self_energy_merge_fullelect_go(nonbonded *)
static void calc_self_energy_merge_fullelect(nonbonded *)
static void select(void)
static void calc_pair_energy_fullelect_int(nonbonded *)
static void calc_pair_energy_merge_fullelect_pprof(nonbonded *)
static BigReal * lambda_table
static void calc_self_energy_fep(nonbonded *)
static void(* calcSlowSelfEnergy)(nonbonded *)
ResizeArray< SortEntry > atomSort_1_sortValues__
static void calc_pair_energy_slow_fullelect_pprof(nonbonded *)
static BigReal * slow_table
static void(* calcSelfEnergy)(nonbonded *)
static void(* calcPairEnergy)(nonbonded *)
static void calc_pair_fullelect_les(nonbonded *)
static void calc_pair_energy_les(nonbonded *)
ResizeArray< plint > pairlistmA1
static void calc_self_merge_fullelect(nonbonded *)
static void calc_self_energy_tabener(nonbonded *)
static void calc_pair_energy_merge_fullelect_int(nonbonded *)
static void calc_self_energy_slow_fullelect_pprof(nonbonded *)
static void calc_self_energy_pprof(nonbonded *)
ResizeArray< plint > pairlistnA4
static void calc_pair_energy_fullelect_pprof(nonbonded *)
static void calc_pair_fullelect_go(nonbonded *)
static void calc_pair_energy_slow_fullelect(nonbonded *)
static void calc_pair_energy_fullelect_les(nonbonded *)
static BigReal * vdwb_table
static void calc_pair_energy_fullelect_tabener(nonbonded *)
static void(* calcFullPair)(nonbonded *)
static void calc_pair_merge_fullelect_pprof(nonbonded *)
static const LJTable * ljTable
static void calc_self_energy_merge_fullelect_pprof(nonbonded *)
ResizeArray< plint > pairlistmA4
static void(* calcFullPairEnergy)(nonbonded *)
void newsize(int list_size)
static BigReal * corr_table
static BigReal * table_short
void setIndexValue(plint i)
gridSize y
static void calc_self(nonbonded *)
static void calc_self_fullelect_ti(nonbonded *)
static void calc_pair_fullelect_tabener(nonbonded *)
static void calc_pair_energy_merge_fullelect_ti(nonbonded *)
static BigReal * table_alloc
Force * fullf[2]
static void calc_self_energy_fullelect_fep(nonbonded *)
static void calc_self_merge_fullelect_tabener(nonbonded *)
static BigReal alchVdwShiftCoeff
static void calc_pair_go(nonbonded *)
gridSize x
BigReal * pressureProfileReduction
plint * newlist(int max_size)
static void calc_pair_ti(nonbonded *)
static void calc_self_energy(nonbonded *)
static void calc_self_fullelect_go(nonbonded *)
static void calc_pair_energy_merge_fullelect_les(nonbonded *)
static void calc_self_pprof(nonbonded *)
static void calc_self_merge_fullelect_les(nonbonded *)
static void calc_pair_slow_fullelect_tabener(nonbonded *)
static void calc_pair_energy_fullelect(nonbonded *)
static void calc_self_merge_fullelect_pprof(nonbonded *)
static void calc_self_energy_slow_fullelect_go(nonbonded *)
static void calc_pair_energy_slow_fullelect_ti(nonbonded *)
ComputeNonbondedWorkArrays * workArrays
static void(* calcMergeSelf)(nonbonded *)
static void calc_self_energy_slow_fullelect_les(nonbonded *)
double BigReal
Definition: common.h:114
static void(* calcFullSelfEnergy)(nonbonded *)
float GBReal
Definition: ComputeGBIS.inl:17
static void calc_pair_fullelect(nonbonded *)
static void calc_self_slow_fullelect_les(nonbonded *)
void register_cuda_compute_pair(ComputeID c, PatchID pid[], int t[])