Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

ProxyMgr.h

Go to the documentation of this file.
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 //1. This class represents for both msg types: one that
00046 //is originally known as ProxyAllMsg which is sent
00047 //at the step where atoms migrate; and the other is
00048 //sent during the steps between two migrations.
00049 //2. In the case of memory optimized version, the scenario
00050 //becomes tricky as load balancer will move compute objects
00051 //around so that new ProxyPatches will be created where
00052 //the CompAtomExt list information is not available. If
00053 //the step immediately after the load balancing is a normal
00054 //step, then the CompAtomExt list info has to be resent by
00055 //the HomePatch. Because of the current Proxy msg communication
00056 //scheme where msg is sent to ProxyMgr first, and then retransmitted
00057 //to ProxyPatches, there's overhead when we want to resend CompAtomExt
00058 //list as not all the ProxyPatches that are managed by ProxyMgr are
00059 //newly created ProxyPatches. 
00060 //--Chao Mei
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   //1. The following field will be only
00073   //useful for memory optimized version.
00074   //2. In normal case, adding this field only
00075   //increases the msg length by 4 bytes which
00076   //can be ignored considering the current fast
00077   //communication network
00078   //--Chao Mei
00079   int plExtLen;
00080   CompAtomExt *positionExtList;
00081 
00082   // DMK - Atom Separation (water vs. non-water)
00083   #if NAMD_SeparateWaters != 0
00084     int numWaterAtoms;  // Number of atoms in positionList (from start)
00085                         //   that are part of water hydrogen groups.
00086   #endif
00087 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00088   //Adding padding bytes to make sure that positionList is
00089   //32-byte aligned which usually gives better cache performance,
00090   //especially on BlueGene/L machine. Otherwise, we have to
00091   //do the extra copy.
00092   //The basic method to calculate padding is to add up
00093   //the size of all the fields so far, including
00094   //the message header (the envelope) , then mod (alignment)
00095   // --Chao Mei
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     //Indicate the position of the force list that has zero value
00124     //which is not recorded in the above force array.
00125     char *isZero;
00126 
00127     //add padding bytes to make sure the beginning 
00128     //of force arrays is 8-byte aligned as it is originally.
00129     //Therefore, we have to put the forceArr field as
00130     //the first variable of varsize array type
00131     char padding[(8-(sizeof(envelope)+sizeof(NodeID)+sizeof(PatchID)+sizeof(int)*Results::maxNumForces+2*sizeof(void *))%8)%8];   
00132 
00133     //The length of "fls" is Results::maxNumForces
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     //For debug
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   //since this msg may be processed by comm thread in the smp mode,
00155   //this variable helps comm thread to find which proc will actually process it.
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 {       // keep track of the spanning trees
00193   public:
00194     int proxyMsgCount;
00195     NodeIDList *proxylist;
00196 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00197     //a node-aware spanning tree array, each element of which
00198     //is a spanning tree for all proxies of a patch
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   //set the proxy patch's parent field
00257   void recvNodeAwareSTParent(int patch, int parent);
00258 
00259   void buildProxySpanningTree2();               // centralized version
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; //a charm Group variable
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 /* PATCHMGR_H */
00353 

Generated on Fri Sep 5 04:07:15 2008 for NAMD by  doxygen 1.3.9.1