Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | 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 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 &);  // expensive - for startup only
00052   void basePatchIDList(int pe, PatchIDList &);  // use for required proxies
00053   int numHomePatches(void);
00054 
00055   // returns the number of patches being managed 
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   // returns the number of patches in each dimension
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   // returns the number of patches in each dimension
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   // returns 1 if periodic in each dimension
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   // returns the origin (minimum, not center) of patch grid
00076   inline ScaledPosition origin(void) const {
00077     return ScaledPosition(aOrigin,bOrigin,cOrigin);
00078   }
00079 
00080   // returns the patch id for the given indices
00081   inline int pid(int aIndex, int bIndex, int cIndex);
00082 
00083   // returns the [abc] index for the given patch id.
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   // returns the min/max [abc] scaled coordinate
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   // returns the center of patch scaled position
00097   inline ScaledPosition center(int pid) const { return patchData[pid].center; }
00098 
00099   // asssigns atom to patch based on position and lattice
00100   inline PatchID assignToPatch(Position p, const Lattice &l);
00101 
00102   // gives more downstream patch of pid1, pid2; handles periodicity right
00103   // given patches must be neighbors!!!
00104   inline int downstream(int pid1, int pid2);
00105 
00106   // if not neighbors use this slower version
00107   inline int downstream2(int pid1, int pid2);
00108 
00109   // returns the node where the patch currently exists.
00110   inline int node(int pid) const { return patchData[pid].node; }
00111 
00112   // returns the node where the patch's upstream proxies exist.
00113   inline int basenode(int pid) const { return patchData[pid].basenode; }
00114 
00115   // numCids(pid) returns the number of compute ids which are registered
00116   inline int numCids(int pid) const { return patchData[pid].numCids; }
00117   
00118   // cid(pid,i) returns the i-th compute id registered
00119   inline int cid(int pid, int i) const { return patchData[pid].cids[i]; }
00120 
00121   void assignNode(PatchID, NodeID);
00122   void assignBaseNode(PatchID, NodeID);
00123   void assignBaseNode(PatchID);
00124 
00125   // newCid(pid,cid) stores a compute id associated with
00126   // patch id pid.  Error returned when there is no room to store
00127   // the pid.
00128   void newCid(int pid, int cid);
00129 
00130   // oneAwayNeighbors(pid, &n, neighbor_ids) returns the number 
00131   // and ids of adjacent patches.  The caller is expected to provide
00132   // sufficient storage for the neighbors.
00133 
00134   int oneAwayNeighbors(int pid, PatchID *neighbor_ids=0, int *transform_ids=0);
00135 
00136   int oneOrTwoAwayNeighbors(int pid, PatchID *neighbor_ids,
00137                             int *transform_ids = 0);
00138 
00139   int upstreamNeighbors(int pid, PatchID *neighbor_ids, 
00140                         int *transform_ids = 0);
00141 
00142   int downstreamNeighbors(int pid, PatchID *neighbor_ids, 
00143                           int *transform_ids = 0);
00144 
00145   void printPatchMap(void);
00146 
00147   inline Patch *patch(PatchID pid);
00148   HomePatch *homePatch(PatchID pid);
00149 
00150   void registerPatch(PatchID pid, HomePatch *pptr);
00151   void unregisterPatch(PatchID pid, HomePatch *pptr);
00152 
00153   void registerPatch(PatchID pid, Patch *pptr);
00154   void unregisterPatch(PatchID pid, Patch *pptr);
00155 
00156 protected:
00157   friend class WorkDistrib;
00158   int packSize(void);
00159   void pack(char *buf);
00160   void unpack(char *buf);
00161   
00162   PatchMap(void);
00163   
00164 private:
00165   struct PatchData
00166   {
00167     int node, basenode;
00168     int aIndex, bIndex, cIndex;
00169     Coordinate aMin, aMax, bMin, bMax, cMin, cMax;
00170     ScaledPosition center;
00171     int numCids;
00172     int numCidsAllocated;
00173     ComputeID *cids;
00174     Patch *myPatch;
00175     HomePatch *myHomePatch;
00176   };
00177   int nPatches;
00178   int nNodesWithPatches;
00179   int *nPatchesOnNode;
00180   PatchData *patchData;
00181   ObjectArena<ComputeID> *computeIdArena;
00182   int aDim, bDim, cDim;
00183   int aAway, bAway, cAway;
00184   int aPeriodic, bPeriodic, cPeriodic;
00185   int aMaxIndex, bMaxIndex, cMaxIndex;
00186   BigReal aOrigin, bOrigin, cOrigin;
00187   BigReal aLength, bLength, cLength;
00188 
00189 private:
00190   //It is used to store the atom ids that each patch has
00191   //we need this structure because we want to create and distribute
00192   //each patch one by one rather than creat all home patches at a time and then
00193   //send them later
00194   vector<int> *tmpPatchAtomsList;
00195 public:
00196   void initTmpPatchAtomsList(){
00197       tmpPatchAtomsList = new vector<int>[nPatches];
00198   }
00199   void delTmpPatchAtomsList() {
00200       for(int i=0; i<nPatches; i++){
00201           tmpPatchAtomsList[i].clear();
00202       }
00203       delete [] tmpPatchAtomsList;
00204       tmpPatchAtomsList = NULL;
00205   }
00206   vector<int> *getTmpPatchAtomsList(){
00207       return tmpPatchAtomsList;
00208   }
00209 
00210 };
00211 
00212 
00213 //----------------------------------------------------------------------
00214 
00215 inline Patch *PatchMap::patch(PatchID pid)
00216 {
00217   return patchData[pid].myPatch;
00218 }
00219 
00220 #endif /* PATCHMAP_H */
00221 

Generated on Sat Nov 7 04:07:49 2009 for NAMD by  doxygen 1.3.9.1