00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _CKCALLBACK_H_
00013 #define _CKCALLBACK_H_
00014
00015 #include "conv-ccs.h"
00016 typedef void (*CkCallbackFn)(void *param,void *message);
00017 typedef void (*Ck1CallbackFn)(void *message);
00018
00019 class CProxyElement_ArrayBase;
00020 class CProxySection_ArrayBase;
00021 class CProxyElement_Group;
00022 class CProxy_NodeGroup;
00023 class Chare;
00024 class Group;
00025 class NodeGroup;
00026 class ArrayElement;
00027 #define CkSelfCallback(ep) CkCallback(this, ep)
00028
00029 class CkCallback {
00030 public:
00031 typedef enum {
00032 invalid=0,
00033 ignore,
00034 ckExit,
00035 resumeThread,
00036 callCFn,
00037 call1Fn,
00038 sendChare,
00039 sendGroup,
00040 sendNodeGroup,
00041 sendArray,
00042 isendChare,
00043 isendGroup,
00044 isendNodeGroup,
00045 isendArray,
00046 bcastGroup,
00047 bcastNodeGroup,
00048 bcastArray,
00049 bcastSection,
00050 replyCCS
00051 } callbackType;
00052 private:
00053 union callbackData {
00054 struct s_thread {
00055 int onPE;
00056 int cb;
00057 CthThread th;
00058 void *ret;
00059 } thread;
00060 struct s_cfn {
00061 int onPE;
00062 CkCallbackFn fn;
00063 void *param;
00064 } cfn;
00065 struct s_c1fn {
00066 Ck1CallbackFn fn;
00067 } c1fn;
00068 struct s_chare {
00069 int ep;
00070 CkChareID id;
00071 } chare;
00072 struct s_group {
00073 int ep;
00074 CkGroupID id;
00075 int onPE;
00076 } group;
00077 struct s_array {
00078 int ep;
00079 CkGroupID id;
00080 CkArrayIndexBase idx;
00081 } array;
00082 struct s_section{
00083 CkSectionInfoStruct sinfo;
00084 CkArrayIndex *_elems;
00085 int _nElems;
00086 int *pelist;
00087 int npes;
00088 int ep;
00089 } section;
00090
00091 struct s_ccsReply {
00092 CcsDelayedReply reply;
00093 } ccsReply;
00094
00095
00096
00097 };
00098
00099 public:
00100 callbackType type;
00101 callbackData d;
00102 void impl_thread_init(void);
00103 void *impl_thread_delay(void) const;
00104
00105 CkCallback(void) {
00106 #if CMK_REPLAYSYSTEM
00107 bzero(this, sizeof(CkCallback));
00108 #endif
00109 type=invalid;
00110 }
00111
00112 CkCallback(callbackType t) {
00113 #if CMK_REPLAYSYSTEM
00114 bzero(this, sizeof(CkCallback));
00115 #endif
00116 if (t==resumeThread) impl_thread_init();
00117 type=t;
00118 }
00119
00120
00121 CkCallback(Ck1CallbackFn fn) {
00122 #if CMK_REPLAYSYSTEM
00123 bzero(this, sizeof(CkCallback));
00124 #endif
00125 type=call1Fn;
00126 d.c1fn.fn=fn;
00127 }
00128
00129
00130 CkCallback(CkCallbackFn fn,void *param) {
00131 #if CMK_REPLAYSYSTEM
00132 bzero(this, sizeof(CkCallback));
00133 #endif
00134 type=callCFn;
00135 d.cfn.onPE=CkMyPe(); d.cfn.fn=fn; d.cfn.param=param;
00136 }
00137
00138
00139 CkCallback(int ep,const CkChareID &id,CmiBool doInline=CmiFalse) {
00140 #if CMK_REPLAYSYSTEM
00141 bzero(this, sizeof(CkCallback));
00142 #endif
00143 type=doInline?isendChare:sendChare;
00144 d.chare.ep=ep; d.chare.id=id;
00145 }
00146
00147
00148 CkCallback(int ep,const CProxy_NodeGroup &ngp);
00149
00150
00151 CkCallback(int ep,const CkGroupID &id, int isNodeGroup=0) {
00152 #if CMK_REPLAYSYSTEM
00153 bzero(this, sizeof(CkCallback));
00154 #endif
00155 type=isNodeGroup?bcastNodeGroup:bcastGroup;
00156 d.group.ep=ep; d.group.id=id;
00157 }
00158
00159
00160 CkCallback(int ep,int onPE,const CProxy_NodeGroup &ngp,CmiBool doInline=CmiFalse);
00161
00162
00163 CkCallback(int ep,int onPE,const CkGroupID &id,CmiBool doInline=CmiFalse, int isNodeGroup=0) {
00164 #if CMK_REPLAYSYSTEM
00165 bzero(this, sizeof(CkCallback));
00166 #endif
00167 type=doInline?(isNodeGroup?isendNodeGroup:isendGroup):(isNodeGroup?sendNodeGroup:sendGroup);
00168 d.group.ep=ep; d.group.id=id; d.group.onPE=onPE;
00169 }
00170
00171
00172 CkCallback(int ep,const CProxyElement_Group &grpElt,CmiBool doInline=CmiFalse);
00173
00174
00175 CkCallback(int ep,const CkArrayID &id) {
00176 #if CMK_REPLAYSYSTEM
00177 bzero(this, sizeof(CkCallback));
00178 #endif
00179 type=bcastArray;
00180 d.array.ep=ep; d.array.id=id;
00181 }
00182
00183
00184 CkCallback(int ep,const CkArrayIndex &idx,const CkArrayID &id,CmiBool doInline=CmiFalse) {
00185 #if CMK_REPLAYSYSTEM
00186 bzero(this, sizeof(CkCallback));
00187 #endif
00188 type=doInline?isendArray:sendArray;
00189 d.array.ep=ep; d.array.id=id; d.array.idx = idx;
00190 }
00191
00192
00193 CkCallback(int ep,const CProxyElement_ArrayBase &arrElt,CmiBool doInline=CmiFalse);
00194
00195
00196 CkCallback(int ep,CProxySection_ArrayBase §Elt,CmiBool doInline=CmiFalse);
00197 CkCallback(int ep, CkSectionID &sid);
00198
00199
00200 CkCallback(Chare *p, int ep, CmiBool doInline=CmiFalse);
00201
00202
00203 CkCallback(Group *p, int ep, CmiBool doInline=CmiFalse);
00204
00205
00206 CkCallback(NodeGroup *p, int ep, CmiBool doInline=CmiFalse);
00207
00208
00209 CkCallback(ArrayElement *p, int ep,CmiBool doInline=CmiFalse);
00210
00211 CkCallback(const CcsDelayedReply &reply) {
00212 #if CMK_REPLAYSYSTEM
00213 bzero(this, sizeof(CkCallback));
00214 #endif
00215 type=replyCCS;
00216 d.ccsReply.reply=reply;
00217 }
00218
00219 ~CkCallback() {
00220 thread_destroy();
00221 if (bcastSection == type) {
00222 if (d.section._elems != NULL) delete [] d.section._elems;
00223 if (d.section.pelist != NULL) delete [] d.section.pelist;
00224 }
00225 }
00226
00227 int isInvalid(void) const {return type==invalid;}
00228
00236 void *thread_delay(void) const {
00237 if (type==resumeThread) return impl_thread_delay();
00238 return NULL;
00239 }
00240
00241 void thread_destroy() const;
00242
00250 void send(void *msg=NULL) const;
00251
00255 void send(int length,const void *data) const;
00256
00257 void pup(PUP::er &p);
00258 };
00259
00260
00270 class CkCallbackResumeThread : public CkCallback {
00271 protected: void ** result;
00272 public:
00273 CkCallbackResumeThread(void)
00274 :CkCallback(resumeThread) { result = NULL; }
00275 CkCallbackResumeThread(void * &ptr)
00276 :CkCallback(resumeThread) { result = &ptr; }
00277 ~CkCallbackResumeThread(void);
00278 };
00279
00280 void _registerCkCallback(void);
00281
00282 void CkCallbackInit();
00283
00284 #endif
00285
00286
00287