NamdTypes.h

Go to the documentation of this file.
00001 
00007 #ifndef NAMDTYPES_H
00008 
00009 #define NAMDTYPES_H
00010 
00011 #include "common.h"
00012 #include "Vector.h"
00013 #ifndef __CUDACC__
00014 #include "ResizeArray.h"
00015 #endif
00016 
00017 class Patch;
00018 class Compute;
00019 
00020 typedef Vector Position;
00021 typedef Vector Velocity;
00022 
00023 //#ifdef ARCH_POWERPC
00024 //typedef AlignVector Force;
00025 //#else
00026 typedef Vector Force;
00027 //#endif
00028 
00029 typedef int AtomID;
00030 typedef int AtomType;
00031 typedef float Mass;
00032 typedef float Charge;
00033 
00034 typedef double Coordinate;
00035 
00036 struct Transform
00037 {
00038   signed char i,j,k;
00039   Transform(void) { i=0; j=0; k=0; }
00040 };
00041 
00042 /*
00043  * 1. "position" field in this structure is very important since it
00044  * needs to be sent to every patch after every timestep.
00045  * 2. Anything that is static (value is decided before computation)
00046  * or only changes after atom migration should be put into the CompAtomExt structure
00047  * 3. This data structure is 32-byte long which is particularly optimized for some machines
00048  * (including BG/L) for better cache and message performance. Therefore, changes
00049  * to this structure should be cautioned for the sake of performance.
00050  */
00051 
00052 struct CompAtom {
00053   Position position;
00054   Charge charge;
00055   short vdwType;
00056   unsigned char partition;
00057   unsigned int nonbondedGroupSize : 3;
00058   unsigned int hydrogenGroupSize : 4;  // could be 3 if unsigned
00059   unsigned int isWater : 1;  // 0 = particle is not in water, 1 = is in water
00060 };
00061 
00062 #ifdef NAMD_KNL
00063 struct CompAtomFlt {
00064   FloatVector position;
00065   int32 vdwType;
00066 };
00067 #endif
00068 
00069 //CompAtomExt is now needed even in normal case
00070 //for changing the packed msg type related to
00071 //ProxyPatch into varsize msg type where
00072 // two types of proxy msgs (originally, the msg 
00073 // for the step where atoms migrate (ProxyAllMsg), 
00074 // and  the msg for normal steps (ProxyDataMsg))
00075 // are declared as the same class (ProxyDataMsg).
00076 // Note that in normal case, the class is needed
00077 // just for passing the compilation, but not involved
00078 // in the actual force calculation.
00079 // --Chao Mei
00080 
00081 typedef int SigIndex;
00082 typedef int AtomSigID;
00083 typedef int ExclSigID;
00084 
00085 struct CompAtomExt {
00086   #if defined(NAMD_CUDA) || defined(NAMD_MIC)
00087   int sortOrder;  // used to reorder atoms for CUDA
00088   #endif
00089   #ifdef MEM_OPT_VERSION
00090   int id;
00091   ExclSigID exclId;
00092   int sigId : 30;  // AtomSigID sigId;
00093   #else
00094   int id : 30;  // minimum for 100M atoms is 28 signed, 27 unsigned
00095   #endif
00096   unsigned int atomFixed : 1;
00097   unsigned int groupFixed : 1;
00098 };
00099 
00100 struct FullAtom : CompAtom, CompAtomExt{
00101   Velocity velocity;
00102   Position fixedPosition;
00103   double recipMass;
00108   Mass mass;
00109   union{
00110       Real langevinParam;
00111 #ifdef MEM_OPT_VERSION
00112       int hydVal;
00113 #endif      
00114   };  
00115   int32 status;
00116   Transform transform;
00117   int migrationGroupSize;
00118   Real rigidBondLength;
00119 
00120 #ifdef MEM_OPT_VERSION
00121   int outputRank;
00122 #endif
00123 
00124 #ifdef MEM_OPT_VERSION
00125   //a HACK to re-sort FullAtom list used in Parallel IO
00126   //When every home patch processor receives its atoms list for a patch,
00127   //the atoms inside this patch may not sorted according to hydList value
00128   //To save space, use anonymous union data structure to share the space
00129   //of "langevinParam" to store "hydList" from an InputAtom and then sort the 
00130   //atom list. The "langevinParam" value is not initialized until home 
00131   //patch creation -Chao Mei
00132   int operator < (const FullAtom &a) const {
00133       return hydVal < a.hydVal;
00134   }
00135 #endif
00136 };
00137 
00138 //InputAtom is used to contain the info of the atoms
00139 //loaded into input processors.
00140 struct InputAtom: FullAtom{
00141         bool isValid;
00142         short isGP;
00143         short isMP;
00144         int hydList;
00145         int GPID;
00146         int MPID;
00147         
00148         int operator < (const InputAtom &a) const{
00149                 return hydList < a.hydList;
00150         }
00151 };
00152 
00153 struct CudaAtom {
00154   float x,y,z,q;
00155 };
00156 
00157 struct CudaForce {
00158   float x, y, z;
00159 };
00160 
00161 #ifndef __CUDACC__
00162 typedef ResizeArray<CudaAtom> CudaAtomList;
00163 typedef ResizeArray<CompAtom> CompAtomList;
00164 typedef ResizeArray<CompAtomExt> CompAtomExtList;
00165 #ifdef NAMD_KNL
00166 typedef ResizeArray<CompAtomFlt> CompAtomFltList;
00167 #endif
00168 typedef ResizeArray<FullAtom> FullAtomList;
00169 typedef ResizeArray<InputAtom> InputAtomList;
00170 typedef ResizeArray<Position> PositionList;
00171 typedef ResizeArray<Velocity> VelocityList;
00172 typedef ResizeArray<Force> ForceList;
00173 typedef ResizeArray<Transform> TransformList;
00174 
00175 typedef ResizeArray<AtomID> AtomIDList;
00176 typedef ResizeArray<BigReal> BigRealList;
00177 typedef ResizeArray<Real> RealList;
00178 typedef float GBReal;
00179 typedef ResizeArray<GBReal> GBRealList;
00180 typedef ResizeArray<int> IntList;
00181 
00182 typedef int PatchID;
00183 typedef int ComputeID;
00184 typedef int NodeID;
00185 
00186 typedef ResizeArray<PatchID> PatchIDList;
00187 typedef ResizeArray<Patch *> PatchList;
00188 
00189 typedef ResizeArray<Compute *> ComputeList;
00190 
00191 // See AtomMap
00192 struct LocalID
00193 {
00194   PatchID pid;
00195   int index;
00196 };
00197 
00198 typedef ResizeArray<NodeID> NodeIDList;
00199 
00200 struct ExtForce {
00201   int replace;
00202   Force force;
00203   ExtForce() : replace(0) {;}
00204 };
00205 
00206 
00207 // DMK - Atom Sort
00208 #if NAMD_ComputeNonbonded_SortAtoms != 0
00209 
00210   typedef struct __sort_entry {
00211     int index;  // Index of atom in CompAtom array
00212     BigReal sortValue;   // Distance of PAp from P0 (see calculation code)
00213   } SortEntry;
00214 
00215 #endif
00216 
00217 //This class represents a tree node of proxy spanning tree
00218 //All pes in this array have the same "nodeID". In other words,
00219 //all those pes are in the same physical node.
00220 //This is a structure for adapting NAMD to multicore processors
00221 struct proxyTreeNode{
00222     int nodeID;
00223     int *peIDs;
00224     int numPes;
00225 
00226     proxyTreeNode(){
00227         nodeID = -1;
00228         peIDs = NULL;
00229         numPes = 0;
00230     }
00231     proxyTreeNode(int nid, int numPes_, int *pes){
00232         nodeID = nid;
00233         numPes = numPes_;
00234         peIDs = new int[numPes];
00235         memcpy(peIDs, pes, sizeof(int)*numPes);
00236     }
00237 
00238     inline proxyTreeNode(const proxyTreeNode &n){
00239         nodeID = n.nodeID;
00240         numPes = n.numPes;
00241         if(numPes==0) {
00242             peIDs = NULL;
00243         }else{
00244             peIDs = new int[n.numPes];
00245             memcpy(peIDs, n.peIDs, sizeof(int)*numPes);
00246         }
00247     }
00248     inline proxyTreeNode &operator=(const proxyTreeNode &n){
00249         nodeID = n.nodeID;
00250         numPes = n.numPes;
00251         delete [] peIDs;
00252         if(numPes==0) {
00253             peIDs = NULL;
00254             return (*this);
00255         }
00256         peIDs = new int[n.numPes];
00257         memcpy(peIDs, n.peIDs, sizeof(int)*numPes);
00258         return (*this);
00259     }
00260     ~proxyTreeNode(){
00261         delete [] peIDs;
00262     }
00263 };
00264 
00265 typedef ResizeArray<proxyTreeNode> proxyTreeNodeList;
00266 #endif // __CUDACC__
00267 
00268 
00269 //
00270 // When defined, use NVTX to record CPU activity into CUDA profiling run.
00271 //
00272 #undef PUSH_RANGE
00273 #undef POP_RANGE
00274 #undef RANGE
00275 
00276 #if defined(NAMD_CUDA) && defined(NAMD_USE_NVTX)
00277 
00278 #include <nvToolsExt.h>
00279 
00280 // C++ note: declaring const variables implies static (internal) linkage,
00281 // and you have to explicitly specify "extern" to get external linkage.
00282 const uint32_t NAMD_nvtx_colors[] = {
00283   0x0000ff00,
00284   0x000000ff,
00285   0x00ffff00,
00286   0x00ff00ff,
00287   0x0000ffff,
00288   0x00ff0000,
00289   0x00ffffff,
00290 };
00291 const int NAMD_nvtx_colors_len = sizeof(NAMD_nvtx_colors)/sizeof(uint32_t);
00292 
00293 // start recording an event
00294 #define PUSH_RANGE(name,cid) \
00295   do { \
00296     int color_id = cid; \
00297     color_id = color_id % NAMD_nvtx_colors_len; \
00298     nvtxEventAttributes_t eventAttrib = {0}; \
00299     eventAttrib.version = NVTX_VERSION; \
00300     eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; \
00301     eventAttrib.colorType = NVTX_COLOR_ARGB; \
00302     eventAttrib.color = NAMD_nvtx_colors[color_id]; \
00303     eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; \
00304     eventAttrib.message.ascii = name; \
00305     nvtxRangePushEx(&eventAttrib); \
00306   } while(0)  // must terminate with semi-colon
00307 
00308 // stop recording an event
00309 #define POP_RANGE \
00310   nvtxRangePop()
00311   // must terminate with semi-colon
00312 
00313 // embed event recording in class to automatically pop when destroyed
00314 class NAMD_NVTX_Tracer {
00315   public:
00316     NAMD_NVTX_Tracer(const char *name, int cid = 0) { PUSH_RANGE(name, cid); }
00317     ~NAMD_NVTX_Tracer() { POP_RANGE; }
00318 };
00319 
00320 // include cid as part of the name
00321 // call RANGE at beginning of function to push event recording
00322 // destructor is automatically called on return to pop event recording
00323 #define RANGE(name,cid) \
00324   NAMD_NVTX_Tracer namd_nvtx_tracer##cid(name,cid)
00325   // must terminate with semi-colon
00326 
00327 #else
00328 
00329 //
00330 // Otherwise the NVTX profiling macros become no-ops.
00331 //
00332 #define PUSH_RANGE(name,cid) do { } while(0)  // must terminate with semi-colon
00333 #define POP_RANGE            do { } while(0)  // must terminate with semi-colon
00334 #define RANGE(namd,cid)      do { } while(0)  // must terminate with semi-colon
00335 
00336 #endif // NAMD_CUDA && NAMD_USE_NVTX
00337 
00338 
00339 #endif /* NAMDTYPES_H */
00340 

Generated on Thu Nov 23 01:17:13 2017 for NAMD by  doxygen 1.4.7