4 #include "charm.h" // For CkNumPes
5 #include <new> // for in-place new operator
6 #include "ckhashtable.h"
8 typedef CkQ
<void *> PtrQ
;
10 typedef CkVec
<CkZeroPtr
<envelope
> > PtrVec
;
15 PtrQ
*pending
; //Buffers msgs recv'd before group is created
19 TableEntry(int ignored
=0) { obj
=0; pending
=0; cIdx
=-1; }
20 inline IrrGroup
* getObj(void) { return obj
; }
21 inline void setObj(void *_obj
) { obj
=(IrrGroup
*)_obj
; }
22 PtrQ
* getPending(void) { return pending
; }
23 inline void clearPending(void) { delete pending
; pending
= NULL
; }
24 void enqMsg(void *msg
) {
29 void setcIdx(int cIdx_
){
32 inline int getcIdx(void) const { return cIdx
; }
35 template <class dtype
>
37 // The initial size of the table for groups created on PE 0:
38 enum {INIT_BINS_PE0
=32};
40 dtype
*tab
; // direct table for groups created on processor 0
41 CkHashtable_c hashTab
; // hashtable for groups created on processors >0
42 int max
; // Size of "tab"
44 //This non-inline version of "find", below, allows the (much simpler)
45 // common case to be inlined.
46 dtype
& nonInlineFind(CkGroupID n
) {
47 #if CMK_ERROR_CHECKING
49 CkAbort("Group ID is zero-- invalid!\n");
53 if (n
.idx
>=max
) { /* Extend processor 0's group table */
58 for (i
=0;i
<oldmax
;i
++) tab
[i
]=oldtab
[i
];
59 for (i
=oldmax
;i
<max
;i
++) tab
[i
]=dtype(0);
64 { /*Groups created on processors >0 go into a hashtable:*/
66 hashTab
= CkCreateHashtable_int(sizeof(dtype
),17);
68 dtype
*ret
= (dtype
*)CkHashtableGet(hashTab
,&(n
.idx
));
70 if(ret
== NULL
) // insert new entry into the table
72 ret
= (dtype
*)CkHashtablePut(hashTab
,&(n
.idx
));
73 new (ret
) dtype(0); //Call dtype's constructor (ICK!)
80 GroupIdxArray() {tab
=NULL
;max
=0;hashTab
=NULL
;}
81 ~GroupIdxArray() {delete[] tab
; if (hashTab
!=NULL
) CkDeleteHashtable(hashTab
);}
85 for(int i
=0;i
<max
;i
++)
90 inline dtype
& find(CkGroupID n
) {
91 if(n
.idx
>0 && n
.idx
<max
)
94 return nonInlineFind(n
);
98 typedef GroupIdxArray
<TableEntry
> GroupTable
;
99 typedef CkVec
<CkGroupID
> GroupIDTable
;
101 typedef void (*CkInitCallFn
)(void);
105 CkQ
<CkInitCallFn
> initNodeCalls
;
106 CkQ
<CkInitCallFn
> initProcCalls
;
108 void enumerateInitCalls();
110 void _registerInitCall(CkInitCallFn fn
, int isNodeCall
);
112 /*********************************************************/
115 These are implemented in init.C.
118 extern unsigned int _printCS
;
119 extern unsigned int _printSS
;
122 extern int _charmHandlerIdx
;
123 extern int _roRestartHandlerIdx
; /* for checkpoint/restart */
124 extern int _bocHandlerIdx
;
125 extern int _qdHandlerIdx
;
126 extern unsigned int _numInitMsgs
;
128 CksvExtern(unsigned int, _numInitNodeMsgs
);
129 CksvExtern(CmiNodeLock
, _nodeLock
);
130 CksvExtern(GroupTable
*, _nodeGroupTable
);
131 CksvExtern(GroupIDTable
, _nodeGroupIDTable
);
132 CksvExtern(CmiImmediateLockType
, _nodeGroupTableImmLock
);
133 CksvExtern(unsigned int, _numNodeGroups
);
135 CkpvExtern(int, _charmEpoch
);
137 CkpvExtern(CkGroupID
,_currentGroup
);
138 CkpvExtern(void*, _currentNodeGroupObj
);
139 CkpvExtern(CkGroupID
, _currentGroupRednMgr
);
141 CkpvExtern(GroupTable
*, _groupTable
);
142 CkpvExtern(GroupIDTable
*, _groupIDTable
);
143 CkpvExtern(CmiImmediateLockType
, _groupTableImmLock
);
144 CkpvExtern(unsigned int, _numGroups
);
146 CkpvExtern(bool, _destroyingNodeGroup
);
148 CkpvExtern(char **,Ck_argv
);
150 static inline IrrGroup
*_localBranch(CkGroupID gID
)
152 return CkpvAccess(_groupTable
)->find(gID
).getObj();
155 extern void _initCharm(int argc
, char **argv
);
157 /** This routine registers the user's main module. It is normally
158 generated by the translator, but for FEM and AMPI may actually be
159 the "fallback" version in compat_regmm.c. */
160 extern "C" void CkRegisterMainModule(void);
162 typedef void (*CkExitFn
) (void);
164 extern CkQ
<CkExitFn
> _CkExitFnVec
;
165 extern void registerExitFn(CkExitFn
);
167 extern "C" void EmergencyExit(void);