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