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   //atomCnt is the number of atoms patch pid has
00157   void preCreateHomePatch(PatchID pid, int atomCnt);
00158 
00159   void movePatch(PatchID, NodeID);
00160   void sendMovePatches();
00161   void recvMovePatches(MovePatchesMsg *msg);
00162 
00163   void sendAtoms(PatchID pid, FullAtomList &a);
00164   void recvAtoms(MovePatchesMsg *msg);
00165 
00166   // void ackMovePatches(AckMovePatchesMsg *msg);
00167 
00168   HomePatch *homePatch(PatchID pid) {
00169      return homePatches.find(HomePatchElem(pid))->patch;
00170   } 
00171 
00172   // void sendMigrationMsg(PatchID, MigrationInfo);
00173   void sendMigrationMsgs(PatchID, MigrationInfo*, int);
00174   // void recvMigrateAtoms(MigrateAtomsMsg *);
00175   void recvMigrateAtomsCombined(MigrateAtomsCombinedMsg *);
00176 
00177   void moveAtom(MoveAtomMsg *msg);
00178   void moveAllBy(MoveAllByMsg *msg);
00179   void setLattice(SetLatticeMsg *msg);
00180 
00181   void sendCheckpointReq(int pid, int remote, const char *key, int task);
00182   void recvCheckpointReq(CheckpointAtomsReqMsg *msg);
00183   void sendCheckpointLoad(CheckpointAtomsMsg *msg, int dst, int dstpe);
00184   void recvCheckpointLoad(CheckpointAtomsMsg *msg);
00185   void sendCheckpointStore(CheckpointAtomsMsg *msg, int dst, int dstpe);
00186   void recvCheckpointStore(CheckpointAtomsMsg *msg);
00187   void sendCheckpointAck(int pid, int dst, int dstpe);
00188   void recvCheckpointAck(CheckpointAtomsReqMsg *msg);
00189 
00190   void sendExchangeReq(int pid, int src);
00191   void recvExchangeReq(ExchangeAtomsReqMsg *msg);
00192   void sendExchangeMsg(ExchangeAtomsMsg *msg, int dst, int dstpe);
00193   void recvExchangeMsg(ExchangeAtomsMsg *msg);
00194 
00195 private:
00196   friend class PatchMap;
00197   PatchMap *patchMap;
00198 
00199   int numAllPatches;
00200   int numHomePatches;
00201 
00202   int recvCheckpointReq_index;
00203   int recvCheckpointLoad_index;
00204   int recvCheckpointStore_index;
00205   int recvCheckpointAck_index;
00206 
00207   int recvExchangeReq_index;
00208   int recvExchangeMsg_index;
00209 
00210   // an array of patch pointers residing on this node
00211   HomePatchList homePatches;
00212 
00213   // an array of patches to move off this node
00214   MovePatchList move;
00215   int ackMovePending;
00216 
00217   // data for combining migration messages
00218   MigrateAtomsCombinedMsg ** combineMigrationMsgs;
00219   ResizeArray<int> combineMigrationDestPes;
00220   int migrationCountdown;
00221 
00222 public:
00223   void setHomePatchFixedAtomNum(int patchId, int numFixed){
00224       HomePatch *thisHomePatch = patchMap->homePatch(patchId);
00225       thisHomePatch->setNumFixedAtoms(numFixed);
00226   }
00227 
00228   void sendOneHomePatch(int patchId, int nodeId);
00229 };
00230 
00231 
00232 
00233 #endif /* PATCHMGR_H */
00234 

Generated on Sat Sep 23 01:17:15 2017 for NAMD by  doxygen 1.4.7