Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2017-2023 The plumed team 3 : (see the PEOPLE file at the root of the distribution for a list of names) 4 : 5 : See http://www.plumed.org for more information. 6 : 7 : This file is part of plumed, version 2. 8 : 9 : plumed is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : plumed is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with plumed. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : #ifndef __PLUMED_core_DomainDecomposition_h 23 : #define __PLUMED_core_DomainDecomposition_h 24 : 25 : #include "ActionForInterface.h" 26 : #include "tools/Communicator.h" 27 : 28 : namespace PLMD { 29 : 30 : class ActionToPutData; 31 : class ActionAtomistic; 32 : 33 : class DomainDecomposition : public ActionForInterface { 34 : private: 35 : class DomainComms : public Communicator { 36 : public: 37 : bool on; 38 : bool async; 39 : 40 : std::vector<Communicator::Request> mpi_request_positions; 41 : std::vector<Communicator::Request> mpi_request_index; 42 : 43 : std::vector<double> positionsToBeSent; 44 : std::vector<double> positionsToBeReceived; 45 : std::vector<int> indexToBeSent; 46 : std::vector<int> indexToBeReceived; 47 : operator bool() const { 48 501527 : return on; 49 : } 50 1216 : DomainComms(): on(false), async(false) {} 51 : void enable(Communicator& c); 52 : }; 53 : DomainComms dd; 54 : long int ddStep; 55 : 56 : std::vector<int> gatindex; 57 : /// Map global indexes to local indexes 58 : /// E.g. g2l[i] is the position of atom i in the array passed from the MD engine. 59 : /// Called "global to local" since originally it was used to map global indexes to local 60 : /// ones used in domain decomposition. However, it is now also used for the NAMD-like 61 : /// interface, where only a small number of atoms is passed to plumed. 62 : std::vector<int> g2l; 63 : 64 : unsigned shuffledAtoms; 65 : 66 : bool asyncSent; 67 : bool unique_serial; // use unique in serial mode 68 : /// This holds the list of unique atoms 69 : std::vector<AtomNumber> unique; 70 : std::vector<unsigned> uniq_index; 71 : /// This holds the list of atoms that have a force on 72 : std::vector<AtomNumber> forced_unique; 73 : /// This holds the list of actions that are set from this action 74 : std::vector<ActionToPutData*> inputs; 75 : /// This holds all the actions that read atoms 76 : std::vector<ActionAtomistic*> actions; 77 : /// The list that holds all the atom indexes we need 78 : std::vector<int> fullList; 79 : /// This actually does the sharing of the data across the domains 80 : void share(const std::vector<AtomNumber>& unique); 81 : /// Get all the atoms in the input that are active at this time 82 : void getAllActiveAtoms( std::vector<AtomNumber>& u ); 83 : public: 84 : static void registerKeywords(Keywords& keys); 85 : explicit DomainDecomposition(const ActionOptions&ao); 86 : void setStart( const std::string& name, const unsigned& sss) override ; 87 : void setStride( const std::string& name, const unsigned& sss) override ; 88 : void resetForStepStart() override ; 89 : bool setValuePointer( const std::string& name, const TypesafePtr & ) override ; 90 : bool setForcePointer( const std::string& name, const TypesafePtr & ) override ; 91 : unsigned getNumberOfForcesToRescale() const override ; 92 : void share() override ; 93 : void shareAll() override ; 94 : void wait() override ; 95 : void reset() override ; 96 : void writeBinary(std::ostream&o) override ; 97 : void readBinary(std::istream&i) override ; 98 : void apply() override ; 99 : void setAtomsNlocal(int n); 100 : void setAtomsGatindex(const TypesafePtr & g,bool fortran); 101 : void setAtomsContiguous(int start); 102 : void Set_comm(Communicator& comm) override ; 103 : void broadcastToDomains( Value* val ); 104 : void sumOverDomains( Value* val ); 105 : const long int& getDdStep() const ; 106 : const std::vector<int>& getGatindex() const ; 107 : void createFullList(const TypesafePtr & x); 108 : void getFullList(const TypesafePtr & x); 109 : void clearFullList(); 110 1707 : bool onStep() const override { 111 1707 : return getNumberOfAtoms()>0; 112 : } 113 : unsigned getNumberOfAtoms() const; 114 3843 : DomainDecomposition* castToDomainDecomposition() noexcept final { 115 3843 : return this; 116 : } 117 : }; 118 : 119 : } 120 : #endif