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

Generated on Fri Jun 22 01:17:12 2018 for NAMD by  doxygen 1.4.7