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