| 1 | /* | 
| 2 | * Copyright (c) 2011 The University of Notre Dame. All Rights Reserved. | 
| 3 | * | 
| 4 | * The University of Notre Dame grants you ("Licensee") a | 
| 5 | * non-exclusive, royalty free, license to use, modify and | 
| 6 | * redistribute this software in source and binary code form, provided | 
| 7 | * that the following conditions are met: | 
| 8 | * | 
| 9 | * 1. Redistributions of source code must retain the above copyright | 
| 10 | *    notice, this list of conditions and the following disclaimer. | 
| 11 | * | 
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 | *    notice, this list of conditions and the following disclaimer in the | 
| 14 | *    documentation and/or other materials provided with the | 
| 15 | *    distribution. | 
| 16 | * | 
| 17 | * This software is provided "AS IS," without a warranty of any | 
| 18 | * kind. All express or implied conditions, representations and | 
| 19 | * warranties, including any implied warranty of merchantability, | 
| 20 | * fitness for a particular purpose or non-infringement, are hereby | 
| 21 | * excluded.  The University of Notre Dame and its licensors shall not | 
| 22 | * be liable for any damages suffered by licensee as a result of | 
| 23 | * using, modifying or distributing the software or its | 
| 24 | * derivatives. In no event will the University of Notre Dame or its | 
| 25 | * licensors be liable for any lost revenue, profit or data, or for | 
| 26 | * direct, indirect, special, consequential, incidental or punitive | 
| 27 | * damages, however caused and regardless of the theory of liability, | 
| 28 | * arising out of the use of or inability to use software, even if the | 
| 29 | * University of Notre Dame has been advised of the possibility of | 
| 30 | * such damages. | 
| 31 | * | 
| 32 | * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your | 
| 33 | * research, please cite the appropriate papers when you publish your | 
| 34 | * work.  Good starting points are: | 
| 35 | * | 
| 36 | * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | 
| 37 | * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | 
| 38 | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). | 
| 39 | * [4]  Vardeman & Gezelter, in progress (2009). | 
| 40 | */ | 
| 41 |  | 
| 42 | #ifndef PARALLEL_FORCEDECOMPOSITION_HPP | 
| 43 | #define PARALLEL_FORCEDECOMPOSITION_HPP | 
| 44 |  | 
| 45 | #include "brains/SimInfo.hpp" | 
| 46 | #include "brains/SnapshotManager.hpp" | 
| 47 | #include "nonbonded/NonBondedInteraction.hpp" | 
| 48 | #include "nonbonded/Cutoffs.hpp" | 
| 49 | #include "nonbonded/InteractionManager.hpp" | 
| 50 | #include "utils/Tuple.hpp" | 
| 51 |  | 
| 52 | using namespace std; | 
| 53 | namespace OpenMD { | 
| 54 |  | 
| 55 | typedef tuple3<RealType, RealType, RealType> groupCutoffs; | 
| 56 |  | 
| 57 | /** | 
| 58 | * @class ForceDecomposition | 
| 59 | * | 
| 60 | * ForceDecomposition is an interface for passing out and collecting | 
| 61 | * information from many processors at various stages of the main | 
| 62 | * non-bonded ForceLoop. | 
| 63 | * | 
| 64 | * The pairwise force calculation has an outer-running loop (the "I" | 
| 65 | * loop) and an inner-running loop (the "J" loop).  In parallel | 
| 66 | * decompositions, these loop over different groups of atoms on | 
| 67 | * different processors.  Between each set of computations on the | 
| 68 | * local processor, data must be exchanged among the processors. | 
| 69 | * This can happen at different times in the calculation: | 
| 70 | * | 
| 71 | *  distributeInitialData      (parallel communication - one time only) | 
| 72 | *  distributeData             (parallel communication - every ForceLoop) | 
| 73 | * | 
| 74 | *  loop iLoop over nLoops     (nLoops may be 1, 2, or until self consistent) | 
| 75 | *  |  loop over i | 
| 76 | *  |  | loop over j | 
| 77 | *  |  | | localComputation | 
| 78 | *  |  |  end | 
| 79 | *  |  end | 
| 80 | *  |  if (nLoops > 1): | 
| 81 | *  |  |   collectIntermediateData    (parallel communication) | 
| 82 | *  |  |   distributeIntermediateData (parallel communication) | 
| 83 | *  |  endif | 
| 84 | *  end | 
| 85 | * collectData                        (parallel communication) | 
| 86 | * | 
| 87 | * ForceDecomposition provides the interface for ForceLoop to do the | 
| 88 | * communication steps and to iterate using the correct set of atoms | 
| 89 | * and cutoff groups. | 
| 90 | */ | 
| 91 | class ForceDecomposition { | 
| 92 | public: | 
| 93 |  | 
| 94 | ForceDecomposition(SimInfo* info); | 
| 95 | virtual ~ForceDecomposition() {} | 
| 96 |  | 
| 97 | virtual void distributeInitialData() = 0; | 
| 98 | virtual void distributeData() = 0; | 
| 99 | virtual void zeroWorkArrays() = 0; | 
| 100 | virtual void collectIntermediateData() = 0; | 
| 101 | virtual void distributeIntermediateData() = 0; | 
| 102 | virtual void collectData() = 0; | 
| 103 | virtual potVec getLongRangePotential() { return longRangePot_; } | 
| 104 |  | 
| 105 | // neighbor list routines | 
| 106 | virtual bool checkNeighborList(); | 
| 107 | virtual vector<pair<int, int> >  buildNeighborList() = 0; | 
| 108 |  | 
| 109 | // how to handle cutoffs: | 
| 110 | void setCutoffPolicy(CutoffPolicy cp) {cutoffPolicy_ = cp;} | 
| 111 | void setUserCutoff(RealType rcut) {userCutoff_ = rcut; userChoseCutoff_ = true; } | 
| 112 |  | 
| 113 | // group bookkeeping | 
| 114 | virtual groupCutoffs getGroupCutoffs(int cg1, int cg2) = 0; | 
| 115 |  | 
| 116 | // Group->atom bookkeeping | 
| 117 | virtual vector<int> getAtomsInGroupRow(int cg1) = 0; | 
| 118 | virtual vector<int> getAtomsInGroupColumn(int cg2) = 0; | 
| 119 |  | 
| 120 | virtual Vector3d getAtomToGroupVectorRow(int atom1, int cg1) = 0; | 
| 121 | virtual Vector3d getAtomToGroupVectorColumn(int atom2, int cg2) = 0; | 
| 122 | virtual RealType getMassFactorRow(int atom1) = 0; | 
| 123 | virtual RealType getMassFactorColumn(int atom2) = 0; | 
| 124 |  | 
| 125 | // spatial data | 
| 126 | virtual Vector3d getIntergroupVector(int cg1, int cg2) = 0; | 
| 127 | virtual Vector3d getInteratomicVector(int atom1, int atom2) = 0; | 
| 128 |  | 
| 129 | // atom bookkeeping | 
| 130 | virtual int getNAtomsInRow() = 0; | 
| 131 | virtual vector<int> getSkipsForRowAtom(int atom1) = 0; | 
| 132 | virtual bool skipAtomPair(int atom1, int atom2) = 0; | 
| 133 | virtual void addForceToAtomRow(int atom1, Vector3d fg) = 0; | 
| 134 | virtual void addForceToAtomColumn(int atom2, Vector3d fg) = 0; | 
| 135 |  | 
| 136 | // filling interaction blocks with pointers | 
| 137 | virtual InteractionData fillInteractionData(int atom1, int atom2) = 0; | 
| 138 | virtual void unpackInteractionData(InteractionData idat, int atom1, int atom2) = 0; | 
| 139 | virtual InteractionData fillSkipData(int atom1, int atom2) = 0; | 
| 140 | virtual SelfData fillSelfData(int atom1); | 
| 141 |  | 
| 142 | protected: | 
| 143 | SimInfo* info_; | 
| 144 | SnapshotManager* sman_; | 
| 145 | Snapshot* snap_; | 
| 146 | ForceField* ff_; | 
| 147 | InteractionManager* interactionMan_; | 
| 148 |  | 
| 149 | int storageLayout_; | 
| 150 | RealType skinThickness_;   /**< Verlet neighbor list skin thickness */ | 
| 151 | RealType largestRcut_; | 
| 152 |  | 
| 153 | map<pair<int, int>, int> topoDist; //< topoDist gives the | 
| 154 | //topological distance between | 
| 155 | //two atomic sites.  This | 
| 156 | //declaration is agnostic | 
| 157 | //regarding the parallel | 
| 158 | //decomposition.  The two | 
| 159 | //indices could be local or row | 
| 160 | //& column.  It will be up to | 
| 161 | //the specific decomposition | 
| 162 | //method to fill this. | 
| 163 | map<pair<int, int>, bool> exclude; //< exclude is the set of pairs | 
| 164 | //to leave out of non-bonded | 
| 165 | //force evaluations.  This | 
| 166 | //declaration is agnostic | 
| 167 | //regarding the parallel | 
| 168 | //decomposition.  The two | 
| 169 | //indices could be local or row | 
| 170 | //& column.  It will be up to | 
| 171 | //the specific decomposition | 
| 172 | //method to fill this. | 
| 173 |  | 
| 174 | vector<vector<int> > groupList_; | 
| 175 |  | 
| 176 | vector<Vector3i> cellOffsets_; | 
| 177 | Vector3i nCells_; | 
| 178 | vector<vector<int> > cellList_; | 
| 179 | vector<Vector3d> saved_CG_positions_; | 
| 180 | potVec longRangePot_; | 
| 181 |  | 
| 182 | bool userChoseCutoff_; | 
| 183 | RealType userCutoff_; | 
| 184 | CutoffPolicy cutoffPolicy_; | 
| 185 |  | 
| 186 | map<pair<int, int>, tuple3<RealType, RealType, RealType> > gTypeCutoffMap; | 
| 187 |  | 
| 188 | }; | 
| 189 | } | 
| 190 | #endif |