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

HomePatch.h

Go to the documentation of this file.
00001 
00007 /*
00008    HomePatch is the key distributed source/sink of Atom data
00009    including positions, velocities and forces applied
00010 */
00011 
00012 #ifndef HOMEPATCH_H
00013 #define HOMEPATCH_H
00014 
00015 #include "charm++.h"
00016 
00017 #include "NamdTypes.h"
00018 #include "Patch.h"
00019 #include "PatchMap.h"
00020 
00021 #include "MigrateAtomsMsg.h"
00022 #include "HomePatchTypes.h"
00023 #include "main.h"
00024 #include "common.h"
00025 #include "Migration.h"
00026 
00027 class RegisterProxyMsg;
00028 class UnregisterProxyMsg;
00029 class ProxyResultVarsizeMsg;
00030 class ProxyResultMsg;
00031 class ProxyCombinedResultMsg;
00032 class Sequencer;
00033 class SubmitReduction;
00034 
00035 class ProxyNodeAwareSpanningTreeMsg;
00036 
00037 class HomePatch : public Patch {
00038   friend class PatchMgr;
00039   friend class Sequencer;
00040   friend class ComputeGlobal;
00041 
00042 private: 
00043   // for PatchMgr to use only
00044   HomePatch(PatchID, FullAtomList);
00045 
00046   HomePatch(PatchID, int atomCnt);
00047 
00048   void reinitAtoms(FullAtomList);
00049   ScaledPosition min, max, center;
00050   int aAway, bAway, cAway;
00051 
00052 #ifdef MEM_OPT_VERSION
00053   //Note: If new proxies are added to this HomePatch
00054   // after load balancing, and it is not the immediate step
00055   // after atom migration (where ProxyAllMsg will be sent), 
00056   // then the CompAtomExt list has to be resent with the 
00057   // ProxyDataMsg (the normal proxy msg when atoms don't 
00058   // migrate), otherwise, program will crash without such 
00059   // information when doing force calculations --Chao Mei
00060   Bool isNewProxyAdded;
00061 #endif
00062 
00063 public:
00064   ~HomePatch();
00065 
00066   // Message from ProxyPatch (via ProxyMgr) which registers its existence
00067   void registerProxy(RegisterProxyMsg *);
00068   // opposite of above
00069   void unregisterProxy(UnregisterProxyMsg *);
00070 
00071   // ProxyPatch sends Forces back to here (via ProxyMgr)  
00072   void receiveResults(ProxyResultVarsizeMsg *msg);
00073   void receiveResults(ProxyResultMsg *msg);     
00074 
00075   void receiveResults(ProxyCombinedResultMsg *msg);
00076 
00077   // AtomMigration messages passes from neighbor HomePatches to here.
00078   void depositMigration(MigrateAtomsMsg *);
00079 
00080   // Bind a Sequencer to this HomePatch
00081   void useSequencer(Sequencer *sequencerPtr);
00082   // start simulation over this Patch of atoms
00083   void runSequencer(void);
00084   
00085   //--------------------------------------------------------------------
00086   // methods for Sequencer to use
00087   //
00088 
00089   // Signal HomePatch that positions stored are to be now to be used
00090   void positionsReady(int doMigration=0);
00091   int marginViolations;
00092 
00093   // methods to implement integration
00094   void saveForce(const int ftag = Results::normal);
00095   void addForceToMomentum(const BigReal, const int ftag = Results::normal,
00096                                 const int useSaved = 0);
00097   void addVelocityToPosition(const BigReal);
00098 
00099   // methods for rigidBonds
00100   int rattle1(const BigReal, Tensor *virial, SubmitReduction *);
00101   void rattle2(const BigReal, Tensor *virial);
00102 
00103   // methods for mollified impluse (MOLLY)
00104   void mollyAverage();
00105   void mollyMollify(Tensor *virial);
00106 //  Bool average(Vector qtilde[],const Vector q[],BigReal lambda[],const int n,const int m, const BigReal imass[], const BigReal length2[], const int ial[], const int ilb[], const Vector qji[], const BigReal tolf, const int ntrial);
00107 //  void mollify(Vector qtilde[],const Vector q0[],const BigReal lambda[], Vector force[],const int n, const int m, const BigReal imass[],const int ial[],const int ibl[],const Vector refab[]); 
00108 
00109   // methods for CONTRA, etc
00110   void checkpoint(void);
00111   void revert(void);
00112 
00113   // methods for QM (ExtForces replacement)
00114   void replaceForces(ExtForce *f);
00115 
00116   // load-balancing trigger
00117   void submitLoadStats(int timestep);
00118 
00119   // for ComputeHomePatches
00120   FullAtomList &getAtomList() { return (atom); }
00121   // set home patch's atom list
00122   void setAtomList(FullAtomList *al) {
00123       atom = *al;
00124   }
00125 
00126 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00127   // build spanning tree for proxy nodes
00128   void buildNodeAwareSpanningTree(void);
00129   void setupChildrenFromProxySpanningTree();
00130 #else
00131     // build spanning tree for proxy nodes
00132   void buildSpanningTree(void);
00133 #endif
00134 
00135   void sendNodeAwareSpanningTree();
00136   void recvNodeAwareSpanningTree(ProxyNodeAwareSpanningTreeMsg *msg);
00137 
00138   void sendSpanningTree();
00139   void recvSpanningTree(int *t, int n);
00140 
00141 
00142   void sendProxies();
00143 
00144 #if USE_TOPOMAP 
00145   int findSubroots(int dim, int* subroots, int psize, int* pidscopy);
00146 #endif
00147 
00148 protected:
00149   virtual void boxClosed(int);
00150 
00151   // Internal Atom Migration methods and data
00152   void doPairlistCheck();
00153   void doGroupSizeCheck();
00154   void doMarginCheck();
00155   void doAtomMigration();
00156   int inMigration;
00157   int numMlBuf;
00158   MigrateAtomsMsg *msgbuf[PatchMap::MaxOneAway];
00159   
00160 private:
00161   // Store of Atom-wise variables
00162   FullAtomList  atom;
00163   ForceList f_saved[Results::maxNumForces];
00164   ExtForce *replacementForces;
00165 
00166 
00167   // DMK - Atom Separation (water vs. non-water)
00168   #if NAMD_SeparateWaters != 0
00169     FullAtomList tempAtom;  // A temporary array used to sort waters
00170                             //   from non-waters in the atom array
00171     void separateAtoms();   // Function to separate the atoms currently in atoms.
00172     void mergeAtomList(FullAtomList &al);  // Function to combine and separate
00173                                            //   the atoms in al with atoms.
00174   #endif
00175 
00176 
00177   // checkpointed state
00178   FullAtomList  checkpoint_atom;
00179   Lattice  checkpoint_lattice;
00180 
00181   // DMK - Atom Separation (water vs. non-water)
00182   #if NAMD_SeparateWaters != 0
00183     int checkpoint_numWaterAtoms;
00184   #endif
00185 
00186 
00187   // checkPairlist data
00188   CompAtomList doPairlistCheck_positions;
00189   Lattice doPairlistCheck_lattice;
00190   BigReal doPairlistCheck_newTolerance;
00191 
00192   // MOLLY data
00193   ResizeArray<BigReal> molly_lambda;
00194   
00195   // List of Proxies
00196   ProxyList     proxy;
00197   
00198   Sequencer  *sequencer;
00199 
00200   // Needed for initialization
00201   int patchMapRead;
00202   void readPatchMap();
00203 
00204   // Atom Migration internals
00205   int allMigrationIn;
00206   int migrationSuspended;
00207   int patchMigrationCounter;
00208   int numNeighbors;
00209   MigrationInfo realInfo[PatchMap::MaxOneAway];
00210   MigrationInfo *mInfo[3][3][3];
00211 
00212 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00213   //the whole spanning tree for all the proxies this home patch has
00214   proxyTreeNodeList ptnTree;
00215   //the immediate children (recording pe ids) containing two parts: 
00216   //one part of them all belong to the physical node this home patch
00217   // resides on; the other part of pes belong to all external nodes.
00218   /* Moved to Patch.h */ 
00219   //int *children;
00220   //int numChild;
00221 #else
00222   NodeIDList tree;              // the whole tree
00223   int *child;   // spanning tree of proxies - immediate children
00224   int nChild;
00225 #endif
00226 
00227   // PLF -- for TIP4P
00228   void redistrib_tip4p_force(Vector&, Vector&, Vector&, Vector&, int, Tensor*);
00229   void redistrib_tip4p_forces(const int, Tensor*);
00230   void tip4_omrepos(Vector*, Vector*, Vector*, BigReal);
00231   void init_tip4();
00232   BigReal r_om, r_ohc;
00233 
00234 #if CMK_PERSISTENT_COMM
00235   PersistentHandle *localphs;
00236   int nphs;
00237 public:
00238   int phsReady;
00239   void destoryPersistComm();
00240 #endif
00241 };
00242 
00243 #endif
00244 

Generated on Sun Sep 7 04:07:41 2008 for NAMD by  doxygen 1.3.9.1