bugfix: provide html.sty and symlink to fix markup
[charm.git] / src / ck-core / init.h
blobdafc3ec3bef7d095a6665a7c0d82dff131c26c19
1 #ifndef _INIT_H
2 #define _INIT_H
4 #include "charm.h" // For CkNumPes
5 #include "charm-api.h"
6 #include <new> // for in-place new operator
7 #include "ckhashtable.h"
8 #include <vector>
10 typedef CkQ<void *> PtrQ;
11 class envelope;
12 typedef std::vector<CkZeroPtr<envelope> > PtrVec;
14 class IrrGroup;
15 class TableEntry {
16 IrrGroup *obj;
17 PtrQ *pending; //Buffers msgs recv'd before group is created
18 int cIdx;
20 public:
21 TableEntry(int ignored=0) { (void)ignored; obj=0; pending=0; cIdx=-1; }
22 inline IrrGroup* getObj(void) { return obj; }
23 inline void setObj(void *_obj) { obj=(IrrGroup *)_obj; }
24 PtrQ* getPending(void) { return pending; }
25 inline void clearPending(void) { delete pending; pending = NULL; }
26 void enqMsg(void *msg) {
27 if (pending==0)
28 pending=new PtrQ();
29 pending->enq(msg);
31 void setcIdx(int cIdx_){
32 cIdx = cIdx_;
34 inline int getcIdx(void) const { return cIdx; }
37 template <class dtype>
38 class GroupIdxArray {
39 // The initial size of the table for groups created on PE 0:
40 enum {INIT_BINS_PE0=32};
42 dtype *tab; // direct table for groups created on processor 0
43 CkHashtable_c hashTab; // hashtable for groups created on processors >0
44 int max; // Size of "tab"
46 //This non-inline version of "find", below, allows the (much simpler)
47 // common case to be inlined.
48 dtype& nonInlineFind(CkGroupID n) {
49 #if CMK_ERROR_CHECKING
50 if (n.idx==0) {
51 CkAbort("Group ID is zero-- invalid!\n");
52 return *(new dtype);
53 } else
54 #endif
55 if (n.idx>=max) { /* Extend processor 0's group table */
56 dtype *oldtab=tab;
57 int i, oldmax=max;
58 max=2*n.idx+1;
59 tab=new dtype[max];
60 for (i=0;i<oldmax;i++) tab[i]=oldtab[i];
61 for (i=oldmax;i<max;i++) tab[i]=dtype(0);
62 delete [] oldtab;
63 return tab[n.idx];
65 else /*n.idx < 0*/
66 { /*Groups created on processors >0 go into a hashtable:*/
67 if(hashTab == NULL)
68 hashTab = CkCreateHashtable_int(sizeof(dtype),17);
70 dtype *ret = (dtype *)CkHashtableGet(hashTab,&(n.idx));
72 if(ret == NULL) // insert new entry into the table
74 ret = (dtype *)CkHashtablePut(hashTab,&(n.idx));
75 new (ret) dtype(0); //Call dtype's constructor (ICK!)
77 return *ret;
81 public:
82 GroupIdxArray() {tab=NULL;max=0;hashTab=NULL;}
83 ~GroupIdxArray() {delete[] tab; if (hashTab!=NULL) CkDeleteHashtable(hashTab);}
84 void init(void) {
85 max = INIT_BINS_PE0;
86 tab = new dtype[max];
87 for(int i=0;i<max;i++)
88 tab[i]=dtype(0);
89 hashTab=NULL;
92 inline dtype& find(CkGroupID n) {
93 if(n.idx>0 && n.idx<max)
94 return tab[n.idx];
95 else
96 return nonInlineFind(n);
100 typedef GroupIdxArray<TableEntry> GroupTable;
101 typedef std::vector<CkGroupID> GroupIDTable;
103 typedef void (*CkInitCallFn)(void);
104 class InitCallTable
106 public:
107 CkQ<CkInitCallFn> initNodeCalls;
108 CkQ<CkInitCallFn> initProcCalls;
109 public:
110 void enumerateInitCalls();
112 void _registerInitCall(CkInitCallFn fn, int isNodeCall);
114 /*********************************************************/
116 \addtogroup CkInit
117 These are implemented in init.C.
119 /*@{*/
120 extern unsigned int _printCS;
121 extern unsigned int _printSS;
123 extern int _infoIdx;
124 extern int _charmHandlerIdx;
125 extern int _roRestartHandlerIdx; /* for checkpoint/restart */
126 #if CMK_SHRINK_EXPAND
127 extern int _ROGroupRestartHandlerIdx; /* for checkpoint/restart */
128 #endif
129 extern int _bocHandlerIdx;
130 extern int _qdHandlerIdx;
131 extern unsigned int _numInitMsgs;
133 CksvExtern(unsigned int, _numInitNodeMsgs);
134 CksvExtern(CmiNodeLock, _nodeLock);
135 CksvExtern(GroupTable*, _nodeGroupTable);
136 CksvExtern(GroupIDTable, _nodeGroupIDTable);
137 CksvExtern(CmiImmediateLockType, _nodeGroupTableImmLock);
138 CksvExtern(unsigned int, _numNodeGroups);
140 CkpvExtern(int, _charmEpoch);
142 CkpvExtern(CkGroupID,_currentGroup);
143 CkpvExtern(void*, _currentNodeGroupObj);
144 CkpvExtern(CkGroupID, _currentGroupRednMgr);
146 CkpvExtern(GroupTable*, _groupTable);
147 CkpvExtern(GroupIDTable*, _groupIDTable);
148 CkpvExtern(CmiImmediateLockType, _groupTableImmLock);
149 CkpvExtern(unsigned int, _numGroups);
151 CkpvExtern(bool, _destroyingNodeGroup);
153 CkpvExtern(char **,Ck_argv);
155 static inline IrrGroup *_localBranch(CkGroupID gID)
157 return CkpvAccess(_groupTable)->find(gID).getObj();
160 extern void _registerCommandLineOpt(const char* opt);
161 extern void _initCharm(int argc, char **argv);
163 extern "C" int charm_main(int argc, char **argv);
164 FDECL void FTN_NAME(CHARM_MAIN_FORTRAN_WRAPPER, charm_main_fortran_wrapper)(int *argc, char **argv);
166 /** This routine registers the user's main module. It is normally
167 generated by the translator, but for FEM and AMPI may actually be
168 the "fallback" version in compat_regmm.c. */
169 extern "C" void CkRegisterMainModule(void);
171 typedef void (*CkExitFn) (void);
173 extern CkQ<CkExitFn> _CkExitFnVec;
174 extern void registerExitFn(CkExitFn);
175 // Each registered exit function must eventually lead to a single call
176 // being made to CkContinueExit()
177 extern void CkContinueExit();
179 extern "C" void EmergencyExit(void);
181 /*@}*/
183 #endif