00001
00007 #ifndef PROXYMGR_H
00008 #define PROXYMGR_H
00009
00010
00011 #include "charm++.h"
00012
00013 #include "main.h"
00014 #include "NamdTypes.h"
00015 #include "PatchTypes.h"
00016 #include "UniqueSet.h"
00017 #include "UniqueSetIter.h"
00018 #include "ProcessorPrivate.h"
00019 #include "ProxyMgr.decl.h"
00020
00021 extern int proxySendSpanning, proxyRecvSpanning;
00022 extern const int proxySpanDim;
00023 extern const int inNodeProxySpanDim;
00024
00025 class RegisterProxyMsg : public CMessage_RegisterProxyMsg {
00026 public:
00027 NodeID node;
00028 PatchID patch;
00029 };
00030
00031 class UnregisterProxyMsg : public CMessage_UnregisterProxyMsg {
00032 public:
00033 NodeID node;
00034 PatchID patch;
00035 };
00036
00037 class ProxyAtomsMsg : public CMessage_ProxyAtomsMsg {
00038 public:
00039 PatchID patch;
00040 AtomIDList atomIDList;
00041 static void* pack(ProxyAtomsMsg *msg);
00042 static ProxyAtomsMsg* unpack(void *ptr);
00043 };
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 class ProxyDataMsg : public CMessage_ProxyDataMsg {
00062 public:
00063 PatchID patch;
00064 Flags flags;
00065
00066 int plLen;
00067
00068 CompAtom *positionList;
00069 int avgPlLen;
00070 CompAtom *avgPositionList;
00071
00072
00073
00074
00075
00076
00077
00078
00079 int plExtLen;
00080 CompAtomExt *positionExtList;
00081
00082
00083 #if NAMD_SeparateWaters != 0
00084 int numWaterAtoms;
00085
00086 #endif
00087 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00088
00089
00090
00091
00092
00093
00094
00095
00096 #if NAMD_SeparateWaters != 0
00097 char padding[(32-(sizeof(envelope)+sizeof(PatchID)+sizeof(Flags)+4*sizeof(int)+3*sizeof(void *))%32)%32];
00098 #else
00099 char padding[(32-(sizeof(envelope)+sizeof(PatchID)+sizeof(Flags)+3*sizeof(int)+3*sizeof(void *))%32)%32];
00100 #endif
00101 #endif
00102
00103 };
00104
00105
00106
00107 class ProxyResultMsg : public CMessage_ProxyResultMsg {
00108 public:
00109 NodeID node;
00110 PatchID patch;
00111 ForceList forceList[Results::maxNumForces];
00112 static void* pack(ProxyResultMsg *msg);
00113 static ProxyResultMsg* unpack(void *ptr);
00114 };
00115
00116 class ProxyResultVarsizeMsg: public CMessage_ProxyResultVarsizeMsg{
00117 public:
00118 NodeID node;
00119 PatchID patch;
00120 int flLen[Results::maxNumForces];
00121
00122 Force *forceArr;
00123
00124
00125 char *isZero;
00126
00127
00128
00129
00130
00131 char padding[(8-(sizeof(envelope)+sizeof(NodeID)+sizeof(PatchID)+sizeof(int)*Results::maxNumForces+2*sizeof(void *))%8)%8];
00132
00133
00134 static ProxyResultVarsizeMsg *getANewMsg(NodeID nid, PatchID pid, int prioSize, ForceList *fls);
00135 };
00136
00137 class ProxyNodeAwareSpanningTreeMsg: public CMessage_ProxyNodeAwareSpanningTreeMsg{
00138 public:
00139 PatchID patch;
00140 NodeID procID;
00141 int numNodesWithProxies;
00142 int *numPesOfNode;
00143 int *allPes;
00144
00145 static ProxyNodeAwareSpanningTreeMsg *getANewMsg(PatchID pid, NodeID nid, proxyTreeNode *tree, int size);
00146
00147
00148 void printOut(char *tag);
00149 };
00150
00151 class ProxyCombinedResultMsg : public CMessage_ProxyCombinedResultMsg {
00152 public:
00153 #if defined(NODEAWARE_PROXY_SPANNINGTREE) && defined(USE_NODEPATCHMGR)
00154
00155
00156 NodeID destPe;
00157 #endif
00158 PatchID patch;
00159 NodeIDList nodes;
00160 ForceList forceList[Results::maxNumForces];
00161 static void* pack(ProxyCombinedResultMsg *msg);
00162 static ProxyCombinedResultMsg* unpack(void *ptr);
00163 };
00164
00165 class ProxySpanningTreeMsg : public CMessage_ProxySpanningTreeMsg {
00166 public:
00167 PatchID patch;
00168 NodeID node;
00169 NodeIDList tree;
00170 static void* pack(ProxySpanningTreeMsg *msg);
00171 static ProxySpanningTreeMsg* unpack(void *ptr);
00172 };
00173
00174 class ProxyPatch;
00175 class PatchMap;
00176
00177 struct ProxyElem {
00178 ProxyElem() : proxyPatch(0) { };
00179 ProxyElem(PatchID pid) : patchID(pid), proxyPatch(0) { };
00180 ProxyElem(PatchID pid, ProxyPatch *p) : patchID(pid), proxyPatch(p) { };
00181
00182 int hash() const { return patchID; }
00183 int operator==(const ProxyElem & pe) const { return patchID == pe.patchID; }
00184
00185 PatchID patchID;
00186 ProxyPatch *proxyPatch;
00187 };
00188
00189 typedef UniqueSet<ProxyElem> ProxySet;
00190 typedef UniqueSetIter<ProxyElem> ProxySetIter;
00191
00192 class ProxyTree {
00193 public:
00194 int proxyMsgCount;
00195 NodeIDList *proxylist;
00196 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00197
00198
00199 proxyTreeNodeList *naTrees;
00200 #else
00201 NodeIDList *trees;
00202 int *sizes;
00203 #endif
00204
00205 public:
00206 ProxyTree() {
00207 proxyMsgCount = 0;
00208 proxylist = NULL;
00209 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00210 naTrees = NULL;
00211 #else
00212 trees = NULL;
00213 sizes = NULL;
00214 #endif
00215 }
00216 ~ProxyTree() {
00217 }
00218 };
00219
00220 class ProxyMgr : public BOCclass
00221 {
00222 public:
00223 ProxyMgr();
00224 ~ProxyMgr();
00225
00226 void removeProxies(void);
00227 void removeUnusedProxies(void);
00228 void createProxies(void);
00229
00230 void createProxy(PatchID pid);
00231 void removeProxy(PatchID pid);
00232
00233 void registerProxy(PatchID pid);
00234 void recvRegisterProxy(RegisterProxyMsg *);
00235
00236 void unregisterProxy(PatchID pid);
00237 void recvUnregisterProxy(UnregisterProxyMsg *);
00238
00239 void setSendSpanning();
00240 int getSendSpanning();
00241
00242 void setRecvSpanning();
00243 int getRecvSpanning();
00244
00245 void buildProxySpanningTree();
00246 void sendSpanningTrees();
00247 void sendSpanningTreeToHomePatch(int pid, int *tree, int n);
00248 void recvSpanningTreeOnHomePatch(int pid, int *tree, int n);
00249 void sendSpanningTree(ProxySpanningTreeMsg *);
00250 void recvSpanningTree(ProxySpanningTreeMsg *);
00251
00252 void sendNodeAwareSpanningTreeToHomePatch(int pid, proxyTreeNode *tree, int n);
00253 void recvNodeAwareSpanningTreeOnHomePatch(ProxyNodeAwareSpanningTreeMsg *msg);
00254 void sendNodeAwareSpanningTree(ProxyNodeAwareSpanningTreeMsg *);
00255 void recvNodeAwareSpanningTree(ProxyNodeAwareSpanningTreeMsg *);
00256
00257 void recvNodeAwareSTParent(int patch, int parent);
00258
00259 void buildProxySpanningTree2();
00260 void sendProxies(int pid, int *list, int n);
00261 void recvProxies(int pid, int *list, int n);
00262
00263 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00264 void buildNodeAwareSpanningTree0();
00265 static void buildSinglePatchNodeAwareSpanningTree(PatchID pid, NodeIDList &proxyList,
00266 proxyTreeNodeList &ptnTree, int *proxyNodeMap);
00267 #else
00268 void buildSpanningTree0();
00269 #endif
00270
00271 void sendResults(ProxyResultVarsizeMsg *);
00272 void recvResults(ProxyResultVarsizeMsg *);
00273 void sendResults(ProxyResultMsg *);
00274 void recvResults(ProxyResultMsg *);
00275 void sendResults(ProxyCombinedResultMsg *);
00276 void recvResults(ProxyCombinedResultMsg *);
00277 void recvImmediateResults(ProxyCombinedResultMsg *);
00278
00279 void sendProxyData(ProxyDataMsg *, int, int*);
00280 void recvImmediateProxyData(ProxyDataMsg *);
00281 void recvProxyData(ProxyDataMsg *);
00282
00283 void sendProxyAll(ProxyDataMsg *, int, int*);
00284 void recvImmediateProxyAll(ProxyDataMsg *);
00285 void recvProxyAll(ProxyDataMsg *);
00286
00287 static ProxyMgr *Object() { return CkpvAccess(ProxyMgr_instance); }
00288
00289 int numProxies() { return proxySet.size(); }
00290
00291 static int nodecount;
00292 ProxyTree &getPtree();
00293
00294 private:
00295 ProxySet proxySet;
00296 ProxyTree ptree;
00297
00298 void printProxySpanningTree();
00299 };
00300
00301 class NodeProxyMgr : public CBase_NodeProxyMgr
00302 {
00303 private:
00304 proxyTreeNode **proxyInfo;
00305 int numPatches;
00306
00307 CkGroupID localProxyMgr;
00308 PatchMap **localPatchMaps;
00309
00310 public:
00311 NodeProxyMgr(){
00312 proxyInfo = NULL;
00313 numPatches = 0;
00314 localPatchMaps = new PatchMap *[CkMyNodeSize()];
00315 }
00316 ~NodeProxyMgr(){
00317 for(int i=0; i<numPatches; i++) {
00318 delete proxyInfo[i];
00319 }
00320 delete [] proxyInfo;
00321 delete [] localPatchMaps;
00322 }
00323
00324 void createProxyInfo(int numPs){
00325 numPatches = numPs;
00326 proxyInfo = new proxyTreeNode *[numPs];
00327 memset(proxyInfo, 0, sizeof(proxyTreeNode *)*numPs);
00328 }
00329 void registerPatch(int patchID, int numPes, int *pes);
00330 proxyTreeNode *getPatchProxyInfo(int patchID){
00331 return proxyInfo[patchID];
00332 }
00333
00334 void registerLocalProxyMgr(CkGroupID one){
00335 localProxyMgr = one;
00336 }
00337 const CkGroupID &getLocalProxyMgr(){
00338 return localProxyMgr;
00339 }
00340 void registerLocalPatchMap(int rank, PatchMap *one){
00341 localPatchMaps[rank] = one;
00342 }
00343 PatchMap *getLocalPatchMap(int rank){
00344 return localPatchMaps[rank];
00345 }
00346
00347 void recvImmediateProxyData(ProxyDataMsg *msg);
00348 void recvImmediateProxyAll(ProxyDataMsg *msg);
00349 void recvImmediateResults(ProxyCombinedResultMsg *);
00350 };
00351
00352 #endif
00353