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 computeExclsType,
00024 computeBondsType,
00025 computeAnglesType,
00026 computeDihedralsType,
00027 computeImpropersType,
00028 computeTholeType,
00029 computeAnisoType,
00030 computeCrosstermsType,
00031 computeSelfExclsType,
00032 computeSelfBondsType,
00033 computeSelfAnglesType,
00034 computeSelfDihedralsType,
00035 computeSelfImpropersType,
00036 computeSelfTholeType,
00037 computeSelfAnisoType,
00038 computeSelfCrosstermsType,
00039 #ifdef DPMTA
00040 computeDPMTAType,
00041 #endif
00042 #ifdef DPME
00043 computeDPMEType,
00044 #endif
00045 computePmeType,
00046 optPmeType,
00047 computeEwaldType,
00048 computeFullDirectType,
00049 computeGlobalType,
00050 computeExtType,
00051 computeGBISserType,
00052 computeLCPOType,
00053 computeFmmType,
00054 computeMsmSerialType,
00055 computeMsmMsaType,
00056 computeMsmType,
00057 computeEFieldType,
00058
00059 computeGridForceType,
00060
00061 computeStirType,
00062 computeSphericalBCType,
00063 computeCylindricalBCType,
00064 computeTclBCType,
00065 computeRestraintsType,
00066 computeConsForceType,
00067 computeConsTorqueType,
00068 computeErrorType
00069 };
00070
00071 class ComputeMap
00072 {
00073 public:
00074 static ComputeMap *Instance();
00075 inline static ComputeMap *Object() { return instance; }
00076
00077 void checkMap();
00078
00079 ~ComputeMap(void);
00080
00081 void registerCompute(ComputeID cid, Compute *c) {
00082 computePtrs[cid] = c;
00083 }
00084
00085
00086
00087 inline int numComputes(void) {
00088 return nComputes;
00089 }
00090
00091
00092 inline int node(ComputeID cid) {
00093 return computeData[cid].node;
00094 }
00095
00096 inline void setNode(ComputeID cid, NodeID node) {
00097 computeData[cid].node = node;
00098 }
00099
00100
00101
00102 inline NodeID newNode(ComputeID cid) {
00103 return (computeData[cid].moveToNode);
00104 }
00105
00106 inline void setNewNode(ComputeID cid, NodeID node) {
00107 computeData[cid].moveToNode = node;
00108 }
00109
00110
00111
00112 int numPids(ComputeID cid);
00113
00114
00115
00116 int pid(ComputeID cid, int i);
00117 int trans(ComputeID cid, int i);
00118
00119
00120 ComputeType type(ComputeID cid);
00121 int partition(ComputeID cid);
00122 int numPartitions(ComputeID cid);
00123
00124 inline void setNumPartitions(ComputeID cid, char numPartitions) {
00125 computeData[cid].numPartitions = numPartitions;
00126 }
00127 inline char newNumPartitions(ComputeID cid) {
00128 return (computeData[cid].newNumPartitions);
00129 }
00130 inline void setNewNumPartitions(ComputeID cid, char numPartitions) {
00131 computeData[cid].newNumPartitions = numPartitions;
00132 }
00133
00134 int allocateCids();
00135
00136
00137
00138
00139 ComputeID storeCompute(int node,int maxPids,ComputeType type,
00140 int partition=-1, int numPartitions=0);
00141
00142
00143
00144 void newPid(ComputeID cid, int pid, int trans = 13);
00145
00146 ComputeID cloneCompute(ComputeID src, int partition);
00147
00148 void printComputeMap(void);
00149 void saveComputeMap(const char *fname);
00150 void loadComputeMap(const char *fname);
00151
00152 Compute *compute(ComputeID cid) { return computePtrs[cid]; };
00153
00154 friend class ComputeMgr;
00155
00156 struct PatchRec
00157 {
00158 PatchID pid;
00159 int trans;
00160
00161 PatchRec() : pid(-1), trans(-1) { ; }
00162 };
00163
00164 enum { numPidsAllocated=8 };
00165
00166 struct ComputeData
00167 {
00168 ComputeData() {
00169 node = -1; moveToNode = -1;
00170 newNumPartitions = 0;
00171 numPids = 0;
00172 }
00173 int node;
00174 int moveToNode;
00175 ComputeType type;
00176 char partition;
00177 char numPartitions;
00178 char newNumPartitions;
00179 char numPids;
00180 PatchRec pids[numPidsAllocated];
00181 };
00182 protected:
00183 friend class WorkDistrib;
00184 void pack(ComputeData *buf);
00185 void unpack(int n, ComputeData *buf);
00186 void initPtrs();
00187 void extendPtrs();
00188
00189 ComputeMap(void);
00190
00191 private:
00192 int nComputes;
00193 ResizeArray<ComputeData> computeData;
00194 Compute **computePtrs;
00195
00196 static ComputeMap *instance;
00197 };
00198
00199 #endif
00200