00001
00005 #ifndef __PARFUM_SA_H
00006 #define __PARFUM_SA_H
00007
00008 #include "tcharm.h"
00009 #include "charm++.h"
00010 #include "ParFUM.h"
00011 #include "idxl.h"
00012 #include "ParFUM_internals.h"
00013
00014
00015 class RegionID{
00016 public:
00017 int chunkID;
00018 int localID;
00019 double prio;
00020 operator CkHashCode() const {
00021 return (CkHashCode )(localID + 1<< chunkID);
00022 };
00023 void pup(PUP::er &p) {
00024 p|chunkID; p|localID; p|prio;
00025 }
00026 inline bool operator==(const RegionID &rhs) const {
00027 return (rhs.chunkID == chunkID) && (rhs.localID == localID);
00028 }
00029 inline RegionID& operator=(const RegionID& rhs) {
00030 chunkID = rhs.chunkID;
00031 localID = rhs.localID;
00032 prio = rhs.prio;
00033 return *this;
00034 }
00035 };
00036
00037
00040 class LockRegion {
00041 public:
00042 RegionID myID;
00043 CkVec<int> localNodes;
00044 CkVec<int> sharedIdxls;
00045 CkHashtableT<CkHashtableAdaptorT<int>, CkVec<adaptAdj> *> remoteElements;
00046 CthThread tid;
00047 int numReplies;
00048 int success;
00049 ~LockRegion(){
00050 CkHashtableIterator *iter = remoteElements.iterator();
00051 while(iter->hasNext()){
00052 CkVec<adaptAdj> *list = *((CkVec<adaptAdj> **)iter->next());
00053
00054 delete list;
00055 }
00056 }
00057 };
00058
00059 #include "ParFUM_SA.decl.h"
00060
00062
00067 class BulkAdapt;
00068 class ParFUMShadowArray : public CBase_ParFUMShadowArray {
00069 private:
00071 int numChunks;
00073 int idx;
00075 TCharm *tc;
00077 CProxy_TCharm tproxy;
00079 FEM_Mesh *fmMesh;
00081 CkHashtableT<CkHashtableAdaptorT<RegionID>,LockRegion *> regionTable;
00082 int regionCount;
00083
00084 public:
00085 BulkAdapt *bulkAdapt;
00086 RegionID holdingLock;
00087 RegionID pendingLock;
00088
00089 public:
00091 ParFUMShadowArray(int s, int i);
00093 ParFUMShadowArray(CkMigrateMessage *m);
00095 ~ParFUMShadowArray();
00096
00098 void pup(PUP::er &p);
00100 void ckJustMigrated(void);
00101
00103 int getNumChunks(){return numChunks;}
00105 int getIdx(){return idx;}
00107 FEM_Mesh *getfmMesh(){return fmMesh;}
00108
00110 void setFemMesh(FEMMeshMsg *m);
00111
00112 void setRunningTCharm(){CtvAccess(_curTCharm)= tc;};
00113
00115 void sort(int *chkList, int chkListSize);
00116
00117
00118
00119
00120
00121 int lockRegion(int numElements,adaptAdj *elements,RegionID *regionID, double prio);
00122 void unlockRegion(RegionID regionID);
00123 void unpendRegion(RegionID regionID);
00124
00125 void collectLocalNodes(int numElements,adaptAdj *elements,CkVec<int> &localNodes);
00126 bool lockLocalNodes(LockRegion *region);
00127 bool lockSharedIdxls(LockRegion *region);
00128 void lockRegionForRemote(RegionID regionID,int *sharedIdxls,int numSharedIdxls,adaptAdj *elements,int numElements);
00129 void lockReply(int remoteChunk,RegionID regionID,int success,int tag, int otherSuccess);
00130 void unlockRegion(LockRegion *region);
00131 void unlockLocalNodes(LockRegion *region);
00132 void unlockSharedIdxls(LockRegion *region);
00133 void unlockForRemote(RegionID regionID);
00134 void unpendForRemote(RegionID regionID);
00135 void unlockReply(int remoteChunk,RegionID regionID);
00136 void freeRegion(LockRegion *region);
00137
00139 FEM_Comm *FindIdxlSide(int idxlType);
00140
00141
00143 int IdxlAddPrimary(int localId, int sharedChk, int idxlType);
00145 bool IdxlAddSecondary(int localId, int sharedChk, int sharedIdx, int idxlType);
00147 int IdxlRemovePrimary(int localId, int sharedChk, int idxlType);
00149 bool IdxlRemoveSecondary(int sharedChk, int sharedIdx, int idxlType);
00150
00152 int IdxlLookUpPrimary(int localId, int sharedChk, int idxlType);
00154 int IdxlLookUpSecondary(int sharedChk, int sharedIdx, int idxlType);
00155
00157 adaptAdjMsg *remote_bulk_edge_bisect_2D(adaptAdj &nbrElem, adaptAdj &splitElem, int new_idxl, int n1_idxl, int n2_idxl, int partitionID);
00158
00159 void remote_adaptAdj_replace(adaptAdj &elem, adaptAdj &oldElem, adaptAdj &newElem);
00160 void remote_edgeAdj_replace(int remotePartID, adaptAdj &adj, adaptAdj &elem,
00161 adaptAdj &splitElem, int n1_idxl, int n2_idxl);
00162 void remote_edgeAdj_add(int remotePartID, adaptAdj &adj, adaptAdj &splitElem,
00163 int n1_idxl, int n2_idxl);
00164 void recv_split_3D(int pos, int tableID, adaptAdj &elem, adaptAdj &splitElem);
00165 void handle_split_3D(int remotePartID, int pos, int tableID, adaptAdj &elem, RegionID lockRegionID,
00166 int n1_idxl, int n2_idxl, int n5_idxl);
00167 void recv_splits(int tableID, int expectedSplits);
00168
00169 longestMsg *isLongest(int elem, int elemType, double len);
00170
00171 void update_asterisk_3D(int remotePartID, int i, adaptAdj &elem,
00172 int numElemPairs, adaptAdj *elemPairs, RegionID lockRegionID,
00173 int n1_idxl, int n2_idxl, int n5_idxl);
00174 };
00175
00177 class lockChunksMsg : public CMessage_lockChunksMsg {
00178 public:
00180 int *chkList;
00182 int chkListSize;
00184 int idxlType;
00185
00186 public:
00187 lockChunksMsg(int *c, int s, int type) {
00188 chkListSize = s;
00189 idxlType = type;
00190 }
00191
00192 ~lockChunksMsg() {
00194 }
00195
00196 int *getChks() {
00197 return chkList;
00198 }
00199
00200 int getSize() {
00201 return chkListSize;
00202 }
00203
00204 int getType() {
00205 return idxlType;
00206 }
00207 };
00208
00209 class adaptAdjMsg : public CMessage_adaptAdjMsg {
00210 public:
00211 adaptAdj elem;
00212 };
00213
00214 class longestMsg : public CMessage_longestMsg {
00215 public:
00216 bool longest;
00217 };
00218
00219 #endif
00220