00001
00009 #ifndef COMLIBSTRATEGY_H
00010 #define COMLIBSTRATEGY_H
00011
00012 #include "charm++.h"
00013 #include "ckhashtable.h"
00014 #include "convcomlibstrategy.h"
00015 #include "ComlibLearner.h"
00016 #include "envelope.h"
00017
00018 CkpvExtern(int, migrationDoneHandlerID);
00019
00020
00022 enum CmhMessageType { CMH_ARRAYSEND,
00023 CMH_GROUPSEND,
00024 CMH_ARRAYBROADCAST,
00025 CMH_ARRAYSECTIONSEND,
00026 CMH_GROUPBROADCAST };
00027
00028
00029
00032 class CharmMessageHolder : public MessageHolder{
00033 public:
00035
00036
00037
00038
00039
00041 CkSectionID *sec_id;
00042
00044 CkSectionID *copy_of_sec_id;
00045
00046 CkArrayID array_id;
00047
00049 CmhMessageType type;
00050
00051 CharmMessageHolder(char * msg, int proc, CmhMessageType t) :
00052 MessageHolder((char *)UsrToEnv(msg), UsrToEnv(msg)->getTotalsize(), proc){
00053 type = t;
00054 sec_id = NULL;
00055 copy_of_sec_id = NULL;
00056
00057
00058
00059
00060
00061
00062
00063 }
00064
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 CharmMessageHolder(CkMigrateMessage *m) : MessageHolder(m) {
00078
00079
00080
00081
00082
00083
00084 }
00085
00086
00087
00088 ~CharmMessageHolder(){
00089
00090 }
00091
00092 inline char * getCharmMessage() {
00093 return (char *)EnvToUsr((envelope *) data);
00094 }
00095
00097 inline void saveCopyOf_sec_id(){
00098
00099
00100
00101
00102 if(sec_id!=NULL){
00103
00104
00105 CkAssert(sec_id->_nElems>=0);
00106 CkAssert(sec_id->npes>=0);
00107
00108
00109
00110 copy_of_sec_id = new CkSectionID();
00111 copy_of_sec_id->_elems = new CkArrayIndex[sec_id->_nElems];
00112 copy_of_sec_id->pelist = new int[sec_id->npes];
00113
00114
00115 copy_of_sec_id->_cookie = sec_id->_cookie;
00116 copy_of_sec_id->_nElems = sec_id->_nElems;
00117 copy_of_sec_id->npes = sec_id->npes;
00118
00119 for(int i=0; i<sec_id->_nElems; i++){
00120 copy_of_sec_id->_elems[i] = sec_id->_elems[i];
00121 }
00122 for(int i=0; i<sec_id->npes; i++){
00123 copy_of_sec_id->pelist[i] = sec_id->pelist[i];
00124 }
00125
00126
00127
00128 }
00129
00130
00131
00132 }
00133
00134 inline void freeCopyOf_sec_id(){
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 }
00146
00147
00148 virtual void pup(PUP::er &p);
00149 PUPable_decl(CharmMessageHolder);
00150 };
00151
00152
00153
00154
00155
00156
00157
00158 class ComlibNodeGroupInfo {
00159 protected:
00160 CkNodeGroupID ngid;
00161 int isNodeGroup;
00162
00163 public:
00164 ComlibNodeGroupInfo();
00165
00166 void setSourceNodeGroup(CkNodeGroupID gid) {
00167 ngid = gid;
00168 isNodeGroup = 1;
00169 }
00170
00171 int isSourceNodeGroup(){return isNodeGroup;}
00172 CkNodeGroupID getSourceNodeGroup();
00173
00174 void pup(PUP::er &p);
00175 };
00176
00177 class ComlibGroupInfo {
00178 protected:
00179 CkGroupID sgid, dgid;
00180 int *srcpelist, nsrcpes;
00181 int *destpelist, ndestpes;
00182 int isSrcGroup;
00183 int isDestGroup;
00184
00185 public:
00186 ComlibGroupInfo();
00187 ~ComlibGroupInfo();
00188
00189 int isSourceGroup(){return isSrcGroup;}
00190 int isDestinationGroup(){return isDestGroup;}
00191
00192 void setSourceGroup(CkGroupID gid, int *srcpelist=0, int nsrcpes=0);
00193 void getSourceGroup(CkGroupID &gid);
00194 void getSourceGroup(CkGroupID &gid, int *&pelist, int &npes);
00195
00196 void setDestinationGroup(CkGroupID sgid,int *destpelist=0,int ndestpes=0);
00197 void getDestinationGroup(CkGroupID &gid);
00198 void getDestinationGroup(CkGroupID &dgid,int *&destpelist, int &ndestpes);
00199
00202 int *getCombinedCountList();
00203
00204 void pup(PUP::er &p);
00205 };
00206
00207 class ComlibMulticastMsg;
00208
00216 class ComlibArrayInfo {
00217 private:
00218
00219 CkArrayID src_aid;
00220 CkArrayID dest_aid;
00221
00225 CkVec<CkArrayIndex> src_elements;
00226
00231 CkVec<CkArrayIndex> new_src_elements;
00232
00236 CkVec<CkArrayIndex> dest_elements;
00237
00242 CkVec<CkArrayIndex> new_dest_elements;
00243
00244 int isSrcArray;
00245 int isDestArray;
00246
00247 bool isAllSrc;
00248 int totalSrc;
00249 bool isAllDest;
00250 int totalDest;
00251
00252 public:
00253 ComlibArrayInfo();
00254
00255
00260 void setSourceArray(CkArrayID aid, CkArrayIndex *e=0, int nind=0);
00261 int isSourceArray(){return isSrcArray;}
00262 CkArrayID getSourceArrayID() {return src_aid;}
00263 const CkVec<CkArrayIndex> & getSourceElements() {return src_elements;}
00264
00269 void setDestinationArray(CkArrayID aid, CkArrayIndex *e=0, int nind=0);
00270 int isDestinationArray(){return isDestArray;}
00271 CkArrayID getDestinationArrayID() {return dest_aid;}
00272 const CkVec<CkArrayIndex> & getDestinationElements() {return dest_elements;}
00273
00275 int getTotalSrc() {return totalSrc;}
00276 int getLocalSrc() {return src_elements.size();}
00277
00279 void addNewLocalDestination(const CkArrayIndex &e) {
00280 CkAssert(e.nInts > 0);
00281 new_dest_elements.push_back(e);
00282 }
00283
00285 void addNewLocalSource(const CkArrayIndex &e) {
00286 CkAssert(e.nInts > 0);
00287 new_src_elements.push_back(e);
00288 }
00289
00291 void useNewSourceAndDestinations() {
00292 ComlibPrintf("[%d] useNewSourceAndDestinations previously had %d elements, now have %d elements\n", CkMyPe(), dest_elements.size(), new_src_elements.size() );
00293 dest_elements.removeAll();
00294 dest_elements = new_dest_elements;
00295 CkAssert(dest_elements.size() == new_dest_elements.size());
00296 new_dest_elements.removeAll();
00297 src_elements.removeAll();
00298 src_elements = new_src_elements;
00299 CkAssert(src_elements.size() == new_src_elements.size());
00300 new_src_elements.removeAll();
00301 if(com_debug)
00302 printDestElementList();
00303 }
00304
00305 int newDestinationListSize(){ return new_dest_elements.size(); }
00306 int newSourceListSize(){ return new_src_elements.size(); }
00307
00308 int getTotalDest() {return totalDest;}
00309 int getLocalDest() {return dest_elements.size();}
00310
00311 void newElement(CkArrayID &id, const CkArrayIndex &idx);
00312
00313 void localBroadcast(envelope *env);
00314 static int localMulticast(CkVec<CkArrayIndex> *idx_vec,envelope *env);
00315 static void deliver(envelope *env);
00316
00320 void purge();
00321
00324 int *getCombinedCountList();
00325
00326 void printDestElementList();
00327
00328
00329 void pup(PUP::er &p);
00330 };
00331
00334 class ComlibElementIterator : public CkLocIterator {
00335 public:
00336 CkVec<CkArrayIndex> *list;
00337
00338 ComlibElementIterator(CkVec<CkArrayIndex> *l) : CkLocIterator() {
00339 list = l;
00340 }
00341
00342 virtual void addLocation (CkLocation &loc) {
00343 list->push_back(loc.getIndex());
00344 }
00345 };
00346
00347
00348
00349
00350 void ComlibManagerRegisterArrayListener(CkArrayID, ComlibArrayInfo*);
00351
00357 class CharmStrategy {
00358
00359 protected:
00360
00361 ComlibLearner *learner;
00362 CmiBool mflag;
00363 CkCallback onFinish;
00364
00365
00367 int deliverToIndices(void *msg, int numDestIdxs, const CkArrayIndex* indices );
00368
00370 inline void deliverToIndices(void *msg, const CkVec< CkArrayIndex > &indices ){
00371 deliverToIndices(msg, indices.size(), indices.getVec() );
00372 }
00373
00374
00375 public:
00376
00377 ComlibGroupInfo ginfo;
00378 ComlibNodeGroupInfo nginfo;
00379
00382 ComlibArrayInfo ainfo;
00383
00384 CharmStrategy() {
00385
00386
00387
00388 learner = NULL;
00389 mflag = CmiFalse;
00390 }
00391
00392 CharmStrategy(CkMigrateMessage *m) {
00393 learner = NULL;
00394 }
00395
00396
00397 inline void setMulticast(){
00398 mflag = CmiTrue;
00399 }
00400
00401
00402 CmiBool getMulticast () {
00403 return mflag;
00404 }
00405
00406 inline void setOnFinish (CkCallback of) {
00407 onFinish = of;
00408 }
00409
00410 inline CkCallback getOnFinish () {
00411 return onFinish;
00412 }
00413
00414
00415 ComlibLearner *getLearner() {return learner;}
00416 void setLearner(ComlibLearner *l) {learner = l;}
00417
00418 virtual void pup(PUP::er &p);
00419
00420 };
00421
00422
00423 void ComlibNotifyMigrationDone();
00424
00425
00426
00427 #endif
00428