NAMD
PatchMgr.h
Go to the documentation of this file.
1 
7 /*****************************************************************************
8  * $Source: /home/cvs/namd/cvsroot/namd2/src/PatchMgr.h,v $
9  * $Author: jim $
10  * $Date: 2015/03/03 17:54:14 $
11  * $Revision: 1.1032 $
12  *****************************************************************************/
13 
14 #ifndef PATCHMGR_H
15 #define PATCHMGR_H
16 
17 #include "charm++.h"
18 
19 #include "NamdTypes.h"
20 #include "SortedArray.h"
21 #include "HomePatch.h"
22 #include "HomePatchList.h"
23 #include "BOCgroup.h"
24 #include "Migration.h"
25 #include "MigrateAtomsMsg.h"
26 #include "PatchMgr.decl.h"
27 
28 #if USE_TOPOMAP
29 #include "TopoManager.h"
30 #endif
31 
32 class HomePatch;
33 
34 class MovePatchesMsg : public CMessage_MovePatchesMsg {
35 public:
39 
40  MovePatchesMsg(void) { ; }
41 
43  {
44  atom.swap(a);
45  fromNodeID = CkMyPe();
46  }
47 
48  // pack and unpack functions
49  static void* pack(MovePatchesMsg *msg);
50  static MovePatchesMsg* unpack(void *ptr);
51 };
52 
53 class MoveAtomMsg : public CMessage_MoveAtomMsg {
54 public:
55  int atomid;
56  int moveto;
58 };
59 
60 class MoveAllByMsg : public CMessage_MoveAllByMsg {
61 public:
63 };
64 
65 class SetLatticeMsg : public CMessage_SetLatticeMsg {
66 public:
68 };
69 
70 
71 class CheckpointAtomsReqMsg : public CMessage_CheckpointAtomsReqMsg {
72 public:
73  int task;
74  int pid;
75  int replica;
76  int pe;
77  char *key;
78 };
79 
80 class CheckpointAtomsMsg : public CMessage_CheckpointAtomsMsg {
81 public:
83  int task;
84  int pid;
85  int replica;
86  int pe;
88  int numAtoms;
90  char *key;
91 };
92 
93 extern "C" {
94  void recvCheckpointReq_handler(envelope*);
95  void recvCheckpointLoad_handler(envelope*);
96  void recvCheckpointStore_handler(envelope*);
97  void recvCheckpointAck_handler(envelope*);
98 }
99 
100 
101 class ExchangeAtomsReqMsg : public CMessage_ExchangeAtomsReqMsg {
102 public:
103  int pid;
104  int dstpe;
105 };
106 
107 class ExchangeAtomsMsg : public CMessage_ExchangeAtomsMsg {
108 public:
110  int pid;
111  int numAtoms;
113 };
114 
115 extern "C" {
116  void recvExchangeReq_handler(envelope*);
117  void recvExchangeMsg_handler(envelope*);
118 }
119 
120 // PatchMgr creates and manages homepatches. There exist one instance of
121 // PatchMgr on each node (derived from Charm++ Group). // That is, when a new operator causes creation of one instance on each node.
122 // In addition to creation of homepatches, it handles the atom redistribution
123 // at the end of each cycle (i.e., atoms can move from patch to patch at the
124 // cycle boundaries).
125 struct MovePatch
126 {
127  MovePatch(PatchID p=-1, NodeID n=-1) : nodeID(n), pid(p) {};
129 
130  NodeID nodeID;
132 
134  return ( nodeID < m.nodeID );
135  }
136 
138  return ( nodeID == m.nodeID );
139  }
140 };
141 
144 
145 class PatchMgr : public CBase_PatchMgr
146 {
147 
148 public:
149  PatchMgr();
150  ~PatchMgr();
151 
152  static PatchMgr* Object() { return CkpvAccess(PatchMgr_instance); }
153 
154  void createHomePatch(PatchID pid, FullAtomList &a);
155 
156  void movePatch(PatchID, NodeID);
157  void sendMovePatches();
158  void recvMovePatches(MovePatchesMsg *msg);
159 
160  void sendAtoms(PatchID pid, FullAtomList &a);
161  void recvAtoms(MovePatchesMsg *msg);
162 
163  // void ackMovePatches(AckMovePatchesMsg *msg);
164 
166  return homePatches.find(HomePatchElem(pid))->patch;
167  }
168 
169  // void sendMigrationMsg(PatchID, MigrationInfo);
171  // void recvMigrateAtoms(MigrateAtomsMsg *);
173 
174  void moveAtom(MoveAtomMsg *msg);
175  void moveAllBy(MoveAllByMsg *msg);
176  void setLattice(SetLatticeMsg *msg);
177 
178  void sendCheckpointReq(int pid, int remote, const char *key, int task);
180  void sendCheckpointLoad(CheckpointAtomsMsg *msg, int dst, int dstpe);
182  void sendCheckpointStore(CheckpointAtomsMsg *msg, int dst, int dstpe);
184  void sendCheckpointAck(int pid, int dst, int dstpe);
186 
187  void sendExchangeReq(int pid, int src);
189  void sendExchangeMsg(ExchangeAtomsMsg *msg, int dst, int dstpe);
191 
192 private:
193  friend class PatchMap;
194  PatchMap *patchMap;
195 
196  int numAllPatches;
197  int numHomePatches;
198 
199  int recvCheckpointReq_index;
200  int recvCheckpointLoad_index;
201  int recvCheckpointStore_index;
202  int recvCheckpointAck_index;
203 
204  int recvExchangeReq_index;
205  int recvExchangeMsg_index;
206 
207  // an array of patch pointers residing on this node
208  HomePatchList homePatches;
209 
210  // an array of patches to move off this node
211  MovePatchList move;
212  int ackMovePending;
213 
214  // data for combining migration messages
215  MigrateAtomsCombinedMsg ** combineMigrationMsgs;
216  ResizeArray<int> combineMigrationDestPes;
217  int migrationCountdown;
218 
219 public:
220  void setHomePatchFixedAtomNum(int patchId, int numFixed){
221  HomePatch *thisHomePatch = patchMap->homePatch(patchId);
222  thisHomePatch->setNumFixedAtoms(numFixed);
223  }
224 
225  void sendOneHomePatch(int patchId, int nodeId);
226 };
227 
228 
229 
230 #endif /* PATCHMGR_H */
231 
~MovePatch()
Definition: PatchMgr.h:128
SortedArray< MovePatch > MovePatchList
Definition: PatchMgr.h:142
NodeID nodeID
Definition: PatchMgr.h:128
void recvCheckpointReq_handler(envelope *env)
Definition: PatchMgr.C:288
void setHomePatchFixedAtomNum(int patchId, int numFixed)
Definition: PatchMgr.h:220
Definition: Vector.h:64
void sendOneHomePatch(int patchId, int nodeId)
Definition: PatchMgr.C:89
void recvExchangeReq_handler(envelope *env)
Definition: PatchMgr.C:400
void createHomePatch(PatchID pid, FullAtomList &a)
Definition: PatchMgr.C:74
void sendAtoms(PatchID pid, FullAtomList &a)
Definition: PatchMgr.C:157
void recvExchangeMsg(ExchangeAtomsMsg *msg)
Definition: PatchMgr.C:433
void sendExchangeReq(int pid, int src)
Definition: PatchMgr.C:386
int atomid
Definition: PatchMgr.h:55
void recvExchangeReq(ExchangeAtomsReqMsg *msg)
Definition: PatchMgr.C:405
HomePatch * homePatch(PatchID pid)
Definition: PatchMap.h:240
FullAtomList atom
Definition: PatchMgr.h:38
FullAtom * atoms
Definition: PatchMgr.h:89
void movePatch(PatchID, NodeID)
Definition: PatchMgr.C:84
Vector offset
Definition: PatchMgr.h:62
MovePatchesMsg(void)
Definition: PatchMgr.h:40
void sendCheckpointAck(int pid, int dst, int dstpe)
Definition: PatchMgr.C:358
void recvCheckpointLoad(CheckpointAtomsMsg *msg)
Definition: PatchMgr.C:326
void recvCheckpointStore(CheckpointAtomsMsg *msg)
Definition: PatchMgr.C:351
PatchID pid
Definition: PatchMgr.h:37
MovePatchesMsg(PatchID n, FullAtomList &a)
Definition: PatchMgr.h:42
Lattice lattice
Definition: PatchMgr.h:109
int operator==(MovePatch m)
Definition: PatchMgr.h:137
ResizeArrayIter< MovePatch > MovePatchListIter
Definition: PatchMgr.h:143
void recvAtoms(MovePatchesMsg *msg)
Definition: PatchMgr.C:168
void recvMigrateAtomsCombined(MigrateAtomsCombinedMsg *)
Definition: PatchMgr.C:219
PatchID pid
Definition: PatchMgr.h:131
MovePatch(PatchID p=-1, NodeID n=-1)
Definition: PatchMgr.h:127
void sendMovePatches()
Definition: PatchMgr.C:110
NodeID fromNodeID
Definition: PatchMgr.h:36
void recvCheckpointLoad_handler(envelope *env)
Definition: PatchMgr.C:320
void setNumFixedAtoms(int numFixed)
Definition: Patch.h:113
void sendMigrationMsgs(PatchID, MigrationInfo *, int)
Definition: PatchMgr.C:175
int moveto
Definition: PatchMgr.h:56
void setLattice(SetLatticeMsg *msg)
Definition: PatchMgr.C:258
int PatchID
Definition: NamdTypes.h:182
void recvCheckpointAck_handler(envelope *env)
Definition: PatchMgr.C:372
int berendsenPressure_count
Definition: PatchMgr.h:87
void sendCheckpointLoad(CheckpointAtomsMsg *msg, int dst, int dstpe)
Definition: PatchMgr.C:308
void moveAtom(MoveAtomMsg *msg)
Definition: PatchMgr.C:226
int operator<(MovePatch m)
Definition: PatchMgr.h:133
void swap(ResizeArray< Elem > &ra)
Definition: ResizeArray.h:64
void recvCheckpointAck(CheckpointAtomsReqMsg *msg)
Definition: PatchMgr.C:378
void recvCheckpointStore_handler(envelope *env)
Definition: PatchMgr.C:345
int numHomePatches(void)
Definition: PatchMap.C:432
~PatchMgr()
Definition: PatchMgr.C:64
void moveAllBy(MoveAllByMsg *msg)
Definition: PatchMgr.C:244
Elem * find(const Elem &elem)
static MovePatchesMsg * unpack(void *ptr)
static void * pack(MovePatchesMsg *msg)
Lattice lattice
Definition: PatchMgr.h:82
HomePatch * homePatch(PatchID pid)
Definition: PatchMgr.h:165
PatchMgr()
Definition: PatchMgr.C:34
FullAtom * atoms
Definition: PatchMgr.h:112
int NodeID
Definition: NamdTypes.h:184
void sendCheckpointStore(CheckpointAtomsMsg *msg, int dst, int dstpe)
Definition: PatchMgr.C:333
Lattice lattice
Definition: PatchMgr.h:67
void recvCheckpointReq(CheckpointAtomsReqMsg *msg)
Definition: PatchMgr.C:294
void sendCheckpointReq(int pid, int remote, const char *key, int task)
Definition: PatchMgr.C:270
static PatchMgr * Object()
Definition: PatchMgr.h:152
void recvExchangeMsg_handler(envelope *env)
Definition: PatchMgr.C:428
Vector coord
Definition: PatchMgr.h:57
void sendExchangeMsg(ExchangeAtomsMsg *msg, int dst, int dstpe)
Definition: PatchMgr.C:417
void recvMovePatches(MovePatchesMsg *msg)
Definition: PatchMgr.C:137