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 replicaUniformPatchGrids, int lcpo,
00040                         int asplit, int bsplit, int csplit);
00041   void checkMap();
00042 
00043   ~PatchMap(void);
00044 
00045   enum { MaxTwoAway = 5*5*5 - 3*3*3 };
00046   enum { MaxOneAway = 3*3*3 - 1 };
00047   enum { MaxOneOrTwoAway = MaxOneAway + MaxTwoAway };
00048 
00049   static void registerPatchMgr(PatchMgr *pmgr) {
00050     CkpvAccess(PatchMap_patchMgr) = pmgr;
00051   }
00052 
00053   HomePatchList *homePatchList();
00054   void homePatchIDList(PatchIDList &);  // expensive - for startup only
00055   void basePatchIDList(int pe, PatchIDList &);  // use for required proxies
00056   int numHomePatches(void);
00057 
00058   // returns the number of patches being managed 
00059   inline int numPatches(void) const { return nPatches; }
00060   inline int numPatchesOnNode(int node) { return nPatchesOnNode[node]; }
00061   inline int numNodesWithPatches(void) { return nNodesWithPatches; }
00062 
00063   // returns the number of patches in each dimension
00064   inline int gridsize_a(void) const { return aDim; }
00065   inline int gridsize_b(void) const { return bDim; }
00066   inline int gridsize_c(void) const { return cDim; }
00067   // returns the number of patches in each dimension
00068   inline int numaway_a(void) const { return aAway; }
00069   inline int numaway_b(void) const { return bAway; }
00070   inline int numaway_c(void) const { return cAway; }
00071 
00072   // returns 1 if periodic in each dimension
00073   inline int periodic_a(void) const { return aPeriodic; }
00074   inline int periodic_b(void) const { return bPeriodic; }
00075   inline int periodic_c(void) const { return cPeriodic; }
00076 
00077   // returns the origin (minimum, not center) of patch grid
00078   inline ScaledPosition origin(void) const {
00079     return ScaledPosition(aOrigin,bOrigin,cOrigin);
00080   }
00081 
00082   // returns the patch id for the given indices
00083   inline int pid(int aIndex, int bIndex, int cIndex);
00084 
00085   // returns the [abc] index for the given patch id.
00086   inline int index_a(int pid) const { return pid % aDim; }
00087   inline int index_b(int pid) const { return (pid / aDim) % bDim; }
00088   inline int index_c(int pid) const { return pid / (aDim*bDim); }
00089 
00090   // returns the min/max [abc] scaled coordinate
00091   inline BigReal min_a(int pid) const { return patchBounds_a[patchData[pid].aIndex*2]; }
00092   inline BigReal max_a(int pid) const { return patchBounds_a[patchData[pid].aIndex*2+2]; }
00093   inline BigReal min_b(int pid) const { return patchBounds_b[patchData[pid].bIndex*2]; }
00094   inline BigReal max_b(int pid) const { return patchBounds_b[patchData[pid].bIndex*2+2]; }
00095   inline BigReal min_c(int pid) const { return patchBounds_c[patchData[pid].cIndex*2]; }
00096   inline BigReal max_c(int pid) const { return patchBounds_c[patchData[pid].cIndex*2+2]; }
00097 
00098   // returns the center of patch scaled position
00099   inline ScaledPosition center(int pid) const {
00100     const PatchData &pd = patchData[pid];
00101     return ScaledPosition(patchBounds_a[pd.aIndex*2+1],
00102                           patchBounds_b[pd.bIndex*2+1],
00103                           patchBounds_c[pd.cIndex*2+1]);
00104   }
00105 
00106   // asssigns atom to patch based on position and lattice
00107   inline PatchID assignToPatch(Position p, const Lattice &l);
00108 
00109   // gives more downstream patch of pid1, pid2; handles periodicity right
00110   // given patches must be neighbors!!!
00111   inline int downstream(int pid1, int pid2);
00112 
00113   // returns the node where the patch currently exists.
00114   inline int node(int pid) const { return patchData[pid].node; }
00115 
00116   // returns the node where the patch's upstream proxies exist.
00117   inline int basenode(int pid) const { return patchData[pid].basenode; }
00118 
00119   // numCids(pid) returns the number of compute ids which are registered
00120   inline int numCids(int pid) const { return patchData[pid].numCids; }
00121   
00122   // cid(pid,i) returns the i-th compute id registered
00123   inline int cid(int pid, int i) const { return patchData[pid].cids[i]; }
00124 
00125 #ifdef MEM_OPT_VERSION
00126   inline int numAtoms(int pid) const { return patchData[pid].numAtoms; }
00127   inline void setNumAtoms(int pid, int num) { patchData[pid].numAtoms = num; }
00128 
00129   inline int numFixedAtoms(int pid) const { return patchData[pid].numFixedAtoms; }
00130   inline void setNumFixedAtoms(int pid, int num) { patchData[pid].numFixedAtoms = num; }
00131 #endif
00132 
00133   void assignNode(PatchID, NodeID);
00134   void assignBaseNode(PatchID, NodeID);
00135   void assignBaseNode(PatchID);
00136 
00137   // newCid(pid,cid) stores a compute id associated with
00138   // patch id pid.  Error returned when there is no room to store
00139   // the pid.
00140   void newCid(int pid, int cid);
00141 
00142   // oneAwayNeighbors(pid, neighbor_ids) returns the number 
00143   // and ids of adjacent patches.  The caller is expected to provide
00144   // sufficient storage for the neighbors.
00145 
00146   int oneAwayNeighbors(int pid, PatchID *neighbor_ids=0);
00147 
00148   int oneOrTwoAwayNeighbors(int pid, PatchID *neighbor_ids,
00149                         PatchID *downstream_ids = 0, int *transform_ids = 0);
00150 
00151   //LCPO
00152   int getPatchesInOctet(int pid, PatchID *pids, int *transform_ids = 0);
00153 
00154   int upstreamNeighbors(int pid, PatchID *neighbor_ids);
00155 
00156   int downstreamNeighbors(int pid, PatchID *neighbor_ids); 
00157 
00158   void printPatchMap(void);
00159 
00160   inline Patch *patch(PatchID pid);
00161   inline HomePatch *homePatch(PatchID pid);
00162 
00163   void registerPatch(PatchID pid, HomePatch *pptr);
00164   void unregisterPatch(PatchID pid, HomePatch *pptr);
00165 
00166   void registerPatch(PatchID pid, Patch *pptr);
00167   void unregisterPatch(PatchID pid, Patch *pptr);
00168 
00169 protected:
00170   friend class WorkDistrib;
00171   int packSize(void);
00172   void pack(char *buf, int size);
00173   void unpack(char *buf);
00174   
00175   PatchMap(void);
00176   
00177 private:
00178   struct PatchData
00179   {
00180     int node, basenode;
00181     short aIndex, bIndex, cIndex;
00182     short numCids;
00183     short numCidsAllocated;
00184     ComputeID *cids;
00185 #ifdef MEM_OPT_VERSION
00186     //added to record #atoms in each patch initially
00187     //--Chao Mei
00188     unsigned short numAtoms;
00189     unsigned short numFixedAtoms;
00190 #endif
00191   };
00192   int nPatches;
00193   int nNodesWithPatches;
00194   static int *nPatchesOnNode;
00195   static PatchData *patchData;
00196   static ObjectArena<ComputeID> *computeIdArena;
00197   BigReal *patchBounds_a;
00198   BigReal *patchBounds_b;
00199   BigReal *patchBounds_c;
00200   Patch **myPatch;
00201   HomePatch **myHomePatch;
00202   int aDim, bDim, cDim;
00203   int aAway, bAway, cAway;
00204   int aPeriodic, bPeriodic, cPeriodic;
00205   int aMaxIndex, bMaxIndex, cMaxIndex;
00206   BigReal aOrigin, bOrigin, cOrigin;
00207   BigReal aLength, bLength, cLength;
00208 
00209 private:
00210   //It is used to store the atom ids that each patch has
00211   //we need this structure because we want to create and distribute
00212   //each patch one by one rather than creat all home patches at a time and then
00213   //send them later
00214   std::vector<int> *tmpPatchAtomsList;
00215 public:
00216   void initTmpPatchAtomsList(){
00217       tmpPatchAtomsList = new std::vector<int>[nPatches];
00218   }
00219   void delTmpPatchAtomsList() {
00220       for(int i=0; i<nPatches; i++){
00221           tmpPatchAtomsList[i].clear();
00222       }
00223       delete [] tmpPatchAtomsList;
00224       tmpPatchAtomsList = NULL;
00225   }
00226   std::vector<int> *getTmpPatchAtomsList(){
00227       return tmpPatchAtomsList;
00228   }
00229 
00230 };
00231 
00232 
00233 //----------------------------------------------------------------------
00234 
00235 inline Patch *PatchMap::patch(PatchID pid)
00236 {
00237   return myPatch[pid];
00238 }
00239 
00240 HomePatch *PatchMap::homePatch(PatchID pid)
00241 {
00242   return myHomePatch[pid];
00243 }
00244 
00245 #endif /* PATCHMAP_H */
00246 

Generated on Fri Sep 22 01:17:14 2017 for NAMD by  doxygen 1.4.7