ComputeMap.h

Go to the documentation of this file.
00001 
00007 #ifndef COMPUTEMAP_H
00008 #define COMPUTEMAP_H
00009 
00010 #include "NamdTypes.h"
00011 #include "ProcessorPrivate.h"
00012 #include "ResizeArray.h"
00013 
00014 class Compute;
00015 class ComputeMgr;
00016 template<class Type> class ObjectArena;
00017 
00018 enum ComputeType
00019 {
00020   computeNonbondedSelfType,
00021   computeNonbondedPairType,
00022   computeNonbondedCUDAType,
00023   computeNonbondedMICType,
00024   computeExclsType,
00025   computeBondsType,
00026   computeAnglesType,
00027   computeDihedralsType,
00028   computeImpropersType,
00029   computeTholeType,
00030   computeAnisoType,
00031   computeCrosstermsType,
00032   // JLai
00033   computeGromacsPairType,
00034   computeSelfGromacsPairType,
00035   // End of JLai entry
00036   computeSelfExclsType,
00037   computeSelfBondsType,
00038   computeSelfAnglesType,
00039   computeSelfDihedralsType,
00040   computeSelfImpropersType,
00041   computeSelfTholeType,
00042   computeSelfAnisoType,
00043   computeSelfCrosstermsType,
00044 #ifdef DPMTA
00045   computeDPMTAType,
00046 #endif
00047 #ifdef DPME
00048   computeDPMEType,
00049 #endif
00050   computePmeType,
00051 #ifdef NAMD_CUDA
00052   computePmeCUDAType,
00053   computeNonbondedCUDA2Type,
00054 #ifdef BONDED_CUDA
00055   computeBondedCUDAType,
00056 #endif
00057 #endif
00058   optPmeType,
00059   computeEwaldType,
00060   computeFullDirectType,
00061   computeGlobalType,
00062   computeExtType,
00063   computeQMType,
00064   computeGBISserType,
00065   computeLCPOType,
00066   computeFmmType,
00067   computeMsmSerialType,
00068   computeMsmMsaType,
00069   computeMsmType,
00070   computeEFieldType,
00071 /* BEGIN gf */
00072   computeGridForceType,
00073 /* END gf */
00074   computeStirType,
00075   computeSphericalBCType,
00076   computeCylindricalBCType,
00077   computeTclBCType,
00078   computeRestraintsType,
00079   computeConsForceType,
00080   computeConsTorqueType,
00081   computeErrorType
00082 };
00083 
00084 class ComputeMap
00085 {
00086 public:
00087   static ComputeMap *Instance();
00088   inline static ComputeMap *Object() { return instance; }
00089 
00090   void checkMap();
00091 
00092   ~ComputeMap(void);
00093 
00094   void registerCompute(ComputeID cid, Compute *c) {
00095     computePtrs[cid] = c;
00096   }
00097 
00098   // numComputes() returns the number of compute objects known
00099   // by the map.
00100   inline int numComputes(void) {
00101     return nComputes;
00102   }
00103 
00104   // node(cid) returns the node where the compute object currently exists.
00105   inline int node(ComputeID cid) {
00106     return computeData[cid].node;
00107   }
00108 
00109   inline void setNode(ComputeID cid, NodeID node) {
00110     computeData[cid].node = node;
00111   }
00112 
00113   // newNode(cid,node) sets up map to tell WorkDistrib to send 
00114   // compute to new node
00115   inline NodeID newNode(ComputeID cid) {
00116     return (computeData[cid].moveToNode);
00117   }
00118 
00119   inline void setNewNode(ComputeID cid, NodeID node) {
00120     computeData[cid].moveToNode = node;
00121   }
00122 
00123   // numPids(cid) returns the number of patch ids which are registered
00124   // with this compute object.
00125   int numPids(ComputeID cid);
00126   
00127   // pid(cid,i) returns the i-th patch id registered
00128   // with the patch.  
00129   int pid(ComputeID cid, int i);
00130   int trans(ComputeID cid, int i);
00131 
00132   // type(cid) returns the compute type of the given ComputeID
00133   ComputeType type(ComputeID cid);
00134   int partition(ComputeID cid);
00135   int numPartitions(ComputeID cid);
00136 
00137   inline void setNumPartitions(ComputeID cid, char numPartitions) {
00138     computeData[cid].numPartitions = numPartitions;
00139   }
00140   inline char newNumPartitions(ComputeID cid) {
00141     return (computeData[cid].newNumPartitions);
00142   }
00143   inline void setNewNumPartitions(ComputeID cid, char numPartitions) {
00144     computeData[cid].newNumPartitions = numPartitions;
00145   }
00146 
00147   int allocateCids();
00148 
00149   // storeCompute(cid,node,maxPids) tells the ComputeMap to store
00150   // information about the indicated patch, and allocate space
00151   // for up to maxPids dependents
00152   ComputeID storeCompute(int node,int maxPids,ComputeType type,
00153                          int partition=-1, int numPartitions=0);
00154 
00155   // newPid(cid,pid) stores the n patch ids associated with
00156   // compute id cid.
00157   void newPid(ComputeID cid, int pid, int trans = 13);
00158 
00159   #if defined(NAMD_MIC)
00160     void setDirectToDevice(const ComputeID cid, const int d);
00161     int directToDevice(const ComputeID cid) const;
00162   #endif
00163 
00164   ComputeID cloneCompute(ComputeID src, int partition);
00165 
00166   void printComputeMap(void);
00167   void saveComputeMap(const char *fname);
00168   void loadComputeMap(const char *fname);
00169 
00170   Compute *compute(ComputeID cid) { return computePtrs[cid]; };
00171 
00172   friend class ComputeMgr;
00173 
00174   struct PatchRec
00175   {
00176     PatchID pid;
00177     int trans;
00178 
00179     PatchRec() : pid(-1), trans(-1) { ; }
00180   };
00181 
00182   enum { numPidsAllocated=8 };
00183 
00184   struct ComputeData
00185   {
00186     ComputeData() { 
00187       node = -1; moveToNode = -1; 
00188       newNumPartitions = 0;
00189       numPids = 0;
00190       #if defined(NAMD_MIC)
00191         directToDevice = 0;
00192       #endif
00193     }
00194     int node;
00195     int moveToNode;
00196     ComputeType type;
00197     char partition;
00198     char numPartitions;
00199     char newNumPartitions;
00200     char numPids;
00201     PatchRec pids[numPidsAllocated];
00202     #if defined(NAMD_MIC)
00203       char directToDevice;
00204     #endif
00205   };
00206 protected:
00207   friend class WorkDistrib;
00208   void pack(ComputeData *buf);
00209   void unpack(int n, ComputeData *buf);
00210   void initPtrs();
00211   void extendPtrs();
00212 
00213   ComputeMap(void);
00214 
00215 private:
00216   int nComputes;
00217   ResizeArray<ComputeData> computeData;
00218   Compute **computePtrs;
00219 
00220   static ComputeMap *instance;
00221 };
00222 
00223 #endif /* COMPUTEMAP_H */
00224 

Generated on Tue Sep 19 01:17:10 2017 for NAMD by  doxygen 1.4.7