NAMD
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
ComputeMap Class Reference

#include <ComputeMap.h>

Classes

struct  ComputeData
 
struct  PatchRec
 

Public Types

enum  { numPidsAllocated =8 }
 

Public Member Functions

void checkMap ()
 
 ~ComputeMap (void)
 
void registerCompute (ComputeID cid, Compute *c)
 
int numComputes (void)
 
int node (ComputeID cid)
 
void setNode (ComputeID cid, NodeID node)
 
NodeID newNode (ComputeID cid)
 
void setNewNode (ComputeID cid, NodeID node)
 
int numPids (ComputeID cid)
 
int pid (ComputeID cid, int i)
 
int trans (ComputeID cid, int i)
 
ComputeType type (ComputeID cid)
 
int partition (ComputeID cid)
 
int numPartitions (ComputeID cid)
 
void setNumPartitions (ComputeID cid, char numPartitions)
 
char newNumPartitions (ComputeID cid)
 
void setNewNumPartitions (ComputeID cid, char numPartitions)
 
int allocateCids ()
 
ComputeID storeCompute (int node, int maxPids, ComputeType type, int partition=-1, int numPartitions=0)
 
void newPid (ComputeID cid, int pid, int trans=13)
 
ComputeID cloneCompute (ComputeID src, int partition)
 
void printComputeMap (void)
 
void saveComputeMap (const char *fname)
 
void loadComputeMap (const char *fname)
 
Computecompute (ComputeID cid)
 

Static Public Member Functions

static ComputeMapInstance ()
 
static ComputeMapObject ()
 

Protected Member Functions

void pack (MOStream *msg)
 
void unpack (MIStream *msg)
 
void initPtrs ()
 
void extendPtrs ()
 
 ComputeMap (void)
 

Friends

class ComputeMgr
 
class WorkDistrib
 

Detailed Description

Definition at line 85 of file ComputeMap.h.

Member Enumeration Documentation

anonymous enum
Enumerator
numPidsAllocated 

Definition at line 183 of file ComputeMap.h.

Constructor & Destructor Documentation

ComputeMap::~ComputeMap ( void  )

Definition at line 42 of file ComputeMap.C.

43 {
44  delete [] computePtrs;
45 }
ComputeMap::ComputeMap ( void  )
protected

Definition at line 35 of file ComputeMap.C.

Referenced by Instance().

36 {
37  nComputes=0;
38  computePtrs=0;
39 }

Member Function Documentation

int ComputeMap::allocateCids ( )

Definition at line 143 of file ComputeMap.C.

Referenced by WorkDistrib::mapComputes().

144 {
145  nComputes = 0;
146  computeData.resize(500);
147  computeData.resize(0);
148 
149  return 0;
150 }
void ComputeMap::checkMap ( void  )

Definition at line 48 of file ComputeMap.C.

References DebugM.

Referenced by ComputeMgr::updateLocalComputes5().

49 {
50  int computeCount = nComputes;
51  for (int i=0; i<nComputes; i++) {
52  if (computePtrs[i]) {
53  computeCount++;
54  if (! (computePtrs[i]->cid == i)) {
55  DebugM(4, "ComputeID("<<computePtrs[i]->cid<<") != ComputeID("
56  << i <<")\n");
57  }
58  }
59  }
60  DebugM(4, "Compute Count = " << computeCount << "\n");
61 }
#define DebugM(x, y)
Definition: Debug.h:59
ComputeID ComputeMap::cloneCompute ( ComputeID  src,
int  partition 
)

Definition at line 185 of file ComputeMap.C.

References partition().

Referenced by ComputeMgr::splitComputes().

186 {
187  const int cid = computeData.size();
188  computeData.resize(cid+1);
189 
190  computeData[cid] = computeData[src];
191  computeData[cid].partition = partition;
192  computeData[cid].node = -1;
193 
194  return cid;
195 }
int partition(ComputeID cid)
Definition: ComputeMap.C:128
Compute* ComputeMap::compute ( ComputeID  cid)
inline

Definition at line 171 of file ComputeMap.h.

Referenced by LdbCoordinator::initialize(), and ComputeMgr::updateLocalComputes().

171 { return computePtrs[cid]; };
void ComputeMap::extendPtrs ( )
protected

Definition at line 89 of file ComputeMap.C.

References NAMD_bug().

Referenced by ComputeMgr::splitComputes().

89  {
90  if ( ! computePtrs ) NAMD_bug("ComputeMap::extendPtrs() 1");
91  int oldN = nComputes;
92  nComputes = computeData.size();
93  if ( nComputes > oldN ) {
94  Compute **oldPtrs = computePtrs;
95  computePtrs = new Compute*[nComputes];
96  memcpy(computePtrs, oldPtrs, oldN*sizeof(Compute*));
97  memset(computePtrs+oldN, 0, (nComputes-oldN)*sizeof(Compute*));
98  delete [] oldPtrs;
99  }
100 }
void NAMD_bug(const char *err_msg)
Definition: common.C:123
void ComputeMap::initPtrs ( )
protected

Definition at line 82 of file ComputeMap.C.

Referenced by WorkDistrib::sendComputeMap().

82  {
83  if ( ! computePtrs ) {
84  computePtrs = new Compute*[nComputes];
85  memset(computePtrs, 0, nComputes*sizeof(Compute*));
86  }
87 }
ComputeMap * ComputeMap::Instance ( )
static

Definition at line 26 of file ComputeMap.C.

References ComputeMap().

Referenced by Node::Node().

26  {
27  if (instance == 0) {
28  instance = new ComputeMap; // this is never deleted
29  }
30  return instance;
31 }
ComputeMap(void)
Definition: ComputeMap.C:35
void ComputeMap::loadComputeMap ( const char *  fname)

Definition at line 278 of file ComputeMap.C.

References node().

Referenced by WorkDistrib::mapComputes().

279 {
280  FILE *fp = fopen(fname, "r");
281  CmiAssert(fp != NULL);
282  int n;
283  fscanf(fp, "%d\n", &n);
284  CmiAssert(n == nComputes);
285  for(int i=0; i < nComputes; i++)
286  {
287  fscanf(fp, "%d\n", &computeData[i].node);
288  }
289  fclose(fp);
290 }
int node(ComputeID cid)
Definition: ComputeMap.h:106
NodeID ComputeMap::newNode ( ComputeID  cid)
inline

Definition at line 116 of file ComputeMap.h.

Referenced by WorkDistrib::recvComputeMapChanges(), ComputeMgr::splitComputes(), ComputeMgr::updateLocalComputes(), and ComputeMgr::updateLocalComputes3().

116  {
117  return (computeData[cid].moveToNode);
118  }
char ComputeMap::newNumPartitions ( ComputeID  cid)
inline

Definition at line 141 of file ComputeMap.h.

Referenced by WorkDistrib::recvComputeMapChanges(), ComputeMgr::splitComputes(), and ComputeMgr::updateLocalComputes().

141  {
142  return (computeData[cid].newNumPartitions);
143  }
char newNumPartitions(ComputeID cid)
Definition: ComputeMap.h:141
void ComputeMap::newPid ( ComputeID  cid,
int  pid,
int  trans = 13 
)

Definition at line 198 of file ComputeMap.C.

References pid(), and trans().

199 {
200  computeData[cid].pids[computeData[cid].numPids].pid=pid;
201  computeData[cid].pids[computeData[cid].numPids].trans=trans;
202  computeData[cid].numPids++;
203 }
int pid(ComputeID cid, int i)
Definition: ComputeMap.C:109
int trans(ComputeID cid, int i)
Definition: ComputeMap.C:114
int ComputeMap::node ( ComputeID  cid)
inline
int ComputeMap::numComputes ( void  )
inline
int ComputeMap::numPartitions ( ComputeID  cid)

Definition at line 135 of file ComputeMap.C.

References computeErrorType.

Referenced by setNewNumPartitions(), setNumPartitions(), ComputeMgr::splitComputes(), storeCompute(), and NamdCentLB::Strategy().

136 {
137  if (nComputes)
138  return computeData[cid].numPartitions;
139  else return computeErrorType;
140 }
int ComputeMap::numPids ( ComputeID  cid)

Definition at line 103 of file ComputeMap.C.

Referenced by ProxyMgr::createProxies(), LdbCoordinator::initialize(), printComputeMap(), and ComputeMgr::updateLocalComputes().

104 {
105  return computeData[cid].numPids;
106 }
static ComputeMap* ComputeMap::Object ( )
inlinestatic
void ComputeMap::pack ( MOStream msg)
protected

Definition at line 63 of file ComputeMap.C.

References DebugM, and MOStream::put().

Referenced by WorkDistrib::sendComputeMap().

64 {
65  DebugM(4,"Packing ComputeMap\n");
66  msg->put(nComputes);
67  msg->put(nComputes,computeData.begin());
68 }
#define DebugM(x, y)
Definition: Debug.h:59
MOStream * put(char data)
Definition: MStream.h:112
int ComputeMap::partition ( ComputeID  cid)

Definition at line 128 of file ComputeMap.C.

References computeErrorType.

Referenced by cloneCompute(), dumpbench(), and storeCompute().

129 {
130  if (nComputes)
131  return computeData[cid].partition;
132  else return computeErrorType;
133 }
int ComputeMap::pid ( ComputeID  cid,
int  i 
)
void ComputeMap::printComputeMap ( void  )

Definition at line 206 of file ComputeMap.C.

References DebugM, node(), numPids(), pid(), and type().

207 {
208  DebugM(2,"---------------------------------------");
209  DebugM(2,"---------------------------------------\n");
210 
211  DebugM(2,"nComputes = " << nComputes << '\n');
212  DebugM(2,"nAllocated = " << nComputes << '\n');
213  for(int i=0; i < nComputes; i++)
214  {
215  DebugM(2,"Compute " << i << '\n');
216  DebugM(2," node = " << computeData[i].node << '\n');
217  DebugM(2," numPids = " << computeData[i].numPids << '\n');
218  for(int j=0; j < computeData[i].numPids; j++)
219  {
220  DebugM(2,computeData[i].pids[j].pid);
221  if (!((j+1) % 6))
222  DebugM(2,'\n');
223  }
224  DebugM(2,"\n---------------------------------------");
225  DebugM(2,"---------------------------------------\n");
226 
227  }
228 
229 #ifdef MEM_OPT_VERSION
230 const char *fname = "computeMap.opt";
231 #else
232 const char *fname = "computeMap.orig";
233 #endif
234 
235  FILE *ofp = fopen(fname, "w");
236  fprintf(ofp,"---------------------------------------");
237  fprintf(ofp,"---------------------------------------\n");
238 
239  fprintf(ofp,"nComputes = %d\n", nComputes);
240  fprintf(ofp,"nAllocated = %d\n", nComputes);
241  for(int i=0; i < nComputes; i++)
242  {
243  fprintf(ofp,"Compute %d\n", i);
244  fprintf(ofp," node = %d\n",computeData[i].node);
245  fprintf(ofp," numPids = %d\n",computeData[i].numPids);
246  fprintf(ofp," type = %d\n",computeData[i].type);
247  for(int j=0; j < computeData[i].numPids; j++)
248  {
249  fprintf(ofp,"%d ",computeData[i].pids[j].pid);
250  if (!((j+1) % 6))
251  fprintf(ofp,"\n");
252  }
253  fprintf(ofp,"\n---------------------------------------");
254  fprintf(ofp,"---------------------------------------\n");
255 
256  }
257 
258 fclose(ofp);
259 
260 }
#define DebugM(x, y)
Definition: Debug.h:59
ComputeType type(ComputeID cid)
Definition: ComputeMap.C:120
int node(ComputeID cid)
Definition: ComputeMap.h:106
int numPids(ComputeID cid)
Definition: ComputeMap.C:103
int pid(ComputeID cid, int i)
Definition: ComputeMap.C:109
void ComputeMap::registerCompute ( ComputeID  cid,
Compute c 
)
inline

Definition at line 95 of file ComputeMap.h.

Referenced by ComputeMgr::updateLocalComputes().

95  {
96  computePtrs[cid] = c;
97  }
void ComputeMap::saveComputeMap ( const char *  fname)

Definition at line 262 of file ComputeMap.C.

References node().

Referenced by WorkDistrib::mapComputes(), and ComputeMgr::updateLocalComputes4().

263 {
264  static int count = 0;
265  char f[128];
266  sprintf(f, "%s.%d", fname, count++);
267  FILE *fp = fopen(f, "w");
268  CmiAssert(fp != NULL);
269  fprintf(fp, "%d\n", nComputes);
270  for(int i=0; i < nComputes; i++)
271  {
272  fprintf(fp, "%d\n", computeData[i].node);
273  }
274  fclose(fp);
275  CkPrintf("ComputeMap has been stored in %s.\n", f);
276 }
int node(ComputeID cid)
Definition: ComputeMap.h:106
void ComputeMap::setNewNode ( ComputeID  cid,
NodeID  node 
)
inline

Definition at line 120 of file ComputeMap.h.

References node().

Referenced by WorkDistrib::recvComputeMapChanges(), ComputeMgr::splitComputes(), NamdCentLB::Strategy(), ComputeMgr::updateLocalComputes3(), and NamdHybridLB::UpdateLocalLBInfo().

120  {
121  computeData[cid].moveToNode = node;
122  }
int node(ComputeID cid)
Definition: ComputeMap.h:106
void ComputeMap::setNewNumPartitions ( ComputeID  cid,
char  numPartitions 
)
inline

Definition at line 144 of file ComputeMap.h.

References numPartitions().

Referenced by WorkDistrib::recvComputeMapChanges(), NamdHybridLB::splitComputes(), ComputeMgr::splitComputes(), NamdCentLB::Strategy(), and ComputeMgr::updateLocalComputes3().

144  {
145  computeData[cid].newNumPartitions = numPartitions;
146  }
int numPartitions(ComputeID cid)
Definition: ComputeMap.C:135
void ComputeMap::setNode ( ComputeID  cid,
NodeID  node 
)
inline

Definition at line 110 of file ComputeMap.h.

References node().

Referenced by ComputeMgr::updateLocalComputes3().

110  {
111  computeData[cid].node = node;
112  }
int node(ComputeID cid)
Definition: ComputeMap.h:106
void ComputeMap::setNumPartitions ( ComputeID  cid,
char  numPartitions 
)
inline

Definition at line 138 of file ComputeMap.h.

References numPartitions().

Referenced by ComputeMgr::splitComputes().

138  {
139  computeData[cid].numPartitions = numPartitions;
140  }
int numPartitions(ComputeID cid)
Definition: ComputeMap.C:135
ComputeID ComputeMap::storeCompute ( int  node,
int  maxPids,
ComputeType  type,
int  partition = -1,
int  numPartitions = 0 
)

Definition at line 153 of file ComputeMap.C.

References NAMD_bug(), numPartitions(), numPidsAllocated, partition(), and type().

156 {
157  if (maxPids > numPidsAllocated) {
158  NAMD_bug("ComputeMap::storeCompute called with maxPids > numPidsAllocated");
159  }
160 
161  int cid;
162 
163  cid = nComputes;
164  nComputes++;
165  computeData.resize(nComputes);
166 
167  computeData[cid].node=inode;
168 
169  computeData[cid].type = type;
170  computeData[cid].partition = partition;
171  computeData[cid].numPartitions = numPartitions;
172 
173  computeData[cid].numPids = 0;
174 
175  #if defined(NAMD_MIC)
176  // Initially in MIC runs, all computes are mapped to the host. The host vs
177  // device LDB scheme will change this mapping later.
178  computeData[cid].directToDevice = 0;
179  #endif
180 
181  return cid;
182 }
void NAMD_bug(const char *err_msg)
Definition: common.C:123
ComputeType type(ComputeID cid)
Definition: ComputeMap.C:120
int numPartitions(ComputeID cid)
Definition: ComputeMap.C:135
int partition(ComputeID cid)
Definition: ComputeMap.C:128
int ComputeMap::trans ( ComputeID  cid,
int  i 
)

Definition at line 114 of file ComputeMap.C.

Referenced by dumpbench(), newPid(), and registerUserEventsForAllComputeObjs().

115 {
116  return computeData[cid].pids[i].trans;
117 }
ComputeType ComputeMap::type ( ComputeID  cid)
void ComputeMap::unpack ( MIStream msg)
protected

Definition at line 70 of file ComputeMap.C.

References DebugM, MIStream::get(), and NAMD_bug().

Referenced by WorkDistrib::sendComputeMap().

71 {
72  DebugM(4,"Unpacking ComputeMap\n");
73  int old = nComputes;
74  msg->get(nComputes);
75  if ( old && old != nComputes ) {
76  NAMD_bug("number of computes in new ComputeMap has changed!\n");
77  }
78  computeData.resize(nComputes);
79  msg->get(nComputes,computeData.begin());
80 }
#define DebugM(x, y)
Definition: Debug.h:59
MIStream * get(char &data)
Definition: MStream.h:29
void NAMD_bug(const char *err_msg)
Definition: common.C:123

Friends And Related Function Documentation

friend class ComputeMgr
friend

Definition at line 171 of file ComputeMap.h.

friend class WorkDistrib
friend

Definition at line 208 of file ComputeMap.h.


The documentation for this class was generated from the following files: