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 
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,
00035                         int asplit, int bsplit, int csplit);
00036   void makePatches(ScaledPosition xmin, ScaledPosition xmax,
00037                         const Lattice &lattice, BigReal patchSize,
00038                         double maxNumPatches,
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   int upstreamNeighbors(int pid, PatchID *neighbor_ids);
00151 
00152   int downstreamNeighbors(int pid, PatchID *neighbor_ids); 
00153 
00154   void printPatchMap(void);
00155 
00156   inline Patch *patch(PatchID pid);
00157   inline HomePatch *homePatch(PatchID pid);
00158 
00159   void registerPatch(PatchID pid, HomePatch *pptr);
00160   void unregisterPatch(PatchID pid, HomePatch *pptr);
00161 
00162   void registerPatch(PatchID pid, Patch *pptr);
00163   void unregisterPatch(PatchID pid, Patch *pptr);
00164 
00165 protected:
00166   friend class WorkDistrib;
00167   int packSize(void);
00168   void pack(char *buf);
00169   void unpack(char *buf);
00170   
00171   PatchMap(void);
00172   
00173 private:
00174   struct PatchData
00175   {
00176     int node, basenode;
00177     short aIndex, bIndex, cIndex;
00178     short numCids;
00179     short numCidsAllocated;
00180     ComputeID *cids;
00181 #ifdef MEM_OPT_VERSION
00182     //added to record #atoms in each patch initially
00183     //--Chao Mei
00184     unsigned short numAtoms;
00185     unsigned short numFixedAtoms;
00186 #endif
00187   };
00188   int nPatches;
00189   int nNodesWithPatches;
00190   static int *nPatchesOnNode;
00191   static PatchData *patchData;
00192   static ObjectArena<ComputeID> *computeIdArena;
00193   BigReal *patchBounds_a;
00194   BigReal *patchBounds_b;
00195   BigReal *patchBounds_c;
00196   Patch **myPatch;
00197   HomePatch **myHomePatch;
00198   int aDim, bDim, cDim;
00199   int aAway, bAway, cAway;
00200   int aPeriodic, bPeriodic, cPeriodic;
00201   int aMaxIndex, bMaxIndex, cMaxIndex;
00202   BigReal aOrigin, bOrigin, cOrigin;
00203   BigReal aLength, bLength, cLength;
00204 
00205 private:
00206   //It is used to store the atom ids that each patch has
00207   //we need this structure because we want to create and distribute
00208   //each patch one by one rather than creat all home patches at a time and then
00209   //send them later
00210   std::vector<int> *tmpPatchAtomsList;
00211 public:
00212   void initTmpPatchAtomsList(){
00213       tmpPatchAtomsList = new std::vector<int>[nPatches];
00214   }
00215   void delTmpPatchAtomsList() {
00216       for(int i=0; i<nPatches; i++){
00217           tmpPatchAtomsList[i].clear();
00218       }
00219       delete [] tmpPatchAtomsList;
00220       tmpPatchAtomsList = NULL;
00221   }
00222   std::vector<int> *getTmpPatchAtomsList(){
00223       return tmpPatchAtomsList;
00224   }
00225 
00226 };
00227 
00228 
00229 //----------------------------------------------------------------------
00230 
00231 inline Patch *PatchMap::patch(PatchID pid)
00232 {
00233   return myPatch[pid];
00234 }
00235 
00236 HomePatch *PatchMap::homePatch(PatchID pid)
00237 {
00238   return myHomePatch[pid];
00239 }
00240 
00241 #endif /* PATCHMAP_H */
00242 

Generated on Sun Feb 12 04:07:56 2012 for NAMD by  doxygen 1.3.9.1