4 #include "charm.h" // For CkNumPes
6 #include <new> // for in-place new operator
7 #include "ckhashtable.h"
10 typedef CkQ
<void *> PtrQ
;
12 typedef std::vector
<CkZeroPtr
<envelope
> > PtrVec
;
17 PtrQ
*pending
; //Buffers msgs recv'd before group is created
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
) {
31 void setcIdx(int cIdx_
){
34 inline int getcIdx(void) const { return cIdx
; }
37 template <class dtype
>
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
51 CkAbort("Group ID is zero-- invalid!\n");
55 if (n
.idx
>=max
) { /* Extend processor 0's group table */
60 for (i
=0;i
<oldmax
;i
++) tab
[i
]=oldtab
[i
];
61 for (i
=oldmax
;i
<max
;i
++) tab
[i
]=dtype(0);
66 { /*Groups created on processors >0 go into a hashtable:*/
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!)
82 GroupIdxArray() {tab
=NULL
;max
=0;hashTab
=NULL
;}
83 ~GroupIdxArray() {delete[] tab
; if (hashTab
!=NULL
) CkDeleteHashtable(hashTab
);}
87 for(int i
=0;i
<max
;i
++)
92 inline dtype
& find(CkGroupID n
) {
93 if(n
.idx
>0 && n
.idx
<max
)
96 return nonInlineFind(n
);
100 typedef GroupIdxArray
<TableEntry
> GroupTable
;
101 typedef std::vector
<CkGroupID
> GroupIDTable
;
103 typedef void (*CkInitCallFn
)(void);
107 CkQ
<CkInitCallFn
> initNodeCalls
;
108 CkQ
<CkInitCallFn
> initProcCalls
;
110 void enumerateInitCalls();
112 void _registerInitCall(CkInitCallFn fn
, int isNodeCall
);
114 /*********************************************************/
117 These are implemented in init.C.
120 extern unsigned int _printCS
;
121 extern unsigned int _printSS
;
124 extern int _charmHandlerIdx
;
125 extern int _roRestartHandlerIdx
; /* for checkpoint/restart */
126 #if CMK_SHRINK_EXPAND
127 extern int _ROGroupRestartHandlerIdx
; /* for checkpoint/restart */
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);