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   // asssigns atom to patch based on position and lattice
00097   inline PatchID assignToPatch(Position p, const Lattice &l);
00098 
00099   // gives more downstream patch of pid1, pid2; handles periodicity right
00100   // given patches must be neighbors!!!
00101   inline int downstream(int pid1, int pid2);
00102 
00103   // if not neighbors use this slower version
00104   inline int downstream2(int pid1, int pid2);
00105 
00106   // returns the node where the patch currently exists.
00107   inline int node(int pid) const { return patchData[pid].node; }
00108 
00109   // returns the node where the patch's upstream proxies exist.
00110   inline int basenode(int pid) const { return patchData[pid].basenode; }
00111 
00112   // numCids(pid) returns the number of compute ids which are registered
00113   inline int numCids(int pid) const { return patchData[pid].numCids; }
00114   
00115   // cid(pid,i) returns the i-th compute id registered
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   // newCid(pid,cid) stores a compute id associated with
00123   // patch id pid.  Error returned when there is no room to store
00124   // the pid.
00125   void newCid(int pid, int cid);
00126 
00127   // oneAwayNeighbors(pid, &n, neighbor_ids) returns the number 
00128   // and ids of adjacent patches.  The caller is expected to provide
00129   // sufficient storage for the neighbors.
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   //It is used to store the atom ids that each patch has
00187   //we need this structure because we want to create and distribute
00188   //each patch one by one rather than creat all home patches at a time and then
00189   //send them later
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 /* PATCHMAP_H */
00217 

Generated on Thu Aug 28 04:07:42 2008 for NAMD by  doxygen 1.3.9.1