NAMD
NamdTypes.h
Go to the documentation of this file.
1 
7 #ifndef NAMDTYPES_H
8 
9 #define NAMDTYPES_H
10 
11 #ifdef NAMD_CUDA
12 #include <cuda_runtime.h> // Include vector types
13 #endif
14 #ifdef NAMD_HIP
15 #include <hip/hip_runtime.h>
16 #endif
17 
18 #include "common.h"
19 #include "Vector.h"
20 #include "CudaRecord.h"
21 #include "ResizeArray.h"
22 
23 class Patch;
24 class Compute;
25 
26 typedef Vector Position;
27 typedef Vector Velocity;
28 
29 //#ifdef ARCH_POWERPC
30 //typedef AlignVector Force;
31 //#else
32 typedef Vector Force;
33 //#endif
34 
35 typedef int32 AtomID;
36 typedef int32 AtomType;
37 typedef float Mass;
38 typedef float Charge;
39 
40 typedef double Coordinate;
41 
42 struct Transform
43 {
44  int8 i,j,k;
45  NAMD_HOST_DEVICE Transform(void) { i=0; j=0; k=0; }
46 
47 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
48  // Allows for implicit conversion from char3
50  : i(input.x), j(input.y), k(input.z) { ; }
51 
52  // Allows for implicit conversion to char3
53  NAMD_HOST_DEVICE operator char3() const {
54  char3 res;
55  res.x = i;
56  res.y = j;
57  res.z = k;
58  return res;
59  }
60 #endif
61 
62 };
63 
64 #ifndef USE_NO_BITFIELDS
65 
66 /*
67  * 1. "position" field in this structure is very important since it
68  * needs to be sent to every patch after every timestep.
69  * 2. Anything that is static (value is decided before computation)
70  * or only changes after atom migration should be put into the CompAtomExt structure
71  * 3. This data structure is 32-byte long which is particularly optimized for some machines
72  * (including BG/L) for better cache and message performance. Therefore, changes
73  * to this structure should be cautioned for the sake of performance.
74  */
75 
76 struct CompAtom {
88  uint8 hydrogenGroupSize : 4; // could be 3 if unsigned
89  uint8 isWater : 1; // 0 = particle is not in water, 1 = is in water
90 };
91 
92 #else
93 
94 /*
95  * Code below from Venkat, removing bitfields to avoid
96  * compilation bugs in the post-2016 Intel compilers.
97  */
98 
99 struct CompAtom {
101  Charge charge;
102  int16 vdwType;
112  uint8 isWater;// 0 = particle is not in water, 1 = is in water
113 
114 };
115 
116 #endif // USE_NO_BITFIELDS
117 
118 #ifdef NAMD_KNL
119 struct CompAtomFlt {
120  FloatVector position;
121  int32 vdwType;
122 };
123 #endif
124 
125 //CompAtomExt is now needed even in normal case
126 //for changing the packed msg type related to
127 //ProxyPatch into varsize msg type where
128 // two types of proxy msgs (originally, the msg
129 // for the step where atoms migrate (ProxyAllMsg),
130 // and the msg for normal steps (ProxyDataMsg))
131 // are declared as the same class (ProxyDataMsg).
132 // Note that in normal case, the class is needed
133 // just for passing the compilation, but not involved
134 // in the actual force calculation.
135 // --Chao Mei
136 
137 typedef int32 SigIndex;
138 typedef int32 AtomSigID;
139 typedef int32 ExclSigID;
140 
141 #ifndef USE_NO_BITFIELDS
142 
143 #define NAMD_ATOM_ID_MASK 0x3FFFFFFFu
144 #define NAMD_ATOM_FIXED_MASK 0x40000000u
145 #define NAMD_GROUP_FIXED_MASK 0x80000000u
146 
147 struct CompAtomExt {
148  #if defined(NAMD_CUDA) || defined(NAMD_MIC) || defined(NAMD_AVXTILES) || defined(NAMD_HIP)
149  int32 sortOrder; // used to reorder atoms for CUDA
150  #endif
151  #ifdef MEM_OPT_VERSION
152  int32 id;
153  ExclSigID exclId;
154  uint32 sigId : 30; // AtomSigID sigId;
155  #else
156  uint32 id : 30; // minimum for 100M atoms is 28 signed, 27 unsigned
157  #endif
160 };
161 
162 // Use this temporary structure when copying SOA back to AOS
163 // to avoid loop vectorization bug in patchReady_SOA.
165  #if defined(NAMD_CUDA) || defined(NAMD_MIC) || defined(NAMD_AVXTILES) || defined(NAMD_HIP)
166  int32 sortOrder; // used to reorder atoms for CUDA
167  #endif
168  #ifdef MEM_OPT_VERSION
169  int32 id;
170  ExclSigID exclId;
171  uint32 sigId; // must bitwise OR high order bits atomFixed, groupFixed
172  #else
173  uint32 id; // must bitwise OR high order bits atomFixed, groupFixed
174  #endif
175 };
176 
177 static_assert(sizeof(CompAtomExt)==sizeof(CompAtomExtCopy), "NAMD fails to compile due to sizeof(CompAtomExt) != sizeof(CompAtomExtCopy)");
178 
179 #else
180 
181 struct CompAtomExt {
182  #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC)
183  int32 sortOrder; // used to reorder atoms for CUDA
184  #endif
185  #ifdef MEM_OPT_VERSION
186  int32 id;
187  ExclSigID exclId;
188  //int sigId : 30; // AtomSigID sigId;
189  int32 sigId;
190  #else
191  //int id : 30; // minimum for 100M atoms is 28 signed, 27 unsigned
192  int32 id;
193  #endif
196 };
197 
198 #endif // USE_NO_BITFIELDS
199 
203  double recipMass;
209  union{
211 #ifdef MEM_OPT_VERSION
212  int32 hydVal;
213 #endif
214  };
215  union{
218  };
222 
223 #ifdef MEM_OPT_VERSION
224  int32 outputRank;
225 #endif
226 
227 #ifdef MEM_OPT_VERSION
228  //a HACK to re-sort FullAtom list used in Parallel IO
229  //When every home patch processor receives its atoms list for a patch,
230  //the atoms inside this patch may not sorted according to hydList value
231  //To save space, use anonymous union data structure to share the space
232  //of "langevinParam" to store "hydList" from an InputAtom and then sort the
233  //atom list. The "langevinParam" value is not initialized until home
234  //patch creation -Chao Mei
235  int32 operator < (const FullAtom &a) const {
236  return hydVal < a.hydVal;
237  }
238 #endif
239 };
240 
241 //InputAtom is used to contain the info of the atoms
242 //loaded into input processors.
244  bool isValid;
250 
251  int32 operator < (const InputAtom &a) const{
252  return hydList < a.hydList;
253  }
254 };
255 
256 #if !(defined(__CUDACC__) || defined(__HIPCC__))
260 #ifdef NAMD_KNL
261 typedef ResizeArray<CompAtomFlt> CompAtomFltList;
262 #endif
269 
273 typedef float GBReal;
276 
277 typedef int32 PatchID;
278 typedef int32 ComputeID;
279 typedef int32 NodeID;
280 
283 
285 
286 // See AtomMap
287 struct LocalID
288 {
291 };
292 
294 
295 struct ExtForce {
298  ExtForce() : replace(0) {;}
299 };
300 
301 
302 // DMK - Atom Sort
303 #if NAMD_ComputeNonbonded_SortAtoms != 0
304 
305  typedef struct __sort_entry {
306  int32 index; // Index of atom in CompAtom array
307  BigReal sortValue; // Distance of PAp from P0 (see calculation code)
308  } SortEntry;
309 
310 #endif
311 
312 //This class represents a tree node of proxy spanning tree
313 //All pes in this array have the same "nodeID". In other words,
314 //all those pes are in the same physical node.
315 //This is a structure for adapting NAMD to multicore processors
320 
322  nodeID = -1;
323  peIDs = NULL;
324  numPes = 0;
325  }
326  proxyTreeNode(int nid, int numPes_, int *pes){
327  nodeID = nid;
328  numPes = numPes_;
329  peIDs = new int[numPes];
330  memcpy(peIDs, pes, sizeof(int)*numPes);
331  }
332 
333  inline proxyTreeNode(const proxyTreeNode &n){
334  nodeID = n.nodeID;
335  numPes = n.numPes;
336  if(numPes==0) {
337  peIDs = NULL;
338  }else{
339  peIDs = new int[n.numPes];
340  memcpy(peIDs, n.peIDs, sizeof(int)*numPes);
341  }
342  }
344  nodeID = n.nodeID;
345  numPes = n.numPes;
346  delete [] peIDs;
347  if(numPes==0) {
348  peIDs = NULL;
349  return (*this);
350  }
351  peIDs = new int[n.numPes];
352  memcpy(peIDs, n.peIDs, sizeof(int)*numPes);
353  return (*this);
354  }
356  delete [] peIDs;
357  }
358 };
359 
361 #endif // __CUDACC__
362 
363 struct PatchDataSOA {
364 
365  unsigned char *buffer;
366 
367  double * pos_x;
368  double * pos_y;
369  double * pos_z;
370 
371  float * charge;
377 
385 
386  double * vel_x;
387  double * vel_y;
388  double * vel_z;
389 
390  double * fixedPosition_x;
391  double * fixedPosition_y;
392  double * fixedPosition_z;
393 
394  double * recipMass;
395  float * mass;
396  float * langevinParam;
397 
399 
403 
405 
407 
408  // derived quantities for Langevin damping
409  float * langScalVelBBK2;
411 
412  // Gaussian distributed random numbers for Langevin damping
413  float * gaussrand_x;
414  float * gaussrand_y;
415  float * gaussrand_z;
416 
417  // forces
418  double * f_normal_x;
419  double * f_normal_y;
420  double * f_normal_z;
421  double * f_nbond_x;
422  double * f_nbond_y;
423  double * f_nbond_z;
424  double * f_slow_x;
425  double * f_slow_y;
426  double * f_slow_z;
427  double * f_global_x;
428  double * f_global_y;
429  double * f_global_z;
430  double * f_saved_nbond_x;
431  double * f_saved_nbond_y;
432  double * f_saved_nbond_z;
433  double * f_saved_slow_x;
434  double * f_saved_slow_y;
435  double * f_saved_slow_z;
437  // temporary storage for rigid bond constraints
438  double * velNew_x;
439  double * velNew_y;
440  double * velNew_z;
441  double * posNew_x;
442  double * posNew_y;
443  double * posNew_z;
444 
445  size_t numBytes;
448 
449 }; // PatchDataSOA
450 
451 
452 #endif /* NAMDTYPES_H */
453 
double * vel_y
Definition: NamdTypes.h:387
ResizeArray< GBReal > GBRealList
Definition: NamdTypes.h:274
Real langevinParam
Definition: NamdTypes.h:210
NAMD_HOST_DEVICE Transform(char3 input)
Definition: NamdTypes.h:49
ResizeArray< Real > RealList
Definition: NamdTypes.h:272
int32 * isWater
Definition: NamdTypes.h:376
int32 AtomSigID
Definition: NamdTypes.h:138
uint8_t uint8
Definition: common.h:40
double * f_normal_z
Definition: NamdTypes.h:420
int32 * groupFixed
Definition: NamdTypes.h:384
ResizeArray< CudaAtom > CudaAtomList
Definition: NamdTypes.h:257
int32 ComputeID
Definition: NamdTypes.h:278
Vector Force
Definition: NamdTypes.h:32
double * f_normal_y
Definition: NamdTypes.h:419
Position fixedPosition
Definition: NamdTypes.h:202
proxyTreeNode & operator=(const proxyTreeNode &n)
Definition: NamdTypes.h:343
double * posNew_z
Definition: NamdTypes.h:443
int32 * exclId
Definition: NamdTypes.h:381
int32 * unsortOrder
Definition: NamdTypes.h:379
ResizeArray< PatchID > PatchIDList
Definition: NamdTypes.h:281
double * f_saved_slow_z
Definition: NamdTypes.h:435
double * f_slow_y
Definition: NamdTypes.h:425
Definition: Vector.h:72
int32 GPID
Definition: NamdTypes.h:248
double * f_global_z
Definition: NamdTypes.h:429
Definition: NamdTypes.h:305
float Real
Definition: common.h:118
int32_t int32
Definition: common.h:38
int8 i
Definition: NamdTypes.h:44
Position position
Definition: NamdTypes.h:77
int32 maxAtoms
max number of atoms available, multiple of MAXFACTOR
Definition: NamdTypes.h:447
int32 MPID
Definition: NamdTypes.h:249
int8 j
Definition: NamdTypes.h:44
Velocity velocity
Definition: NamdTypes.h:201
double * f_saved_slow_y
Definition: NamdTypes.h:434
float * langScalVelBBK2
derived from langevinParam
Definition: NamdTypes.h:409
uint32 groupFixed
Definition: NamdTypes.h:159
int32 SigIndex
Definition: NamdTypes.h:137
double * f_saved_slow_x
Definition: NamdTypes.h:433
float * gaussrand_y
Definition: NamdTypes.h:414
double * pos_y
Definition: NamdTypes.h:368
double * velNew_z
Definition: NamdTypes.h:440
#define NAMD_HOST_DEVICE
Definition: common.h:237
double * fixedPosition_y
Definition: NamdTypes.h:391
int32 * migrationGroupSize
Definition: NamdTypes.h:404
Definition: Patch.h:35
float * mass
Definition: NamdTypes.h:395
double * f_global_y
Definition: NamdTypes.h:428
double * f_nbond_y
Definition: NamdTypes.h:422
int32 index
Definition: NamdTypes.h:290
uint32 id
Definition: NamdTypes.h:156
int32 index
Definition: NamdTypes.h:306
ResizeArray< Force > ForceList
Definition: NamdTypes.h:267
Charge charge
Definition: NamdTypes.h:78
ResizeArray< Velocity > VelocityList
Definition: NamdTypes.h:266
double * f_nbond_z
Definition: NamdTypes.h:423
ResizeArray< Position > PositionList
Definition: NamdTypes.h:265
int32 * hydrogenGroupSize
Definition: NamdTypes.h:375
size_t numBytes
number of bytes allocated for soa_buffer
Definition: NamdTypes.h:445
ResizeArray< BigReal > BigRealList
Definition: NamdTypes.h:271
proxyTreeNode(const proxyTreeNode &n)
Definition: NamdTypes.h:333
double * f_normal_x
Definition: NamdTypes.h:418
float * langevinParam
Definition: NamdTypes.h:396
float * gaussrand_x
fill with Gaussian distributed random numbers
Definition: NamdTypes.h:413
uint32_t uint32
Definition: common.h:42
int32 * vdwType
Definition: NamdTypes.h:372
int32 * sortOrder
Definition: NamdTypes.h:378
float * gaussrand_z
Definition: NamdTypes.h:415
int16 isMP
Definition: NamdTypes.h:246
int32 migrationGroupSize
Definition: NamdTypes.h:220
int32 ExclSigID
Definition: NamdTypes.h:139
PerAtomFlags flags
Definition: NamdTypes.h:216
double * vel_x
Jim recommends double precision velocity.
Definition: NamdTypes.h:386
int32 * id
Definition: NamdTypes.h:380
bool isValid
Definition: NamdTypes.h:244
double Coordinate
Definition: NamdTypes.h:40
int16 vdwType
Definition: NamdTypes.h:79
BigReal sortValue
Definition: NamdTypes.h:307
ResizeArray< FullAtom > FullAtomList
Definition: NamdTypes.h:263
float * charge
Definition: NamdTypes.h:371
int32 replace
Definition: NamdTypes.h:296
NAMD_HOST_DEVICE Transform(void)
Definition: NamdTypes.h:45
ResizeArray< Transform > TransformList
Definition: NamdTypes.h:268
Vector Position
Definition: NamdTypes.h:24
uint8 partition
Definition: NamdTypes.h:80
int32 * transform_i
Definition: NamdTypes.h:400
uint8 hydrogenGroupSize
Definition: NamdTypes.h:88
struct __sort_entry SortEntry
double * f_saved_nbond_x
Definition: NamdTypes.h:430
int32 AtomType
Definition: NamdTypes.h:36
int32 * partition
Definition: NamdTypes.h:373
float Mass
Definition: NamdTypes.h:37
Force force
Definition: NamdTypes.h:297
double * f_saved_nbond_z
Definition: NamdTypes.h:432
double * posNew_y
Definition: NamdTypes.h:442
PatchID pid
Definition: NamdTypes.h:289
int32 NodeID
Definition: NamdTypes.h:279
bool operator<(const intpair &lhs, const intpair &rhs)
Definition: ComputeGlobal.h:30
int32 nodeID
Definition: NamdTypes.h:317
ResizeArray< Compute * > ComputeList
Definition: NamdTypes.h:284
float * rigidBondLength
Definition: NamdTypes.h:406
ResizeArray< AtomID > AtomIDList
Definition: NamdTypes.h:270
int16_t int16
Definition: common.h:37
ExtForce()
Definition: NamdTypes.h:298
int32 status
Atom status bit fields defined in structures.h.
Definition: NamdTypes.h:217
int32 * transform_k
Definition: NamdTypes.h:402
ResizeArray< proxyTreeNode > proxyTreeNodeList
Definition: NamdTypes.h:360
int32 * peIDs
Definition: NamdTypes.h:318
uint8 nonbondedGroupSize
Definition: NamdTypes.h:81
Vector Velocity
Definition: NamdTypes.h:27
double * recipMass
derived from mass
Definition: NamdTypes.h:394
Real rigidBondLength
Definition: NamdTypes.h:221
proxyTreeNode(int nid, int numPes_, int *pes)
Definition: NamdTypes.h:326
double * velNew_y
Definition: NamdTypes.h:439
int32 sortOrder
Definition: NamdTypes.h:149
double * fixedPosition_x
Definition: NamdTypes.h:390
ResizeArray< CompAtom > CompAtomList
Definition: NamdTypes.h:258
double * pos_z
Definition: NamdTypes.h:369
double * f_slow_x
Definition: NamdTypes.h:424
int32 AtomID
Definition: NamdTypes.h:35
int32 hydList
Definition: NamdTypes.h:247
uint8 isWater
Definition: NamdTypes.h:89
double * pos_x
Definition: NamdTypes.h:367
ResizeArray< CompAtomExt > CompAtomExtList
Definition: NamdTypes.h:259
int32 * transform_j
Definition: NamdTypes.h:401
double * vel_z
Definition: NamdTypes.h:388
Mass mass
Definition: NamdTypes.h:208
int32 numPes
Definition: NamdTypes.h:319
ResizeArray< Patch * > PatchList
Definition: NamdTypes.h:282
int8_t int8
Definition: common.h:36
int32 * sigId
Definition: NamdTypes.h:382
double * f_saved_nbond_y
Definition: NamdTypes.h:431
float Mass
Definition: ComputeGBIS.inl:20
double * f_nbond_x
Definition: NamdTypes.h:421
unsigned char * buffer
Definition: NamdTypes.h:365
double * f_global_x
Definition: NamdTypes.h:427
int32 operator<(const InputAtom &a) const
Definition: NamdTypes.h:251
int16 isGP
Definition: NamdTypes.h:245
double * fixedPosition_z
Definition: NamdTypes.h:392
ResizeArray< int > IntList
Definition: NamdTypes.h:275
int32 * status
Definition: NamdTypes.h:398
float * langScalRandBBK2
from langevinParam and recipMass
Definition: NamdTypes.h:410
uint32 atomFixed
Definition: NamdTypes.h:158
double * posNew_x
Definition: NamdTypes.h:441
double recipMass
Definition: NamdTypes.h:203
int32 * atomFixed
Definition: NamdTypes.h:383
int32 * nonbondedGroupSize
Definition: NamdTypes.h:374
int32 PatchID
Definition: NamdTypes.h:277
float GBReal
Definition: NamdTypes.h:273
float Charge
Definition: NamdTypes.h:38
double * f_slow_z
Definition: NamdTypes.h:426
double * velNew_x
temp storage for rigid bond constraints
Definition: NamdTypes.h:438
ResizeArray< InputAtom > InputAtomList
Definition: NamdTypes.h:264
int8 k
Definition: NamdTypes.h:44
double BigReal
Definition: common.h:123
Transform transform
Definition: NamdTypes.h:219
ResizeArray< NodeID > NodeIDList
Definition: NamdTypes.h:293
int32 numAtoms
number of atoms
Definition: NamdTypes.h:446