00001
00007 #ifndef PATCHMAP_H
00008 #define PATCHMAP_H
00009
00010 #include "NamdTypes.h"
00011 #include "HomePatchList.h"
00012 #include "Lattice.h"
00013 #include "ProcessorPrivate.h"
00014
00015 #include <vector>
00016 using namespace std;
00017
00018
00019 class Patch;
00020 class PatchMgr;
00021 class HomePatch;
00022 template<class Type> class ObjectArena;
00023
00024 class PatchMap
00025 {
00026 public:
00027 static PatchMap *Instance();
00028 inline static PatchMap *Object() { return CkpvAccess(PatchMap_instance); }
00029
00030 int sizeGrid(ScaledPosition xmin, ScaledPosition xmax,
00031 const Lattice &lattice, BigReal patchSize,
00032 double maxNumPatches,
00033 int asplit, int bsplit, int csplit);
00034 void makePatches(ScaledPosition xmin, ScaledPosition xmax,
00035 const Lattice &lattice, BigReal patchSize,
00036 double maxNumPatches,
00037 int asplit, int bsplit, int csplit);
00038 void checkMap();
00039
00040 ~PatchMap(void);
00041
00042 enum { MaxTwoAway = 5*5*5 - 3*3*3 };
00043 enum { MaxOneAway = 3*3*3 - 1 };
00044 enum { MaxOneOrTwoAway = MaxOneAway + MaxTwoAway };
00045
00046 static void registerPatchMgr(PatchMgr *pmgr) {
00047 CkpvAccess(PatchMap_patchMgr) = pmgr;
00048 }
00049
00050 HomePatchList *homePatchList();
00051 void homePatchIDList(PatchIDList &);
00052 void basePatchIDList(int pe, PatchIDList &);
00053 int numHomePatches(void);
00054
00055
00056 inline int numPatches(void) const { return nPatches; }
00057 inline int numPatchesOnNode(int node) { return nPatchesOnNode[node]; }
00058 inline int numNodesWithPatches(void) { return nNodesWithPatches; }
00059
00060
00061 inline int gridsize_a(void) const { return aDim; }
00062 inline int gridsize_b(void) const { return bDim; }
00063 inline int gridsize_c(void) const { return cDim; }
00064
00065
00066 inline int numaway_a(void) const { return aAway; }
00067 inline int numaway_b(void) const { return bAway; }
00068 inline int numaway_c(void) const { return cAway; }
00069
00070
00071 inline int periodic_a(void) const { return aPeriodic; }
00072 inline int periodic_b(void) const { return bPeriodic; }
00073 inline int periodic_c(void) const { return cPeriodic; }
00074
00075
00076 inline ScaledPosition origin(void) const {
00077 return ScaledPosition(aOrigin,bOrigin,cOrigin);
00078 }
00079
00080
00081 inline int pid(int aIndex, int bIndex, int cIndex);
00082
00083
00084 inline int index_a(int pid) const { return pid % aDim; }
00085 inline int index_b(int pid) const { return (pid / aDim) % bDim; }
00086 inline int index_c(int pid) const { return pid / (aDim*bDim); }
00087
00088
00089 inline BigReal min_a(int pid) const { return patchData[pid].aMin; }
00090 inline BigReal max_a(int pid) const { return patchData[pid].aMax; }
00091 inline BigReal min_b(int pid) const { return patchData[pid].bMin; }
00092 inline BigReal max_b(int pid) const { return patchData[pid].bMax; }
00093 inline BigReal min_c(int pid) const { return patchData[pid].cMin; }
00094 inline BigReal max_c(int pid) const { return patchData[pid].cMax; }
00095
00096
00097 inline PatchID assignToPatch(Position p, const Lattice &l);
00098
00099
00100
00101 inline int downstream(int pid1, int pid2);
00102
00103
00104 inline int downstream2(int pid1, int pid2);
00105
00106
00107 inline int node(int pid) const { return patchData[pid].node; }
00108
00109
00110 inline int basenode(int pid) const { return patchData[pid].basenode; }
00111
00112
00113 inline int numCids(int pid) const { return patchData[pid].numCids; }
00114
00115
00116 inline int cid(int pid, int i) const { return patchData[pid].cids[i]; }
00117
00118 void assignNode(PatchID, NodeID);
00119 void assignBaseNode(PatchID, NodeID);
00120 void assignBaseNode(PatchID);
00121
00122
00123
00124
00125 void newCid(int pid, int cid);
00126
00127
00128
00129
00130
00131 int oneAwayNeighbors(int pid, PatchID *neighbor_ids=0, int *transform_ids=0);
00132
00133 int oneOrTwoAwayNeighbors(int pid, PatchID *neighbor_ids,
00134 int *transform_ids = 0);
00135
00136 int upstreamNeighbors(int pid, PatchID *neighbor_ids,
00137 int *transform_ids = 0);
00138
00139 int downstreamNeighbors(int pid, PatchID *neighbor_ids,
00140 int *transform_ids = 0);
00141
00142 void printPatchMap(void);
00143
00144 inline Patch *patch(PatchID pid);
00145 HomePatch *homePatch(PatchID pid);
00146
00147 void registerPatch(PatchID pid, HomePatch *pptr);
00148 void unregisterPatch(PatchID pid, HomePatch *pptr);
00149
00150 void registerPatch(PatchID pid, Patch *pptr);
00151 void unregisterPatch(PatchID pid, Patch *pptr);
00152
00153 protected:
00154 friend class WorkDistrib;
00155 int packSize(void);
00156 void pack(char *buf);
00157 void unpack(char *buf);
00158
00159 PatchMap(void);
00160
00161 private:
00162 struct PatchData
00163 {
00164 int node, basenode;
00165 int aIndex, bIndex, cIndex;
00166 Coordinate aMin, aMax, bMin, bMax, cMin, cMax;
00167 int numCids;
00168 int numCidsAllocated;
00169 ComputeID *cids;
00170 Patch *myPatch;
00171 HomePatch *myHomePatch;
00172 };
00173 int nPatches;
00174 int nNodesWithPatches;
00175 int *nPatchesOnNode;
00176 PatchData *patchData;
00177 ObjectArena<ComputeID> *computeIdArena;
00178 int aDim, bDim, cDim;
00179 int aAway, bAway, cAway;
00180 int aPeriodic, bPeriodic, cPeriodic;
00181 int aMaxIndex, bMaxIndex, cMaxIndex;
00182 BigReal aOrigin, bOrigin, cOrigin;
00183 BigReal aLength, bLength, cLength;
00184
00185 private:
00186
00187
00188
00189
00190 vector<int> *tmpPatchAtomsList;
00191 public:
00192 void initTmpPatchAtomsList(){
00193 tmpPatchAtomsList = new vector<int>[nPatches];
00194 }
00195 void delTmpPatchAtomsList() {
00196 for(int i=0; i<nPatches; i++){
00197 tmpPatchAtomsList[i].clear();
00198 }
00199 delete [] tmpPatchAtomsList;
00200 tmpPatchAtomsList = NULL;
00201 }
00202 vector<int> *getTmpPatchAtomsList(){
00203 return tmpPatchAtomsList;
00204 }
00205
00206 };
00207
00208
00209
00210
00211 inline Patch *PatchMap::patch(PatchID pid)
00212 {
00213 return patchData[pid].myPatch;
00214 }
00215
00216 #endif
00217