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 494901 : operator bool() const {return on;} 48 1195 : DomainComms(): on(false), async(false) {} 49 : void enable(Communicator& c); 50 : }; 51 : DomainComms dd; 52 : long int ddStep; 53 : 54 : std::vector<int> gatindex; 55 : /// Map global indexes to local indexes 56 : /// E.g. g2l[i] is the position of atom i in the array passed from the MD engine. 57 : /// Called "global to local" since originally it was used to map global indexes to local 58 : /// ones used in domain decomposition. However, it is now also used for the NAMD-like 59 : /// interface, where only a small number of atoms is passed to plumed. 60 : std::vector<int> g2l; 61 : 62 : unsigned shuffledAtoms; 63 : 64 : bool asyncSent; 65 : bool unique_serial; // use unique in serial mode 66 : /// This holds the list of unique atoms 67 : std::vector<AtomNumber> unique; 68 : std::vector<unsigned> uniq_index; 69 : /// This holds the list of atoms that have a force on 70 : std::vector<AtomNumber> forced_unique; 71 : /// This holds the list of actions that are set from this action 72 : std::vector<ActionToPutData*> inputs; 73 : /// This holds all the actions that read atoms 74 : std::vector<ActionAtomistic*> actions; 75 : /// The list that holds all the atom indexes we need 76 : std::vector<int> fullList; 77 : /// This actually does the sharing of the data across the domains 78 : void share(const std::vector<AtomNumber>& unique); 79 : /// Get all the atoms in the input that are active at this time 80 : void getAllActiveAtoms( std::vector<AtomNumber>& u ); 81 : public: 82 : static void registerKeywords(Keywords& keys); 83 : explicit DomainDecomposition(const ActionOptions&ao); 84 : void setStart( const std::string& name, const unsigned& sss) override ; 85 : void setStride( const std::string& name, const unsigned& sss) override ; 86 : void resetForStepStart() override ; 87 : bool setValuePointer( const std::string& name, const TypesafePtr & ) override ; 88 : bool setForcePointer( const std::string& name, const TypesafePtr & ) override ; 89 : unsigned getNumberOfForcesToRescale() const override ; 90 : void share() override ; 91 : void shareAll() override ; 92 : void wait() override ; 93 : void reset() override ; 94 : void writeBinary(std::ostream&o) override ; 95 : void readBinary(std::istream&i) override ; 96 : void apply() override ; 97 : void setAtomsNlocal(int n); 98 : void setAtomsGatindex(const TypesafePtr & g,bool fortran); 99 : void setAtomsContiguous(int start); 100 : void Set_comm(Communicator& comm) override ; 101 : void broadcastToDomains( Value* val ); 102 : void sumOverDomains( Value* val ); 103 : const long int& getDdStep() const ; 104 : const std::vector<int>& getGatindex() const ; 105 : void createFullList(const TypesafePtr & x); 106 : void getFullList(const TypesafePtr & x); 107 : void clearFullList(); 108 1707 : bool onStep() const override { return getNumberOfAtoms()>0; } 109 : unsigned getNumberOfAtoms() const; 110 3822 : DomainDecomposition* castToDomainDecomposition() noexcept final { return this; } 111 : }; 112 : 113 : } 114 : #endif