Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

PatchMap.h

Go to the documentation of this file.
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 &);  // expensive - for startup only
00054   void basePatchIDList(int pe, PatchIDList &);  // use for required proxies
00055   int numHomePatches(void);
00056 
00057   // returns the number of patches being managed 
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   // returns the number of patches in each dimension
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   // returns the number of patches in each dimension
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   // returns 1 if periodic in each dimension
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   // returns the origin (minimum, not center) of patch grid
00077   inline ScaledPosition origin(void) const {
00078     return ScaledPosition(aOrigin,bOrigin,cOrigin);
00079   }
00080 
00081   // returns the patch id for the given indices
00082   inline int pid(int aIndex, int bIndex, int cIndex);
00083 
00084   // returns the [abc] index for the given patch id.
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   // returns the min/max [abc] scaled coordinate
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   // returns the center of patch scaled position
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   // asssigns atom to patch based on position and lattice
00106   inline PatchID assignToPatch(Position p, const Lattice &l);
00107 
00108   // gives more downstream patch of pid1, pid2; handles periodicity right
00109   // given patches must be neighbors!!!
00110   inline int downstream(int pid1, int pid2);
00111 
00112   // returns the node where the patch currently exists.
00113   inline int node(int pid) const { return patchData[pid].node; }
00114 
00115   // returns the node where the patch's upstream proxies exist.
00116   inline int basenode(int pid) const { return patchData[pid].basenode; }
00117 
00118   // numCids(pid) returns the number of compute ids which are registered
00119   inline int numCids(int pid) const { return patchData[pid].numCids; }
00120   
00121   // cid(pid,i) returns the i-th compute id registered
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   // newCid(pid,cid) stores a compute id associated with
00137   // patch id pid.  Error returned when there is no room to store
00138   // the pid.
00139   void newCid(int pid, int cid);
00140 
00141   // oneAwayNeighbors(pid, neighbor_ids) returns the number 
00142   // and ids of adjacent patches.  The caller is expected to provide
00143   // sufficient storage for the neighbors.
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   //LCPO
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     //added to record #atoms in each patch initially
00186     //--Chao Mei
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   //It is used to store the atom ids that each patch has
00210   //we need this structure because we want to create and distribute
00211   //each patch one by one rather than creat all home patches at a time and then
00212   //send them later
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 /* PATCHMAP_H */
00245 

Generated on Thu May 23 04:07:17 2013 for NAMD by  doxygen 1.3.9.1