00001
00005 #ifndef _REGISTER_H
00006 #define _REGISTER_H
00007
00008 #include "charm.h"
00009 #include "cklists.h"
00010
00013
00026 class EntryInfo {
00027 public:
00051 CkCallFnPtr call;
00053 int msgIdx;
00055 int chareIdx;
00056
00065 CkMarshallUnpackFn marshallUnpack;
00066
00067 #if CMK_CHARMDEBUG
00068
00078 CkMessagePupFn messagePup;
00079 #endif
00080
00082 bool traceEnabled;
00084 bool noKeep;
00086 bool isImmediate;
00088 bool isInline;
00090 bool inCharm;
00091 bool appWork;
00092 bool ownsName;
00093 #ifdef ADAPT_SCHED_MEM
00095 bool isMemCritical;
00096 #endif
00097
00099 const char *name;
00100
00101 EntryInfo(const char *n, CkCallFnPtr c, int m, int ci, bool ownsN=false) :
00102 call(c), msgIdx(m), chareIdx(ci),
00103 marshallUnpack(0)
00104 #if CMK_CHARMDEBUG
00105 ,messagePup(0)
00106 #endif
00107 ,traceEnabled(true), noKeep(false), isImmediate(false), isInline(false), inCharm(false), appWork(false),
00108 ownsName(ownsN), name(n)
00109 {
00110 if (ownsName) initName(n);
00111 }
00112
00113 ~EntryInfo()
00114 {
00115 if (ownsName) delete [] name;
00116 }
00117
00119 void setName(const char* new_name)
00120 {
00121 if (ownsName) delete [] name;
00122 initName(new_name);
00123 }
00124
00125 private:
00126
00127 void initName(const char* new_name)
00128 {
00129 size_t len = strlen(new_name);
00130
00131 char* temp = new char[len + 1];
00132 strcpy(temp, new_name);
00133 name = temp;
00134 ownsName = true;
00135 }
00136 };
00137
00142 class MsgInfo {
00143 public:
00157 CkPackFnPtr pack;
00162 CkUnpackFnPtr unpack;
00167 CkDeallocFnPtr dealloc;
00173 size_t size;
00174
00176 const char *name;
00177
00178 MsgInfo(const char *n,CkPackFnPtr p,CkUnpackFnPtr u,CkDeallocFnPtr d,int s):
00179 pack(p), unpack(u), dealloc(d), size(s), name(n)
00180 {}
00181 };
00182
00187 class ChareInfo {
00188 public:
00190 const char *name;
00192 size_t size;
00193
00195 int defCtor,migCtor;
00197 int numbases;
00199 int bases[16];
00200
00202 ChareType chareType;
00203 int mainChareIdx;
00204
00206 int ndims;
00207
00209 bool isIrr;
00210
00212 bool inCharm;
00213
00214 ChareInfo(const char *n, size_t s, ChareType t) : name(n), size(s) {
00215 defCtor=migCtor=-1;
00216 isIrr = false;
00217 numbases = 0;
00218 chareType = t;
00219 inCharm = false;
00220 mainChareIdx = -1;
00221 ndims = -1;
00222 }
00223 void setDefaultCtor(int idx) { defCtor = idx; }
00224 int getDefaultCtor(void) { return defCtor; }
00225 void setMigCtor(int idx) { migCtor = idx; }
00226 int getMigCtor(void) { return migCtor; }
00227 void addBase(int idx) {
00228 CkAssert(numbases+1 <= 16);
00229
00230 bases[numbases++] = idx;
00231 }
00232 void setInCharm() { inCharm = true; }
00233 bool isInCharm() { return inCharm; }
00234 void setMainChareType(int idx) { mainChareIdx = idx; }
00235 int mainChareType() { return mainChareIdx; }
00236 };
00237
00239 class MainInfo {
00240 public:
00241 void* obj;
00242 const char *name;
00243 int chareIdx;
00244 int entryIdx;
00245 int entryMigCtor;
00246 MainInfo(int c, int e) : name("main"), chareIdx(c), entryIdx(e) {}
00247 inline void* getObj(void) { return obj; }
00248 inline void setObj(void *_obj) { obj=_obj; }
00249 };
00250
00252 class ReadonlyInfo {
00253 public:
00255 size_t size;
00257 void *ptr;
00259 CkPupReadonlyFnPtr pup;
00261 const char *name,*type;
00262
00264 void pupData(PUP::er &p) {
00265 if (pup!=NULL)
00266 (pup)((void *)&p);
00267 else
00268 p((char *)ptr,size);
00269 }
00270 ReadonlyInfo(const char *n,const char *t,
00271 size_t s, void *p,CkPupReadonlyFnPtr pf)
00272 : size(s), ptr(p), pup(pf), name(n), type(t) {}
00273 };
00274
00280 class ReadonlyMsgInfo {
00281 public:
00282 const char *name, *type;
00283 void **pMsg;
00284 ReadonlyMsgInfo(const char *n, const char *t,
00285 void **p) : name(n), type(t), pMsg(p) {}
00286 };
00287
00292 template <class T>
00293 class CkRegisteredInfo {
00294 CkVec<T *> vec;
00295
00296 void outOfBounds(int idx) {
00297 const char *exampleName="";
00298 if (vec.size()>0) exampleName=vec[0]->name;
00299 CkPrintf("register.h> CkRegisteredInfo<%d,%s> called with invalid index "
00300 "%d (should be less than %d)\n", sizeof(T),exampleName,
00301 idx, vec.size());
00302 CkAbort("Registered idx is out of bounds-- is message or memory corrupted?");
00303 }
00304 public:
00312 CkRegisteredInfo() :vec(CkSkipInitialization()) {}
00313 ~CkRegisteredInfo() {
00314 for (size_t i=0; i<vec.size(); i++) if (vec[i]) delete vec[i];
00315 }
00316
00319 int add(T *t) {
00320 #if CMK_ERROR_CHECKING
00321
00322 if (CkMyRank()!=0)
00323 CkAbort("Can only do registrations from rank 0 processors");
00324 #endif
00325 vec.push_back(t);
00326 return vec.size()-1;
00327 }
00328
00329 size_t size(void) {return vec.size();}
00330
00332 T *operator[](size_t idx) {
00333 #if CMK_ERROR_CHECKING
00334
00335 if (idx>=vec.size()) outOfBounds(idx);
00336 #endif
00337 return vec[idx];
00338 }
00339 };
00340
00342 extern CkRegisteredInfo<EntryInfo> _entryTable;
00343 extern CkRegisteredInfo<MsgInfo> _msgTable;
00344 extern CkRegisteredInfo<ChareInfo> _chareTable;
00345 extern CkRegisteredInfo<MainInfo> _mainTable;
00346 extern CkRegisteredInfo<ReadonlyInfo> _readonlyTable;
00347 extern CkRegisteredInfo<ReadonlyMsgInfo> _readonlyMsgs;
00348
00349 extern void _registerInit(void);
00350 extern void _registerDone(void);
00351
00352 extern int CkGetChareIdx(const char *name);
00353
00355 #endif