NAMD
ComputeMap.h
Go to the documentation of this file.
1 
7 #ifndef COMPUTEMAP_H
8 #define COMPUTEMAP_H
9 
10 #include "NamdTypes.h"
11 #include "ProcessorPrivate.h"
12 #include "ResizeArray.h"
13 
14 class Compute;
15 class ComputeMgr;
16 class MIStream;
17 class MOStream;
18 template<class Type> class ObjectArena;
19 
21 {
34  // JLai
37  // End of JLai entry
46 #ifdef DPMTA
47  computeDPMTAType,
48 #endif
49 #ifdef DPME
50  computeDPMEType,
51 #endif
53 #ifdef NAMD_CUDA
56 #ifdef BONDED_CUDA
57  computeBondedCUDAType,
58 #endif
59 #endif
72 /* BEGIN gf */
74 /* END gf */
83 };
84 
86 {
87 public:
88  static ComputeMap *Instance();
89  inline static ComputeMap *Object() { return instance; }
90 
91  void checkMap();
92 
93  ~ComputeMap(void);
94 
96  computePtrs[cid] = c;
97  }
98 
99  // numComputes() returns the number of compute objects known
100  // by the map.
101  inline int numComputes(void) {
102  return nComputes;
103  }
104 
105  // node(cid) returns the node where the compute object currently exists.
106  inline int node(ComputeID cid) {
107  return computeData[cid].node;
108  }
109 
110  inline void setNode(ComputeID cid, NodeID node) {
111  computeData[cid].node = node;
112  }
113 
114  // newNode(cid,node) sets up map to tell WorkDistrib to send
115  // compute to new node
116  inline NodeID newNode(ComputeID cid) {
117  return (computeData[cid].moveToNode);
118  }
119 
120  inline void setNewNode(ComputeID cid, NodeID node) {
121  computeData[cid].moveToNode = node;
122  }
123 
124  // numPids(cid) returns the number of patch ids which are registered
125  // with this compute object.
126  int numPids(ComputeID cid);
127 
128  // pid(cid,i) returns the i-th patch id registered
129  // with the patch.
130  int pid(ComputeID cid, int i);
131  int trans(ComputeID cid, int i);
132 
133  // type(cid) returns the compute type of the given ComputeID
135  int partition(ComputeID cid);
136  int numPartitions(ComputeID cid);
137 
138  inline void setNumPartitions(ComputeID cid, char numPartitions) {
139  computeData[cid].numPartitions = numPartitions;
140  }
141  inline char newNumPartitions(ComputeID cid) {
142  return (computeData[cid].newNumPartitions);
143  }
144  inline void setNewNumPartitions(ComputeID cid, char numPartitions) {
145  computeData[cid].newNumPartitions = numPartitions;
146  }
147 
148  int allocateCids();
149 
150  // storeCompute(cid,node,maxPids) tells the ComputeMap to store
151  // information about the indicated patch, and allocate space
152  // for up to maxPids dependents
153  ComputeID storeCompute(int node,int maxPids,ComputeType type,
154  int partition=-1, int numPartitions=0);
155 
156  // newPid(cid,pid) stores the n patch ids associated with
157  // compute id cid.
158  void newPid(ComputeID cid, int pid, int trans = 13);
159 
160  #if defined(NAMD_MIC)
161  void setDirectToDevice(const ComputeID cid, const int d);
162  int directToDevice(const ComputeID cid) const;
163  #endif
164 
166 
167  void printComputeMap(void);
168  void saveComputeMap(const char *fname);
169  void loadComputeMap(const char *fname);
170 
171  Compute *compute(ComputeID cid) { return computePtrs[cid]; };
172 
173  friend class ComputeMgr;
174 
175  struct PatchRec
176  {
178  int trans;
179 
180  PatchRec() : pid(-1), trans(-1) { ; }
181  };
182 
183  enum { numPidsAllocated=8 };
184 
185  struct ComputeData
186  {
188  node = -1; moveToNode = -1;
189  newNumPartitions = 0;
190  numPids = 0;
191  #if defined(NAMD_MIC)
192  directToDevice = 0;
193  #endif
194  }
195  int node;
198  char partition;
201  char numPids;
203  #if defined(NAMD_MIC)
204  char directToDevice;
205  #endif
206  };
207 protected:
208  friend class WorkDistrib;
209  void pack(MOStream *msg);
210  void unpack(MIStream *msg);
211  void initPtrs();
212  void extendPtrs();
213 
214  ComputeMap(void);
215 
216 private:
217  int nComputes;
218  ResizeArray<ComputeData> computeData;
219  Compute **computePtrs;
220 
221  static ComputeMap *instance;
222 };
223 
224 #endif /* COMPUTEMAP_H */
225 
void checkMap()
Definition: ComputeMap.C:48
void setNewNumPartitions(ComputeID cid, char numPartitions)
Definition: ComputeMap.h:144
int numComputes(void)
Definition: ComputeMap.h:101
void saveComputeMap(const char *fname)
Definition: ComputeMap.C:262
int ComputeID
Definition: NamdTypes.h:183
void initPtrs()
Definition: ComputeMap.C:82
ComputeType
Definition: ComputeMap.h:20
void registerCompute(ComputeID cid, Compute *c)
Definition: ComputeMap.h:95
void loadComputeMap(const char *fname)
Definition: ComputeMap.C:278
void setNumPartitions(ComputeID cid, char numPartitions)
Definition: ComputeMap.h:138
ComputeID storeCompute(int node, int maxPids, ComputeType type, int partition=-1, int numPartitions=0)
Definition: ComputeMap.C:153
void setNode(ComputeID cid, NodeID node)
Definition: ComputeMap.h:110
int allocateCids()
Definition: ComputeMap.C:143
char newNumPartitions(ComputeID cid)
Definition: ComputeMap.h:141
void printComputeMap(void)
Definition: ComputeMap.C:206
~ComputeMap(void)
Definition: ComputeMap.C:42
ComputeType type(ComputeID cid)
Definition: ComputeMap.C:120
void pack(MOStream *msg)
Definition: ComputeMap.C:63
int numPartitions(ComputeID cid)
Definition: ComputeMap.C:135
int PatchID
Definition: NamdTypes.h:182
void setNewNode(ComputeID cid, NodeID node)
Definition: ComputeMap.h:120
int partition(ComputeID cid)
Definition: ComputeMap.C:128
void extendPtrs()
Definition: ComputeMap.C:89
static ComputeMap * Instance()
Definition: ComputeMap.C:26
void newPid(ComputeID cid, int pid, int trans=13)
Definition: ComputeMap.C:198
Compute * compute(ComputeID cid)
Definition: ComputeMap.h:171
ComputeID cloneCompute(ComputeID src, int partition)
Definition: ComputeMap.C:185
static ComputeMap * Object()
Definition: ComputeMap.h:89
int node(ComputeID cid)
Definition: ComputeMap.h:106
int numPids(ComputeID cid)
Definition: ComputeMap.C:103
PatchRec pids[numPidsAllocated]
Definition: ComputeMap.h:202
int pid(ComputeID cid, int i)
Definition: ComputeMap.C:109
int trans(ComputeID cid, int i)
Definition: ComputeMap.C:114
void unpack(MIStream *msg)
Definition: ComputeMap.C:70
int NodeID
Definition: NamdTypes.h:184
ComputeMap(void)
Definition: ComputeMap.C:35
NodeID newNode(ComputeID cid)
Definition: ComputeMap.h:116