PatchMgr.h

Go to the documentation of this file.
00001 
00007 /*****************************************************************************
00008  * $Source: /home/cvs/namd/cvsroot/namd2/src/PatchMgr.h,v $
00009  * $Author: jim $
00010  * $Date: 2015/03/03 17:54:14 $
00011  * $Revision: 1.1032 $
00012  *****************************************************************************/
00013 
00014 #ifndef PATCHMGR_H
00015 #define PATCHMGR_H
00016 
00017 #include "charm++.h"
00018 
00019 #include "NamdTypes.h"
00020 #include "SortedArray.h"
00021 #include "HomePatch.h"
00022 #include "HomePatchList.h"
00023 #include "BOCgroup.h"
00024 #include "Migration.h"
00025 #include "MigrateAtomsMsg.h"
00026 #include "PatchMgr.decl.h"
00027 
00028 #if USE_TOPOMAP 
00029 #include "TopoManager.h"
00030 #endif
00031 
00032 class HomePatch;
00033 
00034 class MovePatchesMsg : public CMessage_MovePatchesMsg {
00035 public:
00036     NodeID  fromNodeID;
00037     PatchID pid;
00038     FullAtomList atom;
00039 
00040     MovePatchesMsg(void) { ; }
00041 
00042     MovePatchesMsg(PatchID n, FullAtomList &a) : pid(n)
00043     {
00044       atom.swap(a);
00045       fromNodeID = CkMyPe();
00046     }
00047 
00048   // pack and unpack functions
00049   static void* pack(MovePatchesMsg *msg);
00050   static MovePatchesMsg* unpack(void *ptr);
00051 };
00052 
00053 class MoveAtomMsg : public CMessage_MoveAtomMsg {
00054 public:
00055   int atomid;
00056   int moveto;
00057   Vector coord;
00058 };
00059 
00060 class MoveAllByMsg : public CMessage_MoveAllByMsg {
00061 public:
00062   Vector offset;
00063 };
00064 
00065 class SetLatticeMsg : public CMessage_SetLatticeMsg {
00066 public:
00067   Lattice lattice;
00068 };
00069 
00070 
00071 class CheckpointAtomsReqMsg : public CMessage_CheckpointAtomsReqMsg {
00072 public:
00073   int task;
00074   int pid;
00075   int replica;
00076   int pe;
00077   char *key;
00078 };
00079 
00080 class CheckpointAtomsMsg : public CMessage_CheckpointAtomsMsg {
00081 public:
00082   Lattice lattice;
00083   int task;
00084   int pid;
00085   int replica;
00086   int pe;
00087   int berendsenPressure_count;
00088   int numAtoms;
00089   FullAtom *atoms;
00090   char *key;
00091 };
00092 
00093 extern "C" {
00094   void recvCheckpointReq_handler(envelope*);
00095   void recvCheckpointLoad_handler(envelope*);
00096   void recvCheckpointStore_handler(envelope*);
00097   void recvCheckpointAck_handler(envelope*);
00098 }
00099 
00100 
00101 class ExchangeAtomsReqMsg : public CMessage_ExchangeAtomsReqMsg {
00102 public:
00103   int pid;
00104   int dstpe;
00105 };
00106 
00107 class ExchangeAtomsMsg : public CMessage_ExchangeAtomsMsg {
00108 public:
00109   Lattice lattice;
00110   int pid;
00111   int numAtoms;
00112   FullAtom *atoms;
00113 };
00114 
00115 extern "C" {
00116   void recvExchangeReq_handler(envelope*);
00117   void recvExchangeMsg_handler(envelope*);
00118 }
00119 
00120 // PatchMgr creates and manages homepatches. There exist one instance of 
00121 // PatchMgr on each node (derived from Charm++ Group).  // That is, when a new operator causes creation of one instance on each node. 
00122 // In addition to creation of homepatches, it handles the atom redistribution
00123 // at the end of each cycle (i.e., atoms can move from patch to patch at the
00124 // cycle boundaries).
00125 struct MovePatch 
00126 {
00127     MovePatch(PatchID p=-1, NodeID n=-1) : nodeID(n), pid(p) {};
00128     ~MovePatch() {};
00129 
00130     NodeID nodeID;
00131     PatchID pid;
00132 
00133     int operator<(MovePatch m) {
00134       return ( nodeID < m.nodeID );
00135     }
00136 
00137     int operator==(MovePatch m) {
00138       return ( nodeID == m.nodeID );
00139     }
00140 };
00141 
00142 typedef SortedArray<MovePatch> MovePatchList;
00143 typedef ResizeArrayIter<MovePatch> MovePatchListIter;
00144 
00145 class PatchMgr : public CBase_PatchMgr
00146 {
00147 
00148 public:
00149   PatchMgr();
00150   ~PatchMgr();
00151 
00152   static PatchMgr* Object() { return CkpvAccess(PatchMgr_instance); }
00153   
00154   void createHomePatch(PatchID pid, FullAtomList &a);
00155 
00156   void movePatch(PatchID, NodeID);
00157   void sendMovePatches();
00158   void recvMovePatches(MovePatchesMsg *msg);
00159 
00160   void sendAtoms(PatchID pid, FullAtomList &a);
00161   void recvAtoms(MovePatchesMsg *msg);
00162 
00163   // void ackMovePatches(AckMovePatchesMsg *msg);
00164 
00165   HomePatch *homePatch(PatchID pid) {
00166      return homePatches.find(HomePatchElem(pid))->patch;
00167   } 
00168 
00169   // void sendMigrationMsg(PatchID, MigrationInfo);
00170   void sendMigrationMsgs(PatchID, MigrationInfo*, int);
00171   // void recvMigrateAtoms(MigrateAtomsMsg *);
00172   void recvMigrateAtomsCombined(MigrateAtomsCombinedMsg *);
00173 
00174   void moveAtom(MoveAtomMsg *msg);
00175   void moveAllBy(MoveAllByMsg *msg);
00176   void setLattice(SetLatticeMsg *msg);
00177 
00178   void sendCheckpointReq(int pid, int remote, const char *key, int task);
00179   void recvCheckpointReq(CheckpointAtomsReqMsg *msg);
00180   void sendCheckpointLoad(CheckpointAtomsMsg *msg, int dst, int dstpe);
00181   void recvCheckpointLoad(CheckpointAtomsMsg *msg);
00182   void sendCheckpointStore(CheckpointAtomsMsg *msg, int dst, int dstpe);
00183   void recvCheckpointStore(CheckpointAtomsMsg *msg);
00184   void sendCheckpointAck(int pid, int dst, int dstpe);
00185   void recvCheckpointAck(CheckpointAtomsReqMsg *msg);
00186 
00187   void sendExchangeReq(int pid, int src);
00188   void recvExchangeReq(ExchangeAtomsReqMsg *msg);
00189   void sendExchangeMsg(ExchangeAtomsMsg *msg, int dst, int dstpe);
00190   void recvExchangeMsg(ExchangeAtomsMsg *msg);
00191 
00192 private:
00193   friend class PatchMap;
00194   PatchMap *patchMap;
00195 
00196   int numAllPatches;
00197   int numHomePatches;
00198 
00199   int recvCheckpointReq_index;
00200   int recvCheckpointLoad_index;
00201   int recvCheckpointStore_index;
00202   int recvCheckpointAck_index;
00203 
00204   int recvExchangeReq_index;
00205   int recvExchangeMsg_index;
00206 
00207   // an array of patch pointers residing on this node
00208   HomePatchList homePatches;
00209 
00210   // an array of patches to move off this node
00211   MovePatchList move;
00212   int ackMovePending;
00213 
00214   // data for combining migration messages
00215   MigrateAtomsCombinedMsg ** combineMigrationMsgs;
00216   ResizeArray<int> combineMigrationDestPes;
00217   int migrationCountdown;
00218 
00219 public:
00220   void setHomePatchFixedAtomNum(int patchId, int numFixed){
00221       HomePatch *thisHomePatch = patchMap->homePatch(patchId);
00222       thisHomePatch->setNumFixedAtoms(numFixed);
00223   }
00224 
00225   void sendOneHomePatch(int patchId, int nodeId);
00226 };
00227 
00228 
00229 
00230 #endif /* PATCHMGR_H */
00231 

Generated on Tue May 22 01:17:15 2018 for NAMD by  doxygen 1.4.7