1 /* 2 * This file is part of the GROMACS molecular simulation package. 3 * 4 * Copyright (c) 2019,2020, by the GROMACS development team, led by 5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, 6 * and including many others, as listed in the AUTHORS file in the 7 * top-level source directory and at http://www.gromacs.org. 8 * 9 * GROMACS is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public License 11 * as published by the Free Software Foundation; either version 2.1 12 * of the License, or (at your option) any later version. 13 * 14 * GROMACS 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 GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with GROMACS; if not, see 21 * http://www.gnu.org/licenses, or write to the Free Software Foundation, 22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 * 24 * If you want to redistribute modifications to GROMACS, please 25 * consider that scientific software is very special. Version 26 * control is crucial - bugs must be traceable. We will be happy to 27 * consider code for inclusion in the official distribution, but 28 * derived work must not be called official GROMACS. Details are found 29 * in the README & COPYING files - if they are missing, get the 30 * official version at http://www.gromacs.org. 31 * 32 * To help us fund GROMACS development, we humbly ask that you cite 33 * the research papers on the package. Check out http://www.gromacs.org. 34 */ 35 /*! \internal \file 36 * \brief Declares the PME load balancing helper for the modular simulator 37 * 38 * \author Pascal Merz <pascal.merz@me.com> 39 * \ingroup module_modularsimulator 40 * 41 * This header is only used within the modular simulator module 42 */ 43 44 #ifndef GMX_MODULARSIMULATOR_PMELOADBALANCEHELPER_H 45 #define GMX_MODULARSIMULATOR_PMELOADBALANCEHELPER_H 46 47 #include "modularsimulatorinterfaces.h" 48 49 struct gmx_wallcycle; 50 struct pme_load_balancing_t; 51 struct t_commrec; 52 struct t_forcerec; 53 struct t_inputrec; 54 55 namespace gmx 56 { 57 class MDLogger; 58 struct MdrunOptions; 59 class StatePropagatorData; 60 61 /*! \internal 62 * \ingroup module_modularsimulator 63 * \brief Infrastructure element responsible for PME load balancing 64 * 65 * This encapsulates the function call to PME load balancing, which is 66 * important for performance but outside of the current scope of the modular 67 * simulator project. This relies on legacy data structures for the state. 68 * 69 * This element does not implement the ISimulatorElement interface, as 70 * the Simulator is calling it explicitly between task queue population 71 * steps. This allows elements to be aware of any changes before 72 * deciding what functionality they need to run. 73 */ 74 class PmeLoadBalanceHelper final : public INeighborSearchSignallerClient 75 { 76 public: 77 //! Constructor 78 PmeLoadBalanceHelper(bool isVerbose, 79 StatePropagatorData* statePropagatorData, 80 FILE* fplog, 81 t_commrec* cr, 82 const MDLogger& mdlog, 83 const t_inputrec* inputrec, 84 gmx_wallcycle* wcycle, 85 t_forcerec* fr); 86 87 //! Initialize the load balancing object 88 void setup(); 89 //! Do load balancing 90 void run(Step step, Time time); 91 //! Final printout and deconstruction of the load balancing object 92 void teardown(); 93 //! Whether PME load balancing printing is active \todo Check this! 94 bool pmePrinting(); 95 96 //! Whether we're doing PME load balancing 97 static bool doPmeLoadBalancing(const MdrunOptions& mdrunOptions, 98 const t_inputrec* inputrec, 99 const t_forcerec* fr); 100 101 //! Direct access to the load balancing object - used by reset counter 102 const pme_load_balancing_t* loadBalancingObject(); 103 104 private: 105 //! The PME load balancing object - used by reset counter 106 pme_load_balancing_t* pme_loadbal_; 107 108 //! INeighborSearchSignallerClient implementation 109 std::optional<SignallerCallback> registerNSCallback() override; 110 111 //! The next NS step 112 Step nextNSStep_; 113 //! Whether we're being verbose 114 const bool isVerbose_; 115 //! Whether PME load balancing printing is active \todo Check this! 116 bool bPMETunePrinting_; 117 118 // TODO: Clarify relationship to data objects and find a more robust alternative to raw pointers (#3583) 119 //! Pointer to the micro state 120 StatePropagatorData* statePropagatorData_; 121 122 // Access to ISimulator data 123 //! Handles logging. 124 FILE* fplog_; 125 //! Handles communication. 126 t_commrec* cr_; 127 //! Handles logging. 128 const MDLogger& mdlog_; 129 //! Contains user input mdp options. 130 const t_inputrec* inputrec_; 131 //! Manages wall cycle accounting. 132 gmx_wallcycle* wcycle_; 133 //! Parameters for force calculations. 134 t_forcerec* fr_; 135 }; 136 137 } // namespace gmx 138 139 #endif // GMX_MODULARSIMULATOR_PMELOADBALANCEHELPER_H 140