hillclimber 0.1.5a8__cp314-cp314-macosx_15_0_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (469) hide show
  1. hillclimber/__init__.py +39 -0
  2. hillclimber/actions.py +53 -0
  3. hillclimber/analysis.py +590 -0
  4. hillclimber/biases.py +293 -0
  5. hillclimber/calc.py +22 -0
  6. hillclimber/cvs.py +1065 -0
  7. hillclimber/interfaces.py +133 -0
  8. hillclimber/metadynamics.py +325 -0
  9. hillclimber/nodes.py +6 -0
  10. hillclimber/opes.py +359 -0
  11. hillclimber/selectors.py +230 -0
  12. hillclimber/virtual_atoms.py +341 -0
  13. hillclimber-0.1.5a8.dist-info/METADATA +209 -0
  14. hillclimber-0.1.5a8.dist-info/RECORD +469 -0
  15. hillclimber-0.1.5a8.dist-info/WHEEL +6 -0
  16. hillclimber-0.1.5a8.dist-info/entry_points.txt +8 -0
  17. hillclimber-0.1.5a8.dist-info/licenses/LICENSE +165 -0
  18. plumed/__init__.py +104 -0
  19. plumed/_lib/bin/plumed +0 -0
  20. plumed/_lib/bin/plumed-config +9 -0
  21. plumed/_lib/bin/plumed-patch +9 -0
  22. plumed/_lib/include/plumed/adjmat/AdjacencyMatrixBase.h +659 -0
  23. plumed/_lib/include/plumed/adjmat/ContactMatrix.h +59 -0
  24. plumed/_lib/include/plumed/asmjit/arch.h +228 -0
  25. plumed/_lib/include/plumed/asmjit/arm.h +43 -0
  26. plumed/_lib/include/plumed/asmjit/asmjit.h +69 -0
  27. plumed/_lib/include/plumed/asmjit/asmjit_apibegin.h +143 -0
  28. plumed/_lib/include/plumed/asmjit/asmjit_apiend.h +93 -0
  29. plumed/_lib/include/plumed/asmjit/asmjit_build.h +971 -0
  30. plumed/_lib/include/plumed/asmjit/assembler.h +183 -0
  31. plumed/_lib/include/plumed/asmjit/base.h +56 -0
  32. plumed/_lib/include/plumed/asmjit/codebuilder.h +944 -0
  33. plumed/_lib/include/plumed/asmjit/codecompiler.h +767 -0
  34. plumed/_lib/include/plumed/asmjit/codeemitter.h +528 -0
  35. plumed/_lib/include/plumed/asmjit/codeholder.h +777 -0
  36. plumed/_lib/include/plumed/asmjit/constpool.h +286 -0
  37. plumed/_lib/include/plumed/asmjit/cpuinfo.h +402 -0
  38. plumed/_lib/include/plumed/asmjit/func.h +1327 -0
  39. plumed/_lib/include/plumed/asmjit/globals.h +370 -0
  40. plumed/_lib/include/plumed/asmjit/inst.h +137 -0
  41. plumed/_lib/include/plumed/asmjit/logging.h +317 -0
  42. plumed/_lib/include/plumed/asmjit/misc_p.h +103 -0
  43. plumed/_lib/include/plumed/asmjit/moved_string.h +318 -0
  44. plumed/_lib/include/plumed/asmjit/operand.h +1599 -0
  45. plumed/_lib/include/plumed/asmjit/osutils.h +207 -0
  46. plumed/_lib/include/plumed/asmjit/regalloc_p.h +597 -0
  47. plumed/_lib/include/plumed/asmjit/runtime.h +227 -0
  48. plumed/_lib/include/plumed/asmjit/simdtypes.h +1104 -0
  49. plumed/_lib/include/plumed/asmjit/utils.h +1387 -0
  50. plumed/_lib/include/plumed/asmjit/vmem.h +183 -0
  51. plumed/_lib/include/plumed/asmjit/x86.h +45 -0
  52. plumed/_lib/include/plumed/asmjit/x86assembler.h +125 -0
  53. plumed/_lib/include/plumed/asmjit/x86builder.h +117 -0
  54. plumed/_lib/include/plumed/asmjit/x86compiler.h +322 -0
  55. plumed/_lib/include/plumed/asmjit/x86emitter.h +5149 -0
  56. plumed/_lib/include/plumed/asmjit/x86globals.h +535 -0
  57. plumed/_lib/include/plumed/asmjit/x86inst.h +2547 -0
  58. plumed/_lib/include/plumed/asmjit/x86instimpl_p.h +74 -0
  59. plumed/_lib/include/plumed/asmjit/x86internal_p.h +108 -0
  60. plumed/_lib/include/plumed/asmjit/x86logging_p.h +92 -0
  61. plumed/_lib/include/plumed/asmjit/x86misc.h +417 -0
  62. plumed/_lib/include/plumed/asmjit/x86operand.h +1133 -0
  63. plumed/_lib/include/plumed/asmjit/x86regalloc_p.h +734 -0
  64. plumed/_lib/include/plumed/asmjit/zone.h +1157 -0
  65. plumed/_lib/include/plumed/bias/Bias.h +82 -0
  66. plumed/_lib/include/plumed/bias/ReweightBase.h +58 -0
  67. plumed/_lib/include/plumed/blas/blas.h +253 -0
  68. plumed/_lib/include/plumed/blas/def_external.h +61 -0
  69. plumed/_lib/include/plumed/blas/def_internal.h +97 -0
  70. plumed/_lib/include/plumed/blas/real.h +49 -0
  71. plumed/_lib/include/plumed/cltools/CLTool.h +32 -0
  72. plumed/_lib/include/plumed/clusters/ClusteringBase.h +70 -0
  73. plumed/_lib/include/plumed/colvar/Colvar.h +32 -0
  74. plumed/_lib/include/plumed/colvar/ColvarInput.h +68 -0
  75. plumed/_lib/include/plumed/colvar/ColvarShortcut.h +81 -0
  76. plumed/_lib/include/plumed/colvar/CoordinationBase.h +52 -0
  77. plumed/_lib/include/plumed/colvar/MultiColvarTemplate.h +333 -0
  78. plumed/_lib/include/plumed/colvar/PathMSDBase.h +101 -0
  79. plumed/_lib/include/plumed/colvar/RMSDVector.h +78 -0
  80. plumed/_lib/include/plumed/config/Config.h +118 -0
  81. plumed/_lib/include/plumed/config/version.h +9 -0
  82. plumed/_lib/include/plumed/contour/ContourFindingObject.h +87 -0
  83. plumed/_lib/include/plumed/contour/DistanceFromContourBase.h +82 -0
  84. plumed/_lib/include/plumed/contour/FindContour.h +67 -0
  85. plumed/_lib/include/plumed/core/Action.h +540 -0
  86. plumed/_lib/include/plumed/core/ActionAnyorder.h +48 -0
  87. plumed/_lib/include/plumed/core/ActionAtomistic.h +343 -0
  88. plumed/_lib/include/plumed/core/ActionForInterface.h +99 -0
  89. plumed/_lib/include/plumed/core/ActionPilot.h +57 -0
  90. plumed/_lib/include/plumed/core/ActionRegister.h +124 -0
  91. plumed/_lib/include/plumed/core/ActionSet.h +163 -0
  92. plumed/_lib/include/plumed/core/ActionSetup.h +48 -0
  93. plumed/_lib/include/plumed/core/ActionShortcut.h +73 -0
  94. plumed/_lib/include/plumed/core/ActionToGetData.h +59 -0
  95. plumed/_lib/include/plumed/core/ActionToPutData.h +101 -0
  96. plumed/_lib/include/plumed/core/ActionWithArguments.h +140 -0
  97. plumed/_lib/include/plumed/core/ActionWithMatrix.h +87 -0
  98. plumed/_lib/include/plumed/core/ActionWithValue.h +258 -0
  99. plumed/_lib/include/plumed/core/ActionWithVector.h +94 -0
  100. plumed/_lib/include/plumed/core/ActionWithVirtualAtom.h +123 -0
  101. plumed/_lib/include/plumed/core/CLTool.h +177 -0
  102. plumed/_lib/include/plumed/core/CLToolMain.h +102 -0
  103. plumed/_lib/include/plumed/core/CLToolRegister.h +108 -0
  104. plumed/_lib/include/plumed/core/Colvar.h +115 -0
  105. plumed/_lib/include/plumed/core/DataPassingObject.h +94 -0
  106. plumed/_lib/include/plumed/core/DataPassingTools.h +54 -0
  107. plumed/_lib/include/plumed/core/DomainDecomposition.h +120 -0
  108. plumed/_lib/include/plumed/core/ExchangePatterns.h +47 -0
  109. plumed/_lib/include/plumed/core/FlexibleBin.h +63 -0
  110. plumed/_lib/include/plumed/core/GREX.h +61 -0
  111. plumed/_lib/include/plumed/core/GenericMolInfo.h +89 -0
  112. plumed/_lib/include/plumed/core/Group.h +41 -0
  113. plumed/_lib/include/plumed/core/ModuleMap.h +30 -0
  114. plumed/_lib/include/plumed/core/ParallelTaskManager.h +1023 -0
  115. plumed/_lib/include/plumed/core/PbcAction.h +61 -0
  116. plumed/_lib/include/plumed/core/PlumedMain.h +632 -0
  117. plumed/_lib/include/plumed/core/PlumedMainInitializer.h +118 -0
  118. plumed/_lib/include/plumed/core/RegisterBase.h +340 -0
  119. plumed/_lib/include/plumed/core/TargetDist.h +48 -0
  120. plumed/_lib/include/plumed/core/Value.h +547 -0
  121. plumed/_lib/include/plumed/core/WithCmd.h +93 -0
  122. plumed/_lib/include/plumed/dimred/SMACOF.h +55 -0
  123. plumed/_lib/include/plumed/drr/DRR.h +383 -0
  124. plumed/_lib/include/plumed/drr/colvar_UIestimator.h +777 -0
  125. plumed/_lib/include/plumed/fisst/legendre_rule_fast.h +44 -0
  126. plumed/_lib/include/plumed/function/Custom.h +54 -0
  127. plumed/_lib/include/plumed/function/Function.h +85 -0
  128. plumed/_lib/include/plumed/function/FunctionOfMatrix.h +368 -0
  129. plumed/_lib/include/plumed/function/FunctionOfScalar.h +135 -0
  130. plumed/_lib/include/plumed/function/FunctionOfVector.h +296 -0
  131. plumed/_lib/include/plumed/function/FunctionSetup.h +180 -0
  132. plumed/_lib/include/plumed/function/FunctionShortcut.h +130 -0
  133. plumed/_lib/include/plumed/function/FunctionWithSingleArgument.h +165 -0
  134. plumed/_lib/include/plumed/gridtools/ActionWithGrid.h +43 -0
  135. plumed/_lib/include/plumed/gridtools/EvaluateGridFunction.h +99 -0
  136. plumed/_lib/include/plumed/gridtools/FunctionOfGrid.h +295 -0
  137. plumed/_lib/include/plumed/gridtools/GridCoordinatesObject.h +179 -0
  138. plumed/_lib/include/plumed/gridtools/GridSearch.h +135 -0
  139. plumed/_lib/include/plumed/gridtools/Interpolator.h +45 -0
  140. plumed/_lib/include/plumed/gridtools/KDE.h +455 -0
  141. plumed/_lib/include/plumed/gridtools/RDF.h +40 -0
  142. plumed/_lib/include/plumed/gridtools/SumOfKernels.h +219 -0
  143. plumed/_lib/include/plumed/isdb/MetainferenceBase.h +398 -0
  144. plumed/_lib/include/plumed/lapack/def_external.h +207 -0
  145. plumed/_lib/include/plumed/lapack/def_internal.h +388 -0
  146. plumed/_lib/include/plumed/lapack/lapack.h +899 -0
  147. plumed/_lib/include/plumed/lapack/lapack_limits.h +79 -0
  148. plumed/_lib/include/plumed/lapack/real.h +50 -0
  149. plumed/_lib/include/plumed/lepton/CompiledExpression.h +164 -0
  150. plumed/_lib/include/plumed/lepton/CustomFunction.h +143 -0
  151. plumed/_lib/include/plumed/lepton/Exception.h +93 -0
  152. plumed/_lib/include/plumed/lepton/ExpressionProgram.h +137 -0
  153. plumed/_lib/include/plumed/lepton/ExpressionTreeNode.h +145 -0
  154. plumed/_lib/include/plumed/lepton/Lepton.h +85 -0
  155. plumed/_lib/include/plumed/lepton/MSVC_erfc.h +123 -0
  156. plumed/_lib/include/plumed/lepton/Operation.h +1302 -0
  157. plumed/_lib/include/plumed/lepton/ParsedExpression.h +165 -0
  158. plumed/_lib/include/plumed/lepton/Parser.h +111 -0
  159. plumed/_lib/include/plumed/lepton/windowsIncludes.h +73 -0
  160. plumed/_lib/include/plumed/mapping/Path.h +44 -0
  161. plumed/_lib/include/plumed/mapping/PathProjectionCalculator.h +57 -0
  162. plumed/_lib/include/plumed/matrixtools/MatrixOperationBase.h +54 -0
  163. plumed/_lib/include/plumed/matrixtools/MatrixTimesMatrix.h +309 -0
  164. plumed/_lib/include/plumed/matrixtools/MatrixTimesVectorBase.h +365 -0
  165. plumed/_lib/include/plumed/matrixtools/OuterProduct.h +238 -0
  166. plumed/_lib/include/plumed/maze/Core.h +65 -0
  167. plumed/_lib/include/plumed/maze/Loss.h +86 -0
  168. plumed/_lib/include/plumed/maze/Member.h +66 -0
  169. plumed/_lib/include/plumed/maze/Memetic.h +799 -0
  170. plumed/_lib/include/plumed/maze/Optimizer.h +357 -0
  171. plumed/_lib/include/plumed/maze/Random_MT.h +156 -0
  172. plumed/_lib/include/plumed/maze/Tools.h +183 -0
  173. plumed/_lib/include/plumed/metatomic/vesin.h +188 -0
  174. plumed/_lib/include/plumed/molfile/Gromacs.h +2013 -0
  175. plumed/_lib/include/plumed/molfile/endianswap.h +217 -0
  176. plumed/_lib/include/plumed/molfile/fastio.h +683 -0
  177. plumed/_lib/include/plumed/molfile/largefiles.h +78 -0
  178. plumed/_lib/include/plumed/molfile/libmolfile_plugin.h +77 -0
  179. plumed/_lib/include/plumed/molfile/molfile_plugin.h +1034 -0
  180. plumed/_lib/include/plumed/molfile/periodic_table.h +248 -0
  181. plumed/_lib/include/plumed/molfile/readpdb.h +447 -0
  182. plumed/_lib/include/plumed/molfile/vmdplugin.h +236 -0
  183. plumed/_lib/include/plumed/multicolvar/MultiColvarShortcuts.h +45 -0
  184. plumed/_lib/include/plumed/opes/ExpansionCVs.h +79 -0
  185. plumed/_lib/include/plumed/sasa/Sasa.h +32 -0
  186. plumed/_lib/include/plumed/secondarystructure/SecondaryStructureBase.h +372 -0
  187. plumed/_lib/include/plumed/setup/ActionSetup.h +25 -0
  188. plumed/_lib/include/plumed/small_vector/small_vector.h +6114 -0
  189. plumed/_lib/include/plumed/symfunc/CoordinationNumbers.h +41 -0
  190. plumed/_lib/include/plumed/tools/Angle.h +52 -0
  191. plumed/_lib/include/plumed/tools/AtomDistribution.h +138 -0
  192. plumed/_lib/include/plumed/tools/AtomNumber.h +152 -0
  193. plumed/_lib/include/plumed/tools/BiasRepresentation.h +106 -0
  194. plumed/_lib/include/plumed/tools/BitmaskEnum.h +167 -0
  195. plumed/_lib/include/plumed/tools/Brent1DRootSearch.h +159 -0
  196. plumed/_lib/include/plumed/tools/CheckInRange.h +44 -0
  197. plumed/_lib/include/plumed/tools/Citations.h +74 -0
  198. plumed/_lib/include/plumed/tools/ColvarOutput.h +118 -0
  199. plumed/_lib/include/plumed/tools/Communicator.h +316 -0
  200. plumed/_lib/include/plumed/tools/ConjugateGradient.h +80 -0
  201. plumed/_lib/include/plumed/tools/DLLoader.h +79 -0
  202. plumed/_lib/include/plumed/tools/ERMSD.h +73 -0
  203. plumed/_lib/include/plumed/tools/Exception.h +406 -0
  204. plumed/_lib/include/plumed/tools/File.h +28 -0
  205. plumed/_lib/include/plumed/tools/FileBase.h +153 -0
  206. plumed/_lib/include/plumed/tools/FileTools.h +37 -0
  207. plumed/_lib/include/plumed/tools/ForwardDecl.h +54 -0
  208. plumed/_lib/include/plumed/tools/Grid.h +638 -0
  209. plumed/_lib/include/plumed/tools/HistogramBead.h +136 -0
  210. plumed/_lib/include/plumed/tools/IFile.h +117 -0
  211. plumed/_lib/include/plumed/tools/KernelFunctions.h +113 -0
  212. plumed/_lib/include/plumed/tools/Keywords.h +380 -0
  213. plumed/_lib/include/plumed/tools/LatticeReduction.h +66 -0
  214. plumed/_lib/include/plumed/tools/LeptonCall.h +64 -0
  215. plumed/_lib/include/plumed/tools/LinkCells.h +126 -0
  216. plumed/_lib/include/plumed/tools/Log.h +41 -0
  217. plumed/_lib/include/plumed/tools/LoopUnroller.h +163 -0
  218. plumed/_lib/include/plumed/tools/Matrix.h +721 -0
  219. plumed/_lib/include/plumed/tools/MatrixSquareBracketsAccess.h +138 -0
  220. plumed/_lib/include/plumed/tools/MergeVectorTools.h +153 -0
  221. plumed/_lib/include/plumed/tools/Minimise1DBrent.h +244 -0
  222. plumed/_lib/include/plumed/tools/MinimiseBase.h +120 -0
  223. plumed/_lib/include/plumed/tools/MolDataClass.h +51 -0
  224. plumed/_lib/include/plumed/tools/NeighborList.h +112 -0
  225. plumed/_lib/include/plumed/tools/OFile.h +286 -0
  226. plumed/_lib/include/plumed/tools/OpenACC.h +180 -0
  227. plumed/_lib/include/plumed/tools/OpenMP.h +75 -0
  228. plumed/_lib/include/plumed/tools/PDB.h +154 -0
  229. plumed/_lib/include/plumed/tools/Pbc.h +139 -0
  230. plumed/_lib/include/plumed/tools/PlumedHandle.h +105 -0
  231. plumed/_lib/include/plumed/tools/RMSD.h +493 -0
  232. plumed/_lib/include/plumed/tools/Random.h +80 -0
  233. plumed/_lib/include/plumed/tools/RootFindingBase.h +79 -0
  234. plumed/_lib/include/plumed/tools/Stopwatch.h +475 -0
  235. plumed/_lib/include/plumed/tools/Subprocess.h +142 -0
  236. plumed/_lib/include/plumed/tools/SwitchingFunction.h +208 -0
  237. plumed/_lib/include/plumed/tools/Tensor.h +724 -0
  238. plumed/_lib/include/plumed/tools/TokenizedLine.h +123 -0
  239. plumed/_lib/include/plumed/tools/Tools.h +638 -0
  240. plumed/_lib/include/plumed/tools/Torsion.h +55 -0
  241. plumed/_lib/include/plumed/tools/TrajectoryParser.h +118 -0
  242. plumed/_lib/include/plumed/tools/Tree.h +61 -0
  243. plumed/_lib/include/plumed/tools/TypesafePtr.h +463 -0
  244. plumed/_lib/include/plumed/tools/Units.h +167 -0
  245. plumed/_lib/include/plumed/tools/Vector.h +433 -0
  246. plumed/_lib/include/plumed/tools/View.h +296 -0
  247. plumed/_lib/include/plumed/tools/View2D.h +100 -0
  248. plumed/_lib/include/plumed/tools/h36.h +39 -0
  249. plumed/_lib/include/plumed/vatom/ActionWithVirtualAtom.h +32 -0
  250. plumed/_lib/include/plumed/ves/BasisFunctions.h +380 -0
  251. plumed/_lib/include/plumed/ves/CoeffsBase.h +310 -0
  252. plumed/_lib/include/plumed/ves/CoeffsMatrix.h +220 -0
  253. plumed/_lib/include/plumed/ves/CoeffsVector.h +251 -0
  254. plumed/_lib/include/plumed/ves/FermiSwitchingFunction.h +74 -0
  255. plumed/_lib/include/plumed/ves/GridIntegrationWeights.h +50 -0
  256. plumed/_lib/include/plumed/ves/GridLinearInterpolation.h +81 -0
  257. plumed/_lib/include/plumed/ves/GridProjWeights.h +61 -0
  258. plumed/_lib/include/plumed/ves/LinearBasisSetExpansion.h +303 -0
  259. plumed/_lib/include/plumed/ves/Optimizer.h +444 -0
  260. plumed/_lib/include/plumed/ves/TargetDistModifer.h +53 -0
  261. plumed/_lib/include/plumed/ves/TargetDistribution.h +266 -0
  262. plumed/_lib/include/plumed/ves/VesBias.h +545 -0
  263. plumed/_lib/include/plumed/ves/VesTools.h +142 -0
  264. plumed/_lib/include/plumed/ves/WaveletGrid.h +75 -0
  265. plumed/_lib/include/plumed/volumes/ActionVolume.h +268 -0
  266. plumed/_lib/include/plumed/volumes/VolumeShortcut.h +147 -0
  267. plumed/_lib/include/plumed/wrapper/Plumed.h +5025 -0
  268. plumed/_lib/include/plumed/xdrfile/xdrfile.h +663 -0
  269. plumed/_lib/include/plumed/xdrfile/xdrfile_trr.h +89 -0
  270. plumed/_lib/include/plumed/xdrfile/xdrfile_xtc.h +90 -0
  271. plumed/_lib/lib/PythonCVInterface.dylib +0 -0
  272. plumed/_lib/lib/libplumed.dylib +0 -0
  273. plumed/_lib/lib/libplumedKernel.dylib +0 -0
  274. plumed/_lib/lib/libplumedWrapper.a +0 -0
  275. plumed/_lib/lib/pkgconfig/plumed.pc +13 -0
  276. plumed/_lib/lib/pkgconfig/plumedInternals.pc +13 -0
  277. plumed/_lib/lib/pkgconfig/plumedWrapper.pc +13 -0
  278. plumed/_lib/lib/plumed/fortran/plumed.f90 +879 -0
  279. plumed/_lib/lib/plumed/fortran/plumed_f08.f90 +2625 -0
  280. plumed/_lib/lib/plumed/modulefile +69 -0
  281. plumed/_lib/lib/plumed/patches/gromacs-2022.5.config +43 -0
  282. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/CMakeLists.txt +543 -0
  283. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/CMakeLists.txt.preplumed +540 -0
  284. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/expanded.cpp +1628 -0
  285. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/expanded.cpp.preplumed +1590 -0
  286. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/expanded.h +103 -0
  287. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/expanded.h.preplumed +99 -0
  288. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/sim_util.cpp +2527 -0
  289. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/sim_util.cpp.preplumed +2513 -0
  290. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/legacymdrunoptions.cpp +208 -0
  291. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/legacymdrunoptions.cpp.preplumed +175 -0
  292. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/legacymdrunoptions.h +408 -0
  293. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/legacymdrunoptions.h.preplumed +394 -0
  294. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/md.cpp +2348 -0
  295. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/md.cpp.preplumed +2091 -0
  296. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/minimize.cpp +3573 -0
  297. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/minimize.cpp.preplumed +3495 -0
  298. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/replicaexchange.cpp +1506 -0
  299. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/replicaexchange.cpp.preplumed +1402 -0
  300. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/replicaexchange.h +114 -0
  301. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/replicaexchange.h.preplumed +106 -0
  302. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/rerun.cpp +997 -0
  303. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/rerun.cpp.preplumed +906 -0
  304. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/runner.cpp +2780 -0
  305. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/runner.cpp.preplumed +2738 -0
  306. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp +224 -0
  307. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp.preplumed +222 -0
  308. plumed/_lib/lib/plumed/patches/gromacs-2023.5.config +43 -0
  309. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/CMakeLists.txt +549 -0
  310. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/CMakeLists.txt.preplumed +546 -0
  311. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/expanded.cpp +1632 -0
  312. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/expanded.cpp.preplumed +1594 -0
  313. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/expanded.h +104 -0
  314. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/expanded.h.preplumed +100 -0
  315. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/sim_util.cpp +2624 -0
  316. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/sim_util.cpp.preplumed +2610 -0
  317. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/legacymdrunoptions.cpp +208 -0
  318. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/legacymdrunoptions.cpp.preplumed +175 -0
  319. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/legacymdrunoptions.h +409 -0
  320. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/legacymdrunoptions.h.preplumed +395 -0
  321. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/md.cpp +2419 -0
  322. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/md.cpp.preplumed +2164 -0
  323. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/minimize.cpp +3546 -0
  324. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/minimize.cpp.preplumed +3468 -0
  325. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/replicaexchange.cpp +1513 -0
  326. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/replicaexchange.cpp.preplumed +1409 -0
  327. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/replicaexchange.h +114 -0
  328. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/replicaexchange.h.preplumed +106 -0
  329. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/rerun.cpp +991 -0
  330. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/rerun.cpp.preplumed +900 -0
  331. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/runner.cpp +2895 -0
  332. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/runner.cpp.preplumed +2849 -0
  333. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp +224 -0
  334. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp.preplumed +222 -0
  335. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/taskassignment/decidegpuusage.cpp +886 -0
  336. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/taskassignment/decidegpuusage.cpp.preplumed +880 -0
  337. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/taskassignment/include/gromacs/taskassignment/decidegpuusage.h +347 -0
  338. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/taskassignment/include/gromacs/taskassignment/decidegpuusage.h.preplumed +345 -0
  339. plumed/_lib/lib/plumed/patches/gromacs-2024.3.config +43 -0
  340. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/CMakeLists.txt +575 -0
  341. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/CMakeLists.txt.preplumed +572 -0
  342. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/expanded.cpp +1632 -0
  343. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/expanded.cpp.preplumed +1594 -0
  344. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/expanded.h +104 -0
  345. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/expanded.h.preplumed +100 -0
  346. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/sim_util.cpp +2564 -0
  347. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/sim_util.cpp.preplumed +2550 -0
  348. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/legacymdrunoptions.cpp +208 -0
  349. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/legacymdrunoptions.cpp.preplumed +175 -0
  350. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/legacymdrunoptions.h +410 -0
  351. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/legacymdrunoptions.h.preplumed +396 -0
  352. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/md.cpp +2435 -0
  353. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/md.cpp.preplumed +2187 -0
  354. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/minimize.cpp +3592 -0
  355. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/minimize.cpp.preplumed +3514 -0
  356. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/replicaexchange.cpp +1513 -0
  357. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/replicaexchange.cpp.preplumed +1409 -0
  358. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/replicaexchange.h +114 -0
  359. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/replicaexchange.h.preplumed +106 -0
  360. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/rerun.cpp +958 -0
  361. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/rerun.cpp.preplumed +929 -0
  362. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/runner.cpp +2987 -0
  363. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/runner.cpp.preplumed +2941 -0
  364. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp +224 -0
  365. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp.preplumed +222 -0
  366. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/taskassignment/decidegpuusage.cpp +904 -0
  367. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/taskassignment/decidegpuusage.cpp.preplumed +898 -0
  368. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/taskassignment/include/gromacs/taskassignment/decidegpuusage.h +353 -0
  369. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/taskassignment/include/gromacs/taskassignment/decidegpuusage.h.preplumed +351 -0
  370. plumed/_lib/lib/plumed/patches/gromacs-2025.0.config +39 -0
  371. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/cmake/gmxManagePlumed.cmake +82 -0
  372. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/cmake/gmxManagePlumed.cmake.preplumed +82 -0
  373. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedMDModule.cpp +162 -0
  374. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedMDModule.cpp.preplumed +154 -0
  375. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedOptions.cpp +107 -0
  376. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedOptions.cpp.preplumed +99 -0
  377. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedOptions.h +120 -0
  378. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedOptions.h.preplumed +111 -0
  379. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedforceprovider.cpp +215 -0
  380. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedforceprovider.cpp.preplumed +197 -0
  381. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedforceprovider.h +87 -0
  382. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedforceprovider.h.preplumed +86 -0
  383. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/mdrun/runner.cpp +2971 -0
  384. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/mdrun/runner.cpp.preplumed +2970 -0
  385. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/mdrunutility/mdmodulesnotifiers.h +430 -0
  386. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/mdrunutility/mdmodulesnotifiers.h.preplumed +429 -0
  387. plumed/_lib/lib/plumed/patches/namd-2.12.config +30 -0
  388. plumed/_lib/lib/plumed/patches/namd-2.12.diff +267 -0
  389. plumed/_lib/lib/plumed/patches/namd-2.13.config +30 -0
  390. plumed/_lib/lib/plumed/patches/namd-2.13.diff +267 -0
  391. plumed/_lib/lib/plumed/patches/namd-2.14.config +30 -0
  392. plumed/_lib/lib/plumed/patches/namd-2.14.diff +268 -0
  393. plumed/_lib/lib/plumed/patches/patch.sh +500 -0
  394. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.config +25 -0
  395. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/forces.f90 +368 -0
  396. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/forces.f90.preplumed +366 -0
  397. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/plugin_forces.f90 +71 -0
  398. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/plugin_forces.f90.preplumed +24 -0
  399. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/plugin_initialization.f90 +62 -0
  400. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/plugin_initialization.f90.preplumed +21 -0
  401. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/pwscf.f90 +189 -0
  402. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/pwscf.f90.preplumed +185 -0
  403. plumed/_lib/lib/plumed/patches/qespresso-6.2.config +26 -0
  404. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/forces.f90 +422 -0
  405. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/forces.f90.preplumed +420 -0
  406. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/plugin_ext_forces.f90 +70 -0
  407. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/plugin_ext_forces.f90.preplumed +23 -0
  408. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/plugin_initialization.f90 +62 -0
  409. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/plugin_initialization.f90.preplumed +21 -0
  410. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/run_pwscf.f90 +233 -0
  411. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/run_pwscf.f90.preplumed +230 -0
  412. plumed/_lib/lib/plumed/patches/qespresso-7.0.config +28 -0
  413. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/Modules/Makefile +175 -0
  414. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/Modules/Makefile.preplumed +171 -0
  415. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/forces.f90 +486 -0
  416. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/forces.f90.preplumed +484 -0
  417. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/plugin_ext_forces.f90 +74 -0
  418. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/plugin_ext_forces.f90.preplumed +23 -0
  419. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/plugin_initialization.f90 +64 -0
  420. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/plugin_initialization.f90.preplumed +21 -0
  421. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/run_pwscf.f90 +532 -0
  422. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/run_pwscf.f90.preplumed +518 -0
  423. plumed/_lib/lib/plumed/patches/qespresso-7.2.config +28 -0
  424. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/Modules/Makefile +249 -0
  425. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/Modules/Makefile.preplumed +244 -0
  426. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/forces.f90 +532 -0
  427. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/forces.f90.preplumed +535 -0
  428. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/plugin_ext_forces.f90 +74 -0
  429. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/plugin_ext_forces.f90.preplumed +23 -0
  430. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/plugin_initialization.f90 +64 -0
  431. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/plugin_initialization.f90.preplumed +21 -0
  432. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/run_pwscf.f90 +569 -0
  433. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/run_pwscf.f90.preplumed +560 -0
  434. plumed/_lib/lib/plumed/plumed-config +9 -0
  435. plumed/_lib/lib/plumed/plumed-mklib +9 -0
  436. plumed/_lib/lib/plumed/plumed-newcv +9 -0
  437. plumed/_lib/lib/plumed/plumed-partial_tempering +9 -0
  438. plumed/_lib/lib/plumed/plumed-patch +9 -0
  439. plumed/_lib/lib/plumed/plumed-runtime +0 -0
  440. plumed/_lib/lib/plumed/plumed-selector +9 -0
  441. plumed/_lib/lib/plumed/plumed-vim2html +9 -0
  442. plumed/_lib/lib/plumed/scripts/config.sh +126 -0
  443. plumed/_lib/lib/plumed/scripts/mklib.sh +175 -0
  444. plumed/_lib/lib/plumed/scripts/newcv.sh +26 -0
  445. plumed/_lib/lib/plumed/scripts/partial_tempering.sh +319 -0
  446. plumed/_lib/lib/plumed/scripts/patch.sh +4 -0
  447. plumed/_lib/lib/plumed/scripts/selector.sh +234 -0
  448. plumed/_lib/lib/plumed/scripts/vim2html.sh +190 -0
  449. plumed/_lib/lib/plumed/src/colvar/Template.cpp +116 -0
  450. plumed/_lib/lib/plumed/src/config/compile_options.sh +3 -0
  451. plumed/_lib/lib/plumed/src/config/config.txt +181 -0
  452. plumed/_lib/lib/plumed/src/lib/Plumed.cmake +6 -0
  453. plumed/_lib/lib/plumed/src/lib/Plumed.cmake.runtime +5 -0
  454. plumed/_lib/lib/plumed/src/lib/Plumed.cmake.shared +5 -0
  455. plumed/_lib/lib/plumed/src/lib/Plumed.cmake.static +3 -0
  456. plumed/_lib/lib/plumed/src/lib/Plumed.inc +6 -0
  457. plumed/_lib/lib/plumed/src/lib/Plumed.inc.runtime +5 -0
  458. plumed/_lib/lib/plumed/src/lib/Plumed.inc.shared +5 -0
  459. plumed/_lib/lib/plumed/src/lib/Plumed.inc.static +3 -0
  460. plumed/_lib/lib/plumed/vim/scripts.vim +6 -0
  461. plumed/_plumed_core.cpython-311-darwin.so +0 -0
  462. plumed/_plumed_core.cpython-312-darwin.so +0 -0
  463. plumed/_plumed_core.cpython-313-darwin.so +0 -0
  464. plumed/_plumed_core.cpython-314-darwin.so +0 -0
  465. plumedCommunications.cpython-311-darwin.so +0 -0
  466. plumedCommunications.cpython-312-darwin.so +0 -0
  467. plumedCommunications.cpython-313-darwin.so +0 -0
  468. plumedCommunications.cpython-314-darwin.so +0 -0
  469. plumedCommunications.pyi +431 -0
@@ -0,0 +1,2895 @@
1
+ /*
2
+ * This file is part of the GROMACS molecular simulation package.
3
+ *
4
+ * Copyright 1991- The GROMACS Authors
5
+ * and the project initiators Erik Lindahl, Berk Hess and David van der Spoel.
6
+ * Consult the AUTHORS/COPYING files and https://www.gromacs.org for details.
7
+ *
8
+ * GROMACS is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public License
10
+ * as published by the Free Software Foundation; either version 2.1
11
+ * of the License, or (at your option) any later version.
12
+ *
13
+ * GROMACS is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with GROMACS; if not, see
20
+ * https://www.gnu.org/licenses, or write to the Free Software Foundation,
21
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
+ *
23
+ * If you want to redistribute modifications to GROMACS, please
24
+ * consider that scientific software is very special. Version
25
+ * control is crucial - bugs must be traceable. We will be happy to
26
+ * consider code for inclusion in the official distribution, but
27
+ * derived work must not be called official GROMACS. Details are found
28
+ * in the README & COPYING files - if they are missing, get the
29
+ * official version at https://www.gromacs.org.
30
+ *
31
+ * To help us fund GROMACS development, we humbly ask that you cite
32
+ * the research papers on the package. Check out https://www.gromacs.org.
33
+ */
34
+ /*! \internal \file
35
+ *
36
+ * \brief Implements the MD runner routine calling all integrators.
37
+ *
38
+ * \author David van der Spoel <david.vanderspoel@icm.uu.se>
39
+ * \ingroup module_mdrun
40
+ */
41
+ #include "gmxpre.h"
42
+
43
+ #include "runner.h"
44
+
45
+ #include "config.h"
46
+
47
+ #include <cassert>
48
+ #include <cinttypes>
49
+ #include <csignal>
50
+ #include <cstdlib>
51
+ #include <cstring>
52
+
53
+ #include <algorithm>
54
+ #include <memory>
55
+ #include <optional>
56
+
57
+ #include "gromacs/commandline/filenm.h"
58
+ #include "gromacs/domdec/builder.h"
59
+ #include "gromacs/domdec/domdec.h"
60
+ #include "gromacs/domdec/domdec_struct.h"
61
+ #include "gromacs/domdec/gpuhaloexchange.h"
62
+ #include "gromacs/domdec/localatomsetmanager.h"
63
+ #include "gromacs/domdec/makebondedlinks.h"
64
+ #include "gromacs/domdec/partition.h"
65
+ #include "gromacs/domdec/reversetopology.h"
66
+ #include "gromacs/ewald/ewald_utils.h"
67
+ #include "gromacs/ewald/pme.h"
68
+ #include "gromacs/ewald/pme_gpu_program.h"
69
+ #include "gromacs/ewald/pme_only.h"
70
+ #include "gromacs/ewald/pme_pp_comm_gpu.h"
71
+ #include "gromacs/fileio/checkpoint.h"
72
+ #include "gromacs/fileio/gmxfio.h"
73
+ #include "gromacs/fileio/oenv.h"
74
+ #include "gromacs/fileio/tpxio.h"
75
+ #include "gromacs/fileio/trrio.h"
76
+ #include "gromacs/gmxlib/network.h"
77
+ #include "gromacs/gmxlib/nrnb.h"
78
+ #include "gromacs/gpu_utils/device_stream_manager.h"
79
+ #include "gromacs/gpu_utils/gpueventsynchronizer_helpers.h"
80
+ #include "gromacs/hardware/cpuinfo.h"
81
+ #include "gromacs/hardware/detecthardware.h"
82
+ #include "gromacs/hardware/device_management.h"
83
+ #include "gromacs/hardware/hardwaretopology.h"
84
+ #include "gromacs/hardware/printhardware.h"
85
+ #include "gromacs/imd/imd.h"
86
+ #include "gromacs/listed_forces/disre.h"
87
+ #include "gromacs/listed_forces/listed_forces.h"
88
+ #include "gromacs/listed_forces/listed_forces_gpu.h"
89
+ #include "gromacs/listed_forces/orires.h"
90
+ #include "gromacs/math/functions.h"
91
+ #include "gromacs/math/utilities.h"
92
+ #include "gromacs/math/vec.h"
93
+ #include "gromacs/mdlib/boxdeformation.h"
94
+ #include "gromacs/mdlib/broadcaststructs.h"
95
+ #include "gromacs/mdlib/calc_verletbuf.h"
96
+ #include "gromacs/mdlib/dispersioncorrection.h"
97
+ #include "gromacs/mdlib/enerdata_utils.h"
98
+ #include "gromacs/mdlib/force.h"
99
+ #include "gromacs/mdlib/forcerec.h"
100
+ #include "gromacs/mdlib/gmx_omp_nthreads.h"
101
+ #include "gromacs/mdlib/gpuforcereduction.h"
102
+ #include "gromacs/mdlib/makeconstraints.h"
103
+ #include "gromacs/mdlib/md_support.h"
104
+ #include "gromacs/mdlib/mdatoms.h"
105
+ #include "gromacs/mdlib/mdgraph_gpu.h"
106
+ #include "gromacs/mdlib/sighandler.h"
107
+ #include "gromacs/mdlib/stophandler.h"
108
+ #include "gromacs/mdlib/tgroup.h"
109
+ #include "gromacs/mdlib/updategroups.h"
110
+ #include "gromacs/mdlib/vsite.h"
111
+ #include "gromacs/mdrun/mdmodules.h"
112
+ #include "gromacs/mdrun/simulationcontext.h"
113
+ #include "gromacs/mdrun/simulationinput.h"
114
+ #include "gromacs/mdrun/simulationinputhandle.h"
115
+ #include "gromacs/mdrunutility/handlerestart.h"
116
+ #include "gromacs/mdrunutility/logging.h"
117
+ #include "gromacs/mdrunutility/mdmodulesnotifiers.h"
118
+ #include "gromacs/mdrunutility/multisim.h"
119
+ #include "gromacs/mdrunutility/printtime.h"
120
+ #include "gromacs/mdrunutility/threadaffinity.h"
121
+ #include "gromacs/mdtypes/checkpointdata.h"
122
+ #include "gromacs/mdtypes/commrec.h"
123
+ #include "gromacs/mdtypes/enerdata.h"
124
+ #include "gromacs/mdtypes/fcdata.h"
125
+ #include "gromacs/mdtypes/forcerec.h"
126
+ #include "gromacs/mdtypes/group.h"
127
+ #include "gromacs/mdtypes/inputrec.h"
128
+ #include "gromacs/mdtypes/interaction_const.h"
129
+ #include "gromacs/mdtypes/md_enums.h"
130
+ #include "gromacs/mdtypes/mdatom.h"
131
+ #include "gromacs/mdtypes/mdrunoptions.h"
132
+ #include "gromacs/mdtypes/multipletimestepping.h"
133
+ #include "gromacs/mdtypes/observableshistory.h"
134
+ #include "gromacs/mdtypes/observablesreducer.h"
135
+ #include "gromacs/mdtypes/simulation_workload.h"
136
+ #include "gromacs/mdtypes/state.h"
137
+ #include "gromacs/mdtypes/state_propagator_data_gpu.h"
138
+ #include "gromacs/modularsimulator/modularsimulator.h"
139
+ #include "gromacs/nbnxm/gpu_data_mgmt.h"
140
+ #include "gromacs/nbnxm/nbnxm.h"
141
+ #include "gromacs/nbnxm/pairlist_tuning.h"
142
+ #include "gromacs/pbcutil/pbc.h"
143
+ #include "gromacs/pulling/output.h"
144
+ #include "gromacs/pulling/pull.h"
145
+ #include "gromacs/pulling/pull_rotation.h"
146
+ #include "gromacs/restraint/manager.h"
147
+ #include "gromacs/restraint/restraintmdmodule.h"
148
+ #include "gromacs/restraint/restraintpotential.h"
149
+ #include "gromacs/swap/swapcoords.h"
150
+ #include "gromacs/taskassignment/decidegpuusage.h"
151
+ #include "gromacs/taskassignment/decidesimulationworkload.h"
152
+ #include "gromacs/taskassignment/resourcedivision.h"
153
+ #include "gromacs/taskassignment/taskassignment.h"
154
+ #include "gromacs/taskassignment/usergpuids.h"
155
+ #include "gromacs/timing/gpu_timing.h"
156
+ #include "gromacs/timing/wallcycle.h"
157
+ #include "gromacs/timing/wallcyclereporting.h"
158
+ #include "gromacs/topology/mtop_util.h"
159
+ #include "gromacs/topology/topology.h"
160
+ #include "gromacs/trajectory/trajectoryframe.h"
161
+ #include "gromacs/utility/basenetwork.h"
162
+ #include "gromacs/utility/cstringutil.h"
163
+ #include "gromacs/utility/exceptions.h"
164
+ #include "gromacs/utility/fatalerror.h"
165
+ #include "gromacs/utility/filestream.h"
166
+ #include "gromacs/utility/gmxassert.h"
167
+ #include "gromacs/utility/gmxmpi.h"
168
+ #include "gromacs/utility/keyvaluetree.h"
169
+ #include "gromacs/utility/logger.h"
170
+ #include "gromacs/utility/loggerbuilder.h"
171
+ #include "gromacs/utility/mpiinfo.h"
172
+ #include "gromacs/utility/physicalnodecommunicator.h"
173
+ #include "gromacs/utility/pleasecite.h"
174
+ #include "gromacs/utility/programcontext.h"
175
+ #include "gromacs/utility/smalloc.h"
176
+ #include "gromacs/utility/stringutil.h"
177
+
178
+ #include "isimulator.h"
179
+ #include "membedholder.h"
180
+ #include "replicaexchange.h"
181
+ #include "simulatorbuilder.h"
182
+
183
+ /* PLUMED */
184
+ #include "../../../Plumed.h"
185
+ int plumedswitch;
186
+ plumed plumedmain;
187
+ /* END PLUMED */
188
+
189
+ /* PLUMED HREX */
190
+ int plumed_hrex;
191
+ /* END PLUMED HREX */
192
+
193
+ namespace gmx
194
+ {
195
+
196
+ /*! \brief Manage any development feature flag variables encountered
197
+ *
198
+ * The use of dev features indicated by environment variables is
199
+ * logged in order to ensure that runs with such features enabled can
200
+ * be identified from their log and standard output. Any cross
201
+ * dependencies are also checked, and if unsatisfied, a fatal error
202
+ * issued.
203
+ *
204
+ * Note that some development features overrides are applied already here:
205
+ * the GPU communication flags are set to false in non-tMPI and non-CUDA builds.
206
+ *
207
+ * \param[in] mdlog Logger object.
208
+ * \param[in] useGpuForNonbonded True if the nonbonded task is offloaded in this run.
209
+ * \param[in] pmeRunMode Run mode indicating what resource is PME executed on.
210
+ * \param[in] numRanksPerSimulation The number of ranks in each simulation.
211
+ * \param[in] numPmeRanksPerSimulation The number of PME ranks in each simulation, can be -1
212
+ * \returns The object populated with development feature flags.
213
+ */
214
+ static DevelopmentFeatureFlags manageDevelopmentFeatures(const gmx::MDLogger& mdlog,
215
+ const bool useGpuForNonbonded,
216
+ const PmeRunMode pmeRunMode,
217
+ const int numRanksPerSimulation,
218
+ const int numPmeRanksPerSimulation)
219
+ {
220
+ DevelopmentFeatureFlags devFlags;
221
+
222
+ devFlags.enableGpuBufferOps = (GMX_GPU_CUDA || GMX_GPU_SYCL) && useGpuForNonbonded
223
+ && (getenv("GMX_USE_GPU_BUFFER_OPS") != nullptr);
224
+
225
+ if (getenv("GMX_CUDA_GRAPH") != nullptr)
226
+ {
227
+ if (GMX_HAVE_CUDA_GRAPH_SUPPORT)
228
+ {
229
+ devFlags.enableCudaGraphs = true;
230
+ GMX_LOG(mdlog.warning)
231
+ .asParagraph()
232
+ .appendText(
233
+ "GMX_CUDA_GRAPH environment variable is detected. "
234
+ "The experimental CUDA Graphs feature will be used if run conditions "
235
+ "allow.");
236
+ }
237
+ else
238
+ {
239
+ devFlags.enableCudaGraphs = false;
240
+ GMX_LOG(mdlog.warning)
241
+ .asParagraph()
242
+ .appendText(
243
+ "GMX_CUDA_GRAPH environment variable is detected, "
244
+ "but the CUDA version in use is below the minumum requirement (11.1). "
245
+ "CUDA Graphs will be disabled.");
246
+ }
247
+ }
248
+
249
+ // Flag use to enable GPU-aware MPI depenendent features such PME GPU decomposition
250
+ // GPU-aware MPI is marked available if it has been detected by GROMACS or detection fails but
251
+ // user wants to force its use
252
+ devFlags.canUseGpuAwareMpi = false;
253
+
254
+ // Direct GPU comm path is being used with GPU-aware MPI
255
+ // make sure underlying MPI implementation is GPU-aware
256
+
257
+ if (GMX_LIB_MPI && (GMX_GPU_CUDA || GMX_GPU_SYCL))
258
+ {
259
+ // Allow overriding the detection for GPU-aware MPI
260
+ GpuAwareMpiStatus gpuAwareMpiStatus = checkMpiCudaAwareSupport();
261
+ const bool forceGpuAwareMpi = gpuAwareMpiStatus == GpuAwareMpiStatus::Forced;
262
+ const bool haveDetectedGpuAwareMpi = gpuAwareMpiStatus == GpuAwareMpiStatus::Supported;
263
+ if (getenv("GMX_FORCE_CUDA_AWARE_MPI") != nullptr)
264
+ {
265
+ GMX_LOG(mdlog.warning)
266
+ .asParagraph()
267
+ .appendText(
268
+ "GMX_FORCE_CUDA_AWARE_MPI environment variable is inactive. "
269
+ "Please use GMX_FORCE_GPU_AWARE_MPI instead.");
270
+ }
271
+
272
+ devFlags.canUseGpuAwareMpi = haveDetectedGpuAwareMpi || forceGpuAwareMpi;
273
+ if (getenv("GMX_ENABLE_DIRECT_GPU_COMM") != nullptr)
274
+ {
275
+ if (!haveDetectedGpuAwareMpi && forceGpuAwareMpi)
276
+ {
277
+ // GPU-aware support not detected in MPI library but, user has forced it's use
278
+ GMX_LOG(mdlog.warning)
279
+ .asParagraph()
280
+ .appendText(
281
+ "This run has forced use of 'GPU-aware MPI'. "
282
+ "However, GROMACS cannot determine if underlying MPI is GPU-aware. "
283
+ "Check the GROMACS install guide for recommendations for GPU-aware "
284
+ "support. If you observe failures at runtime, try unsetting the "
285
+ "GMX_FORCE_GPU_AWARE_MPI environment variable.");
286
+ }
287
+
288
+ if (devFlags.canUseGpuAwareMpi)
289
+ {
290
+ GMX_LOG(mdlog.warning)
291
+ .asParagraph()
292
+ .appendText(
293
+ "GMX_ENABLE_DIRECT_GPU_COMM environment variable detected, "
294
+ "enabling direct GPU communication using GPU-aware MPI.");
295
+ }
296
+ else
297
+ {
298
+ GMX_LOG(mdlog.warning)
299
+ .asParagraph()
300
+ .appendText(
301
+ "GPU-aware MPI was not detected, will not use direct GPU "
302
+ "communication. Check the GROMACS install guide for "
303
+ "recommendations "
304
+ "for GPU-aware support. If you are certain about GPU-aware support "
305
+ "in your MPI library, you can force its use by setting the "
306
+ "GMX_FORCE_GPU_AWARE_MPI environment variable.");
307
+ }
308
+ }
309
+ else if (haveDetectedGpuAwareMpi)
310
+ {
311
+ // GPU-aware MPI was detected, let the user know that using it may improve performance
312
+ GMX_LOG(mdlog.warning)
313
+ .asParagraph()
314
+ .appendText(
315
+ "GPU-aware MPI detected, but by default GROMACS will not "
316
+ "make use the direct GPU communication capabilities of MPI. "
317
+ "For improved performance try enabling the feature by setting "
318
+ "the GMX_ENABLE_DIRECT_GPU_COMM environment variable.");
319
+ }
320
+ }
321
+ else
322
+ {
323
+ if (getenv("GMX_FORCE_GPU_AWARE_MPI") != nullptr)
324
+ {
325
+ // Cannot force use of GPU-aware MPI in this build configuration
326
+ GMX_LOG(mdlog.info)
327
+ .asParagraph()
328
+ .appendText(
329
+ "A CUDA or SYCL build with an external MPI library is required in "
330
+ "order to benefit from GMX_FORCE_GPU_AWARE_MPI. That environment "
331
+ "variable is being ignored because such a build is not in use.");
332
+ }
333
+ }
334
+
335
+ if (devFlags.enableGpuBufferOps)
336
+ {
337
+ GMX_LOG(mdlog.warning)
338
+ .asParagraph()
339
+ .appendTextFormatted(
340
+ "This run uses the 'GPU buffer ops' feature, enabled by the "
341
+ "GMX_USE_GPU_BUFFER_OPS environment variable.");
342
+ }
343
+
344
+ // PME decomposition is supported only with CUDA-backend in mixed mode
345
+ // CUDA-backend also needs GPU-aware MPI support for decomposition to work
346
+ const bool pmeGpuDecompositionRequested =
347
+ (pmeRunMode == PmeRunMode::GPU || pmeRunMode == PmeRunMode::Mixed)
348
+ && ((numRanksPerSimulation > 1 && numPmeRanksPerSimulation == 0)
349
+ || numPmeRanksPerSimulation > 1);
350
+ const bool pmeGpuDecompositionSupported =
351
+ (devFlags.canUseGpuAwareMpi && (GMX_GPU_CUDA || GMX_GPU_SYCL)
352
+ && ((pmeRunMode == PmeRunMode::GPU && (GMX_USE_Heffte || GMX_USE_cuFFTMp))
353
+ || pmeRunMode == PmeRunMode::Mixed));
354
+
355
+ const bool forcePmeGpuDecomposition = getenv("GMX_GPU_PME_DECOMPOSITION") != nullptr;
356
+
357
+ if (pmeGpuDecompositionSupported && pmeGpuDecompositionRequested)
358
+ {
359
+ // PME decomposition is supported only when it is forced using GMX_GPU_PME_DECOMPOSITION
360
+ if (forcePmeGpuDecomposition)
361
+ {
362
+ GMX_LOG(mdlog.warning)
363
+ .asParagraph()
364
+ .appendTextFormatted(
365
+ "This run has requested the 'GPU PME decomposition' feature, enabled "
366
+ "by the GMX_GPU_PME_DECOMPOSITION environment variable. "
367
+ "PME decomposition lacks substantial testing "
368
+ "and should be used with caution.");
369
+ }
370
+ else
371
+ {
372
+ gmx_fatal(FARGS,
373
+ "Multiple PME tasks were required to run on GPUs, "
374
+ "but that is not supported. "
375
+ "Use GMX_GPU_PME_DECOMPOSITION environment variable to enable it.");
376
+ }
377
+ }
378
+
379
+ if (!pmeGpuDecompositionSupported && pmeGpuDecompositionRequested)
380
+ {
381
+ if (GMX_GPU_CUDA)
382
+ {
383
+ gmx_fatal(FARGS,
384
+ "PME tasks were required to run on more than one CUDA-devices. To enable "
385
+ "this feature, "
386
+ "use MPI with CUDA-aware support and build GROMACS with cuFFTMp support.");
387
+ }
388
+ else
389
+ {
390
+ gmx_fatal(
391
+ FARGS,
392
+ "PME tasks were required to run on GPUs, but that is not implemented with "
393
+ "more than one PME rank. Use a single rank simulation, or a separate PME rank, "
394
+ "or permit PME tasks to be assigned to the CPU.");
395
+ }
396
+ }
397
+
398
+ devFlags.enableGpuPmeDecomposition =
399
+ forcePmeGpuDecomposition && pmeGpuDecompositionRequested && pmeGpuDecompositionSupported;
400
+
401
+ return devFlags;
402
+ }
403
+
404
+ /*! \brief Barrier for safe simultaneous thread access to mdrunner data
405
+ *
406
+ * Used to ensure that the main thread does not modify mdrunner during copy
407
+ * on the spawned threads. */
408
+ static void threadMpiMdrunnerAccessBarrier()
409
+ {
410
+ #if GMX_THREAD_MPI
411
+ MPI_Barrier(MPI_COMM_WORLD);
412
+ #endif
413
+ }
414
+
415
+ Mdrunner Mdrunner::cloneOnSpawnedThread() const
416
+ {
417
+ auto newRunner = Mdrunner(std::make_unique<MDModules>());
418
+
419
+ // All runners in the same process share a restraint manager resource because it is
420
+ // part of the interface to the client code, which is associated only with the
421
+ // original thread. Handles to the same resources can be obtained by copy.
422
+ {
423
+ newRunner.restraintManager_ = std::make_unique<RestraintManager>(*restraintManager_);
424
+ }
425
+
426
+ // Copy members of main runner.
427
+ // \todo Replace with builder when Simulation context and/or runner phases are better defined.
428
+ // Ref https://gitlab.com/gromacs/gromacs/-/issues/2587 and https://gitlab.com/gromacs/gromacs/-/issues/2375
429
+ newRunner.hw_opt = hw_opt;
430
+ newRunner.filenames = filenames;
431
+
432
+ newRunner.hwinfo_ = hwinfo_;
433
+ newRunner.oenv = oenv;
434
+ newRunner.mdrunOptions = mdrunOptions;
435
+ newRunner.domdecOptions = domdecOptions;
436
+ newRunner.nbpu_opt = nbpu_opt;
437
+ newRunner.pme_opt = pme_opt;
438
+ newRunner.pme_fft_opt = pme_fft_opt;
439
+ newRunner.bonded_opt = bonded_opt;
440
+ newRunner.update_opt = update_opt;
441
+ newRunner.nstlist_cmdline = nstlist_cmdline;
442
+ newRunner.replExParams = replExParams;
443
+ newRunner.pforce = pforce;
444
+ // Give the spawned thread the newly created valid communicator
445
+ // for the simulation.
446
+ newRunner.libraryWorldCommunicator = MPI_COMM_WORLD;
447
+ newRunner.simulationCommunicator = MPI_COMM_WORLD;
448
+ newRunner.ms = ms;
449
+ newRunner.startingBehavior = startingBehavior;
450
+ newRunner.stopHandlerBuilder_ = std::make_unique<StopHandlerBuilder>(*stopHandlerBuilder_);
451
+ newRunner.inputHolder_ = inputHolder_;
452
+
453
+ threadMpiMdrunnerAccessBarrier();
454
+
455
+ return newRunner;
456
+ }
457
+
458
+ /*! \brief The callback used for running on spawned threads.
459
+ *
460
+ * Obtains the pointer to the main mdrunner object from the one
461
+ * argument permitted to the thread-launch API call, copies it to make
462
+ * a new runner for this thread, reinitializes necessary data, and
463
+ * proceeds to the simulation. */
464
+ static void mdrunner_start_fn(const void* arg)
465
+ {
466
+ try
467
+ {
468
+ const auto* mainMdrunner = reinterpret_cast<const gmx::Mdrunner*>(arg);
469
+ /* copy the arg list to make sure that it's thread-local. This
470
+ doesn't copy pointed-to items, of course; fnm, cr and fplog
471
+ are reset in the call below, all others should be const. */
472
+ gmx::Mdrunner mdrunner = mainMdrunner->cloneOnSpawnedThread();
473
+ mdrunner.mdrunner();
474
+ }
475
+ GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
476
+ }
477
+
478
+
479
+ void Mdrunner::spawnThreads(int numThreadsToLaunch)
480
+ {
481
+ #if GMX_THREAD_MPI
482
+ /* now spawn new threads that start mdrunner_start_fn(), while
483
+ the main thread returns. Thread affinity is handled later. */
484
+ if (tMPI_Init_fn(TRUE, numThreadsToLaunch, TMPI_AFFINITY_NONE, mdrunner_start_fn, static_cast<const void*>(this))
485
+ != TMPI_SUCCESS)
486
+ {
487
+ GMX_THROW(gmx::InternalError("Failed to spawn thread-MPI threads"));
488
+ }
489
+
490
+ // Give the main thread the newly created valid communicator for
491
+ // the simulation.
492
+ libraryWorldCommunicator = MPI_COMM_WORLD;
493
+ simulationCommunicator = MPI_COMM_WORLD;
494
+ threadMpiMdrunnerAccessBarrier();
495
+ #else
496
+ GMX_UNUSED_VALUE(numThreadsToLaunch);
497
+ GMX_UNUSED_VALUE(mdrunner_start_fn);
498
+ #endif
499
+ }
500
+
501
+ } // namespace gmx
502
+
503
+ /*! \brief Initialize variables for Verlet scheme simulation */
504
+ static void prepare_verlet_scheme(FILE* fplog,
505
+ t_commrec* cr,
506
+ t_inputrec* ir,
507
+ int nstlist_cmdline,
508
+ const gmx_mtop_t& mtop,
509
+ gmx::ArrayRef<const gmx::RVec> coordinates,
510
+ const matrix box,
511
+ bool makeGpuPairList,
512
+ const gmx::CpuInfo& cpuinfo)
513
+ {
514
+ // We checked the cut-offs in grompp, but double-check here.
515
+ // We have PME+LJcutoff kernels for rcoulomb>rvdw.
516
+ if (usingPmeOrEwald(ir->coulombtype) && ir->vdwtype == VanDerWaalsType::Cut)
517
+ {
518
+ GMX_RELEASE_ASSERT(ir->rcoulomb >= ir->rvdw,
519
+ "With Verlet lists and PME we should have rcoulomb>=rvdw");
520
+ }
521
+ else
522
+ {
523
+ GMX_RELEASE_ASSERT(ir->rcoulomb == ir->rvdw,
524
+ "With Verlet lists and no PME rcoulomb and rvdw should be identical");
525
+ }
526
+
527
+ std::optional<real> effectiveAtomDensity;
528
+ if (EI_DYNAMICS(ir->eI))
529
+ {
530
+ effectiveAtomDensity = computeEffectiveAtomDensity(
531
+ coordinates, box, std::max(ir->rcoulomb, ir->rvdw), cr->mpiDefaultCommunicator);
532
+ }
533
+
534
+ /* For NVE simulations, we will retain the initial list buffer */
535
+ if (EI_DYNAMICS(ir->eI) && ir->verletbuf_tol > 0
536
+ && !(EI_MD(ir->eI) && ir->etc == TemperatureCoupling::No))
537
+ {
538
+ /* Update the Verlet buffer size for the current run setup */
539
+
540
+ /* Here we assume SIMD-enabled kernels are being used. But as currently
541
+ * calc_verlet_buffer_size gives the same results for 4x8 and 4x4
542
+ * and 4x2 gives a larger buffer than 4x4, this is ok.
543
+ */
544
+ ListSetupType listType =
545
+ (makeGpuPairList ? ListSetupType::Gpu : ListSetupType::CpuSimdWhenSupported);
546
+ VerletbufListSetup listSetup = verletbufGetSafeListSetup(listType);
547
+
548
+ const real rlist_new = calcVerletBufferSize(
549
+ mtop, effectiveAtomDensity.value(), *ir, -1, ir->nstlist, ir->nstlist - 1, -1, listSetup);
550
+
551
+ if (rlist_new != ir->rlist)
552
+ {
553
+ if (fplog != nullptr)
554
+ {
555
+ fprintf(fplog,
556
+ "\nChanging rlist from %g to %g for non-bonded %dx%d atom kernels\n\n",
557
+ ir->rlist,
558
+ rlist_new,
559
+ listSetup.cluster_size_i,
560
+ listSetup.cluster_size_j);
561
+ }
562
+ ir->rlist = rlist_new;
563
+ }
564
+ }
565
+
566
+ if (nstlist_cmdline > 0 && (!EI_DYNAMICS(ir->eI) || ir->verletbuf_tol <= 0))
567
+ {
568
+ gmx_fatal(FARGS,
569
+ "Can not set nstlist without %s",
570
+ !EI_DYNAMICS(ir->eI) ? "dynamics" : "verlet-buffer-tolerance");
571
+ }
572
+
573
+ if (EI_DYNAMICS(ir->eI))
574
+ {
575
+ /* Set or try nstlist values */
576
+ increaseNstlist(
577
+ fplog, cr, ir, nstlist_cmdline, &mtop, box, effectiveAtomDensity.value(), makeGpuPairList, cpuinfo);
578
+ }
579
+ }
580
+
581
+ /*! \brief Override the nslist value in inputrec
582
+ *
583
+ * with value passed on the command line (if any)
584
+ */
585
+ static void override_nsteps_cmdline(const gmx::MDLogger& mdlog, int64_t nsteps_cmdline, t_inputrec* ir)
586
+ {
587
+ assert(ir);
588
+
589
+ /* override with anything else than the default -2 */
590
+ if (nsteps_cmdline > -2)
591
+ {
592
+ char sbuf_steps[STEPSTRSIZE];
593
+ char sbuf_msg[STRLEN];
594
+
595
+ ir->nsteps = nsteps_cmdline;
596
+ if (EI_DYNAMICS(ir->eI) && nsteps_cmdline != -1)
597
+ {
598
+ sprintf(sbuf_msg,
599
+ "Overriding nsteps with value passed on the command line: %s steps, %.3g ps",
600
+ gmx_step_str(nsteps_cmdline, sbuf_steps),
601
+ fabs(nsteps_cmdline * ir->delta_t));
602
+ }
603
+ else
604
+ {
605
+ sprintf(sbuf_msg,
606
+ "Overriding nsteps with value passed on the command line: %s steps",
607
+ gmx_step_str(nsteps_cmdline, sbuf_steps));
608
+ }
609
+
610
+ GMX_LOG(mdlog.warning).asParagraph().appendText(sbuf_msg);
611
+ }
612
+ else if (nsteps_cmdline < -2)
613
+ {
614
+ gmx_fatal(FARGS, "Invalid nsteps value passed on the command line: %" PRId64, nsteps_cmdline);
615
+ }
616
+ /* Do nothing if nsteps_cmdline == -2 */
617
+ }
618
+
619
+ namespace gmx
620
+ {
621
+
622
+ /*! \brief Return whether GPU acceleration of nonbondeds is supported with the given settings.
623
+ *
624
+ * If not, and if a warning may be issued, logs a warning about
625
+ * falling back to CPU code. With thread-MPI, only the first
626
+ * call to this function should have \c issueWarning true. */
627
+ static bool gpuAccelerationOfNonbondedIsUseful(const MDLogger& mdlog,
628
+ const t_inputrec& ir,
629
+ const bool issueWarning,
630
+ const bool doRerun)
631
+ {
632
+ bool gpuIsUseful = true;
633
+ std::string warning;
634
+
635
+ if (ir.opts.ngener - ir.nwall > 1)
636
+ {
637
+ /* The GPU code does not support more than one energy group.
638
+ * If the user requested GPUs explicitly, a fatal error is given later.
639
+ */
640
+ gpuIsUseful = false;
641
+ if (!doRerun)
642
+ {
643
+ warning =
644
+ "Multiple energy groups is not implemented for GPUs, falling back to the CPU. "
645
+ "For better performance, run on the GPU without energy groups and then do "
646
+ "gmx mdrun -rerun option on the trajectory with an energy group .tpr file.";
647
+ }
648
+ }
649
+
650
+ /* There are resource handling issues in the GPU code paths with MTS on anything else than only
651
+ * PME. Also those code paths need more testing.
652
+ */
653
+ MtsLevel mtsLevelOnlyPme;
654
+ mtsLevelOnlyPme.forceGroups.set(static_cast<int>(MtsForceGroups::LongrangeNonbonded));
655
+ if (ir.useMts && !(ir.mtsLevels.size() == 2 && ir.mtsLevels[1].forceGroups == mtsLevelOnlyPme.forceGroups))
656
+ {
657
+ gpuIsUseful = false;
658
+ warning = gmx::formatString(
659
+ "Multiple time stepping is only supported with GPUs when MTS is only applied to %s "
660
+ "forces.",
661
+ mtsForceGroupNames[MtsForceGroups::LongrangeNonbonded].c_str());
662
+ }
663
+
664
+ if (EI_TPI(ir.eI))
665
+ {
666
+ gpuIsUseful = false;
667
+ warning = "TPI is not implemented for GPUs.";
668
+ }
669
+
670
+ if (!gpuIsUseful && issueWarning)
671
+ {
672
+ GMX_LOG(mdlog.warning).asParagraph().appendText(warning);
673
+ }
674
+
675
+ return gpuIsUseful;
676
+ }
677
+
678
+ //! Initializes the logger for mdrun.
679
+ static gmx::LoggerOwner buildLogger(FILE* fplog, const bool isSimulationMainRank)
680
+ {
681
+ gmx::LoggerBuilder builder;
682
+ if (fplog != nullptr)
683
+ {
684
+ builder.addTargetFile(gmx::MDLogger::LogLevel::Info, fplog);
685
+ }
686
+ if (isSimulationMainRank)
687
+ {
688
+ builder.addTargetStream(gmx::MDLogger::LogLevel::Warning, &gmx::TextOutputFile::standardError());
689
+ }
690
+ return builder.build();
691
+ }
692
+
693
+ //! Make a TaskTarget from an mdrun argument string.
694
+ static TaskTarget findTaskTarget(const char* optionString)
695
+ {
696
+ TaskTarget returnValue = TaskTarget::Auto;
697
+
698
+ if (strncmp(optionString, "auto", 3) == 0)
699
+ {
700
+ returnValue = TaskTarget::Auto;
701
+ }
702
+ else if (strncmp(optionString, "cpu", 3) == 0)
703
+ {
704
+ returnValue = TaskTarget::Cpu;
705
+ }
706
+ else if (strncmp(optionString, "gpu", 3) == 0)
707
+ {
708
+ returnValue = TaskTarget::Gpu;
709
+ }
710
+ else
711
+ {
712
+ GMX_ASSERT(false, "Option string should have been checked for sanity already");
713
+ }
714
+
715
+ return returnValue;
716
+ }
717
+
718
+ //! Finish run, aggregate data to print performance info.
719
+ static void finish_run(FILE* fplog,
720
+ const gmx::MDLogger& mdlog,
721
+ const t_commrec* cr,
722
+ const t_inputrec& inputrec,
723
+ t_nrnb nrnb[],
724
+ gmx_wallcycle* wcycle,
725
+ gmx_walltime_accounting_t walltime_accounting,
726
+ nonbonded_verlet_t* nbv,
727
+ const gmx_pme_t* pme,
728
+ gmx_bool bWriteStat)
729
+ {
730
+ double delta_t = 0;
731
+ double nbfs = 0, mflop = 0;
732
+ double elapsed_time, elapsed_time_over_all_ranks, elapsed_time_over_all_threads,
733
+ elapsed_time_over_all_threads_over_all_ranks;
734
+ /* Control whether it is valid to print a report. Only the
735
+ simulation main may print, but it should not do so if the run
736
+ terminated e.g. before a scheduled reset step. This is
737
+ complicated by the fact that PME ranks are unaware of the
738
+ reason why they were sent a pmerecvqxFINISH. To avoid
739
+ communication deadlocks, we always do the communication for the
740
+ report, even if we've decided not to write the report, because
741
+ how long it takes to finish the run is not important when we've
742
+ decided not to report on the simulation performance.
743
+
744
+ Further, we only report performance for dynamical integrators,
745
+ because those are the only ones for which we plan to
746
+ consider doing any optimizations. */
747
+ bool printReport = EI_DYNAMICS(inputrec.eI) && SIMMAIN(cr);
748
+
749
+ if (printReport && !walltime_accounting_get_valid_finish(walltime_accounting))
750
+ {
751
+ GMX_LOG(mdlog.warning)
752
+ .asParagraph()
753
+ .appendText("Simulation ended prematurely, no performance report will be written.");
754
+ printReport = false;
755
+ }
756
+
757
+ t_nrnb* nrnb_tot;
758
+ std::unique_ptr<t_nrnb> nrnbTotalStorage;
759
+ if (cr->nnodes > 1)
760
+ {
761
+ nrnbTotalStorage = std::make_unique<t_nrnb>();
762
+ nrnb_tot = nrnbTotalStorage.get();
763
+ #if GMX_MPI
764
+ MPI_Allreduce(nrnb->n.data(), nrnb_tot->n.data(), eNRNB, MPI_DOUBLE, MPI_SUM, cr->mpi_comm_mysim);
765
+ #endif
766
+ }
767
+ else
768
+ {
769
+ nrnb_tot = nrnb;
770
+ }
771
+
772
+ elapsed_time = walltime_accounting_get_time_since_reset(walltime_accounting);
773
+ elapsed_time_over_all_threads =
774
+ walltime_accounting_get_time_since_reset_over_all_threads(walltime_accounting);
775
+ if (GMX_MPI && cr->nnodes > 1)
776
+ {
777
+ #if GMX_MPI
778
+ /* reduce elapsed_time over all MPI ranks in the current simulation */
779
+ MPI_Allreduce(&elapsed_time, &elapsed_time_over_all_ranks, 1, MPI_DOUBLE, MPI_SUM, cr->mpi_comm_mysim);
780
+ elapsed_time_over_all_ranks /= cr->nnodes;
781
+ /* Reduce elapsed_time_over_all_threads over all MPI ranks in the
782
+ * current simulation. */
783
+ MPI_Allreduce(&elapsed_time_over_all_threads,
784
+ &elapsed_time_over_all_threads_over_all_ranks,
785
+ 1,
786
+ MPI_DOUBLE,
787
+ MPI_SUM,
788
+ cr->mpi_comm_mysim);
789
+ #endif
790
+ }
791
+ else
792
+ {
793
+ elapsed_time_over_all_ranks = elapsed_time;
794
+ elapsed_time_over_all_threads_over_all_ranks = elapsed_time_over_all_threads;
795
+ }
796
+
797
+ if (printReport)
798
+ {
799
+ print_flop(fplog, nrnb_tot, &nbfs, &mflop);
800
+ }
801
+
802
+ if (thisRankHasDuty(cr, DUTY_PP) && haveDDAtomOrdering(*cr))
803
+ {
804
+ print_dd_statistics(cr, inputrec, fplog);
805
+ }
806
+
807
+ /* TODO Move the responsibility for any scaling by thread counts
808
+ * to the code that handled the thread region, so that there's a
809
+ * mechanism to keep cycle counting working during the transition
810
+ * to task parallelism. */
811
+ int nthreads_pp = gmx_omp_nthreads_get(ModuleMultiThread::Nonbonded);
812
+ int nthreads_pme = gmx_omp_nthreads_get(ModuleMultiThread::Pme);
813
+ wallcycle_scale_by_num_threads(
814
+ wcycle, thisRankHasDuty(cr, DUTY_PME) && !thisRankHasDuty(cr, DUTY_PP), nthreads_pp, nthreads_pme);
815
+ auto cycle_sum(wallcycle_sum(cr, wcycle));
816
+
817
+ if (printReport)
818
+ {
819
+ auto* nbnxn_gpu_timings =
820
+ (nbv != nullptr && nbv->useGpu()) ? Nbnxm::gpu_get_timings(nbv->gpu_nbv) : nullptr;
821
+ gmx_wallclock_gpu_pme_t pme_gpu_timings = {};
822
+
823
+ if (pme_gpu_task_enabled(pme))
824
+ {
825
+ pme_gpu_get_timings(pme, &pme_gpu_timings);
826
+ }
827
+ wallcycle_print(fplog,
828
+ mdlog,
829
+ cr->nnodes,
830
+ cr->npmenodes,
831
+ nthreads_pp,
832
+ nthreads_pme,
833
+ elapsed_time_over_all_ranks,
834
+ wcycle,
835
+ cycle_sum,
836
+ nbnxn_gpu_timings,
837
+ &pme_gpu_timings);
838
+
839
+ if (EI_DYNAMICS(inputrec.eI))
840
+ {
841
+ delta_t = inputrec.delta_t;
842
+ }
843
+
844
+ if (fplog)
845
+ {
846
+ print_perf(fplog,
847
+ elapsed_time_over_all_threads_over_all_ranks,
848
+ elapsed_time_over_all_ranks,
849
+ walltime_accounting_get_nsteps_done_since_reset(walltime_accounting),
850
+ delta_t,
851
+ nbfs,
852
+ mflop);
853
+ }
854
+ if (bWriteStat)
855
+ {
856
+ print_perf(stderr,
857
+ elapsed_time_over_all_threads_over_all_ranks,
858
+ elapsed_time_over_all_ranks,
859
+ walltime_accounting_get_nsteps_done_since_reset(walltime_accounting),
860
+ delta_t,
861
+ nbfs,
862
+ mflop);
863
+ }
864
+ }
865
+ }
866
+
867
+ int Mdrunner::mdrunner()
868
+ {
869
+ std::unique_ptr<t_forcerec> fr;
870
+ real ewaldcoeff_q = 0;
871
+ real ewaldcoeff_lj = 0;
872
+ int nChargePerturbed = -1, nTypePerturbed = 0;
873
+ gmx_walltime_accounting_t walltime_accounting = nullptr;
874
+ MembedHolder membedHolder(filenames.size(), filenames.data());
875
+
876
+ /* CAUTION: threads may be started later on in this function, so
877
+ cr doesn't reflect the final parallel state right now */
878
+ gmx_mtop_t mtop;
879
+
880
+ /* TODO: inputrec should tell us whether we use an algorithm, not a file option */
881
+ const bool doEssentialDynamics = opt2bSet("-ei", filenames.size(), filenames.data());
882
+ const bool doRerun = mdrunOptions.rerun;
883
+
884
+ // Handle task-assignment related user options.
885
+ EmulateGpuNonbonded emulateGpuNonbonded =
886
+ (getenv("GMX_EMULATE_GPU") != nullptr ? EmulateGpuNonbonded::Yes : EmulateGpuNonbonded::No);
887
+
888
+ std::vector<int> userGpuTaskAssignment;
889
+ try
890
+ {
891
+ userGpuTaskAssignment = parseUserTaskAssignmentString(hw_opt.userGpuTaskAssignment);
892
+ }
893
+ GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
894
+ auto nonbondedTarget = findTaskTarget(nbpu_opt);
895
+ auto pmeTarget = findTaskTarget(pme_opt);
896
+ auto pmeFftTarget = findTaskTarget(pme_fft_opt);
897
+ auto bondedTarget = findTaskTarget(bonded_opt);
898
+ auto updateTarget = findTaskTarget(update_opt);
899
+
900
+ FILE* fplog = nullptr;
901
+ // If we are appending, we don't write log output because we need
902
+ // to check that the old log file matches what the checkpoint file
903
+ // expects. Otherwise, we should start to write log output now if
904
+ // there is a file ready for it.
905
+ if (logFileHandle != nullptr && startingBehavior != StartingBehavior::RestartWithAppending)
906
+ {
907
+ fplog = gmx_fio_getfp(logFileHandle);
908
+ }
909
+ const bool isSimulationMainRank = findIsSimulationMainRank(ms, simulationCommunicator);
910
+ gmx::LoggerOwner logOwner(buildLogger(fplog, isSimulationMainRank));
911
+ gmx::MDLogger mdlog(logOwner.logger());
912
+
913
+ gmx_print_detected_hardware(fplog, isSimulationMainRank && isMainSim(ms), mdlog, hwinfo_);
914
+
915
+ std::vector<int> availableDevices =
916
+ makeListOfAvailableDevices(hwinfo_->deviceInfoList, hw_opt.devicesSelectedByUser);
917
+ const int numAvailableDevices = gmx::ssize(availableDevices);
918
+
919
+ // Print citation requests after all software/hardware printing
920
+ pleaseCiteGromacs(fplog);
921
+
922
+ // Note: legacy program logic relies on checking whether these pointers are assigned.
923
+ // Objects may or may not be allocated later.
924
+ std::unique_ptr<t_inputrec> inputrec;
925
+ std::unique_ptr<t_state> globalState;
926
+
927
+ auto partialDeserializedTpr = std::make_unique<PartialDeserializedTprFile>();
928
+
929
+ if (isSimulationMainRank)
930
+ {
931
+ // Allocate objects to be initialized by later function calls.
932
+ /* Only the main rank has the global state */
933
+ globalState = std::make_unique<t_state>();
934
+ inputrec = std::make_unique<t_inputrec>();
935
+
936
+ /* Read (nearly) all data required for the simulation
937
+ * and keep the partly serialized tpr contents to send to other ranks later
938
+ */
939
+ applyGlobalSimulationState(
940
+ *inputHolder_.get(), partialDeserializedTpr.get(), globalState.get(), inputrec.get(), &mtop);
941
+
942
+ static_assert(sc_trrMaxAtomCount == sc_checkpointMaxAtomCount);
943
+ if (mtop.natoms > sc_checkpointMaxAtomCount)
944
+ {
945
+ gmx_fatal(FARGS,
946
+ "System has %d atoms, which is more than can be stored in checkpoint and trr "
947
+ "files (max %" PRId64 ")",
948
+ mtop.natoms,
949
+ sc_checkpointMaxAtomCount);
950
+ }
951
+
952
+ // The XTC format has been updated to support up to 2^31-1 atoms, which is anyway the
953
+ // largest supported by GROMACS, so no need for any particular check here.
954
+ }
955
+
956
+ /* Check and update the hardware options for internal consistency */
957
+ checkAndUpdateHardwareOptions(
958
+ mdlog, &hw_opt, isSimulationMainRank, domdecOptions.numPmeRanks, inputrec.get());
959
+
960
+ if (GMX_THREAD_MPI && isSimulationMainRank)
961
+ {
962
+ bool useGpuForNonbonded = false;
963
+ bool useGpuForPme = false;
964
+ try
965
+ {
966
+ GMX_RELEASE_ASSERT(inputrec != nullptr, "Keep the compiler happy");
967
+
968
+ // If the user specified the number of ranks, then we must
969
+ // respect that, but in default mode, we need to allow for
970
+ // the number of GPUs to choose the number of ranks.
971
+ auto canUseGpuForNonbonded = buildSupportsNonbondedOnGpu(nullptr);
972
+ useGpuForNonbonded = decideWhetherToUseGpusForNonbondedWithThreadMpi(
973
+ nonbondedTarget,
974
+ numAvailableDevices > 0,
975
+ userGpuTaskAssignment,
976
+ emulateGpuNonbonded,
977
+ canUseGpuForNonbonded,
978
+ gpuAccelerationOfNonbondedIsUseful(mdlog, *inputrec, GMX_THREAD_MPI, doRerun),
979
+ hw_opt.nthreads_tmpi);
980
+ useGpuForPme = decideWhetherToUseGpusForPmeWithThreadMpi(useGpuForNonbonded,
981
+ pmeTarget,
982
+ pmeFftTarget,
983
+ numAvailableDevices,
984
+ userGpuTaskAssignment,
985
+ *inputrec,
986
+ hw_opt.nthreads_tmpi,
987
+ domdecOptions.numPmeRanks);
988
+ }
989
+ GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
990
+
991
+ /* Determine how many thread-MPI ranks to start.
992
+ *
993
+ * TODO Over-writing the user-supplied value here does
994
+ * prevent any possible subsequent checks from working
995
+ * correctly. */
996
+ hw_opt.nthreads_tmpi = get_nthreads_mpi(hwinfo_,
997
+ &hw_opt,
998
+ numAvailableDevices,
999
+ useGpuForNonbonded,
1000
+ useGpuForPme,
1001
+ inputrec.get(),
1002
+ mtop,
1003
+ mdlog,
1004
+ membedHolder.doMembed() && (plumedswitch==0) /* PLUMED */);
1005
+
1006
+ // Now start the threads for thread MPI.
1007
+ spawnThreads(hw_opt.nthreads_tmpi);
1008
+ // The spawned threads enter mdrunner() and execution of
1009
+ // main and spawned threads joins at the end of this block.
1010
+ }
1011
+
1012
+ GMX_RELEASE_ASSERT(!GMX_MPI || ms || simulationCommunicator != MPI_COMM_NULL,
1013
+ "Must have valid communicator unless running a multi-simulation");
1014
+ std::unique_ptr<t_commrec> crHandle(init_commrec(simulationCommunicator));
1015
+ t_commrec* cr = crHandle.get();
1016
+ GMX_RELEASE_ASSERT(cr != nullptr, "Must have valid commrec");
1017
+
1018
+ PhysicalNodeCommunicator physicalNodeComm(libraryWorldCommunicator, gmx_physicalnode_id_hash());
1019
+
1020
+ if (PAR(cr))
1021
+ {
1022
+ /* now broadcast everything to the non-main nodes/threads: */
1023
+ if (!isSimulationMainRank)
1024
+ {
1025
+ // Until now, only the main rank has a non-null pointer.
1026
+ // On non-main ranks, allocate the object that will receive data in the following call.
1027
+ inputrec = std::make_unique<t_inputrec>();
1028
+ }
1029
+ init_parallel(
1030
+ cr->mpiDefaultCommunicator, MAIN(cr), inputrec.get(), &mtop, partialDeserializedTpr.get());
1031
+ }
1032
+ GMX_RELEASE_ASSERT(inputrec != nullptr, "All ranks should have a valid inputrec now");
1033
+ partialDeserializedTpr.reset(nullptr);
1034
+
1035
+ // Note that these variables describe only their own node.
1036
+ //
1037
+ // Note that when bonded interactions run on a GPU they always run
1038
+ // alongside a nonbonded task, so do not influence task assignment
1039
+ // even though they affect the force calculation workload.
1040
+ bool useGpuForNonbonded = false;
1041
+ bool useGpuForPme = false;
1042
+ bool useGpuForBonded = false;
1043
+ bool useGpuForUpdate = false;
1044
+ bool gpusWereDetected = hwinfo_->ngpu_compatible_tot > 0;
1045
+ try
1046
+ {
1047
+ // It's possible that there are different numbers of GPUs on
1048
+ // different nodes, which is the user's responsibility to
1049
+ // handle. If unsuitable, we will notice that during task
1050
+ // assignment.
1051
+ auto canUseGpuForNonbonded = buildSupportsNonbondedOnGpu(nullptr);
1052
+ useGpuForNonbonded = decideWhetherToUseGpusForNonbonded(
1053
+ nonbondedTarget,
1054
+ userGpuTaskAssignment,
1055
+ emulateGpuNonbonded,
1056
+ canUseGpuForNonbonded,
1057
+ gpuAccelerationOfNonbondedIsUseful(mdlog, *inputrec, !GMX_THREAD_MPI, doRerun),
1058
+ gpusWereDetected);
1059
+ useGpuForPme = decideWhetherToUseGpusForPme(useGpuForNonbonded,
1060
+ pmeTarget,
1061
+ pmeFftTarget,
1062
+ userGpuTaskAssignment,
1063
+ *inputrec,
1064
+ cr->sizeOfDefaultCommunicator,
1065
+ domdecOptions.numPmeRanks,
1066
+ gpusWereDetected);
1067
+ useGpuForBonded = decideWhetherToUseGpusForBonded(
1068
+ useGpuForNonbonded, useGpuForPme, bondedTarget, *inputrec, mtop, domdecOptions.numPmeRanks, gpusWereDetected);
1069
+ }
1070
+ GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
1071
+
1072
+ const PmeRunMode pmeRunMode = determinePmeRunMode(useGpuForPme, pmeFftTarget, *inputrec);
1073
+
1074
+ // Initialize development feature flags that enabled by environment variable
1075
+ // and report those features that are enabled.
1076
+ const DevelopmentFeatureFlags devFlags = manageDevelopmentFeatures(
1077
+ mdlog, useGpuForNonbonded, pmeRunMode, cr->sizeOfDefaultCommunicator, domdecOptions.numPmeRanks);
1078
+
1079
+ const bool useModularSimulator = checkUseModularSimulator(false,
1080
+ inputrec.get(),
1081
+ doRerun,
1082
+ mtop,
1083
+ ms,
1084
+ replExParams,
1085
+ nullptr,
1086
+ doEssentialDynamics,
1087
+ membedHolder.doMembed(),
1088
+ updateTarget == TaskTarget::Gpu);
1089
+
1090
+ // Now the number of ranks is known to all ranks, and each knows
1091
+ // the inputrec read by the main rank. The ranks can now all run
1092
+ // the task-deciding functions and will agree on the result
1093
+ // without needing to communicate.
1094
+ // The LBFGS minimizer, test-particle insertion, normal modes and shell dynamics don't support DD
1095
+ const bool hasCustomParallelization =
1096
+ (EI_TPI(inputrec->eI) || inputrec->eI == IntegrationAlgorithm::NM);
1097
+ const bool canUseDomainDecomposition =
1098
+ (inputrec->eI != IntegrationAlgorithm::LBFGS && !hasCustomParallelization
1099
+ && gmx_mtop_particletype_count(mtop)[ParticleType::Shell] == 0);
1100
+ GMX_RELEASE_ASSERT(!PAR(cr) || hasCustomParallelization || canUseDomainDecomposition,
1101
+ "A parallel run should not arrive here without DD support");
1102
+
1103
+ int useDDWithSingleRank = -1;
1104
+ if (const char* ddSingleRankEnv = getenv("GMX_DD_SINGLE_RANK"))
1105
+ {
1106
+ useDDWithSingleRank = std::strtol(ddSingleRankEnv, nullptr, 10);
1107
+ }
1108
+
1109
+ // The overhead of DD partitioning is only compensated when we have both non-bondeds and PME on the CPU
1110
+ const bool useDomainDecomposition =
1111
+ canUseDomainDecomposition
1112
+ && (PAR(cr)
1113
+ || (!useGpuForNonbonded && usingFullElectrostatics(inputrec->coulombtype)
1114
+ && useDDWithSingleRank != 0)
1115
+ || useDDWithSingleRank == 1);
1116
+
1117
+ ObservablesReducerBuilder observablesReducerBuilder;
1118
+
1119
+ // Build restraints.
1120
+ // TODO: hide restraint implementation details from Mdrunner.
1121
+ // There is nothing unique about restraints at this point as far as the
1122
+ // Mdrunner is concerned. The Mdrunner should just be getting a sequence of
1123
+ // factory functions from the SimulationContext on which to call mdModules_->add().
1124
+ // TODO: capture all restraints into a single RestraintModule, passed to the runner builder.
1125
+ for (auto&& restraint : restraintManager_->getRestraints())
1126
+ {
1127
+ auto module = RestraintMDModule::create(restraint, restraint->sites());
1128
+ mdModules_->add(std::move(module));
1129
+ }
1130
+
1131
+ // TODO: Error handling
1132
+ mdModules_->assignOptionsToModules(*inputrec->params, nullptr);
1133
+ // now that the MDModules know their options, they know which callbacks to sign up to
1134
+ mdModules_->subscribeToSimulationSetupNotifications();
1135
+ const auto& setupNotifier = mdModules_->notifiers().simulationSetupNotifier_;
1136
+
1137
+ // Notify MdModules of existing logger
1138
+ setupNotifier.notify(mdlog);
1139
+
1140
+ // Notify MdModules of internal parameters, saved into KVT
1141
+ if (inputrec->internalParameters != nullptr)
1142
+ {
1143
+ setupNotifier.notify(*inputrec->internalParameters);
1144
+ }
1145
+
1146
+ // Let MdModules know the .tpr filename
1147
+ {
1148
+ gmx::MdRunInputFilename mdRunInputFilename = { ftp2fn(efTPR, filenames.size(), filenames.data()) };
1149
+ setupNotifier.notify(mdRunInputFilename);
1150
+ }
1151
+
1152
+ if (fplog != nullptr)
1153
+ {
1154
+ pr_inputrec(fplog, 0, "Input Parameters", inputrec.get(), FALSE);
1155
+ fprintf(fplog, "\n");
1156
+ }
1157
+
1158
+ if (SIMMAIN(cr))
1159
+ {
1160
+ /* In rerun, set velocities to zero if present */
1161
+ if (doRerun && ((globalState->flags & enumValueToBitMask(StateEntry::V)) != 0))
1162
+ {
1163
+ // rerun does not use velocities
1164
+ GMX_LOG(mdlog.info)
1165
+ .asParagraph()
1166
+ .appendText(
1167
+ "Rerun trajectory contains velocities. Rerun does only evaluate "
1168
+ "potential energy and forces. The velocities will be ignored.");
1169
+ for (int i = 0; i < globalState->natoms; i++)
1170
+ {
1171
+ clear_rvec(globalState->v[i]);
1172
+ }
1173
+ globalState->flags &= ~enumValueToBitMask(StateEntry::V);
1174
+ }
1175
+
1176
+ /* now make sure the state is initialized and propagated */
1177
+ set_state_entries(globalState.get(), inputrec.get(), useModularSimulator);
1178
+ }
1179
+
1180
+ /* NM and TPI parallelize over force/energy calculations, not atoms,
1181
+ * so we need to initialize and broadcast the global state.
1182
+ */
1183
+ if (inputrec->eI == IntegrationAlgorithm::NM || inputrec->eI == IntegrationAlgorithm::TPI)
1184
+ {
1185
+ if (!MAIN(cr))
1186
+ {
1187
+ globalState = std::make_unique<t_state>();
1188
+ }
1189
+ broadcastStateWithoutDynamics(
1190
+ cr->mpiDefaultCommunicator, haveDDAtomOrdering(*cr), PAR(cr), globalState.get());
1191
+ }
1192
+
1193
+ /* A parallel command line option consistency check that we can
1194
+ only do after any threads have started. */
1195
+ if (!PAR(cr)
1196
+ && (domdecOptions.numCells[XX] > 1 || domdecOptions.numCells[YY] > 1
1197
+ || domdecOptions.numCells[ZZ] > 1 || domdecOptions.numPmeRanks > 0))
1198
+ {
1199
+ gmx_fatal(FARGS,
1200
+ "The -dd or -npme option request a parallel simulation, "
1201
+ #if !GMX_MPI
1202
+ "but %s was compiled without threads or MPI enabled",
1203
+ output_env_get_program_display_name(oenv));
1204
+ #elif GMX_THREAD_MPI
1205
+ "but the number of MPI-threads (option -ntmpi) is not set or is 1");
1206
+ #else
1207
+ "but %s was not started through mpirun/mpiexec or only one rank was requested "
1208
+ "through mpirun/mpiexec",
1209
+ output_env_get_program_display_name(oenv));
1210
+ #endif
1211
+ }
1212
+
1213
+ if (doRerun && (EI_ENERGY_MINIMIZATION(inputrec->eI) || IntegrationAlgorithm::NM == inputrec->eI))
1214
+ {
1215
+ gmx_fatal(FARGS,
1216
+ "The .mdp file specified an energy mininization or normal mode algorithm, and "
1217
+ "these are not compatible with mdrun -rerun");
1218
+ }
1219
+
1220
+ /* NMR restraints must be initialized before load_checkpoint,
1221
+ * since with time averaging the history is added to t_state.
1222
+ * For proper consistency check we therefore need to extend
1223
+ * t_state here.
1224
+ * So the PME-only nodes (if present) will also initialize
1225
+ * the distance restraints.
1226
+ */
1227
+
1228
+ /* This needs to be called before read_checkpoint to extend the state */
1229
+ t_disresdata* disresdata;
1230
+ snew(disresdata, 1);
1231
+ init_disres(fplog,
1232
+ mtop,
1233
+ inputrec.get(),
1234
+ DisResRunMode::MDRun,
1235
+ MAIN(cr) ? DDRole::Main : DDRole::Agent,
1236
+ PAR(cr) ? NumRanks::Multiple : NumRanks::Single,
1237
+ cr->mpi_comm_mysim,
1238
+ ms,
1239
+ disresdata,
1240
+ globalState.get(),
1241
+ replExParams.exchangeInterval > 0);
1242
+
1243
+ if (gmx_mtop_ftype_count(mtop, F_ORIRES) > 0 && isSimulationMainRank)
1244
+ {
1245
+ extendStateWithOriresHistory(mtop, *inputrec, globalState.get());
1246
+ }
1247
+
1248
+ #if GMX_FAHCORE
1249
+ /* We have to remember the generation's first step before reading checkpoint.
1250
+ This way, we can report to the F@H core both the generation's first step
1251
+ and the restored first step, thus making it able to distinguish between
1252
+ an interruption/resume and start of the n-th generation simulation.
1253
+ Having this information, the F@H core can correctly calculate and report
1254
+ the progress.
1255
+ */
1256
+ int gen_first_step = 0;
1257
+ if (MAIN(cr))
1258
+ {
1259
+ gen_first_step = inputrec->init_step;
1260
+ }
1261
+ #endif
1262
+
1263
+ ObservablesHistory observablesHistory = {};
1264
+
1265
+ auto modularSimulatorCheckpointData = std::make_unique<ReadCheckpointDataHolder>();
1266
+ if (startingBehavior != StartingBehavior::NewSimulation)
1267
+ {
1268
+ /* Check if checkpoint file exists before doing continuation.
1269
+ * This way we can use identical input options for the first and subsequent runs...
1270
+ */
1271
+ if (mdrunOptions.numStepsCommandline > -2)
1272
+ {
1273
+ /* Temporarily set the number of steps to unlimited to avoid
1274
+ * triggering the nsteps check in load_checkpoint().
1275
+ * This hack will go away soon when the -nsteps option is removed.
1276
+ */
1277
+ inputrec->nsteps = -1;
1278
+ }
1279
+
1280
+ // Finish applying initial simulation state information from external sources on all ranks.
1281
+ // Reconcile checkpoint file data with Mdrunner state established up to this point.
1282
+ applyLocalState(*inputHolder_.get(),
1283
+ logFileHandle,
1284
+ cr,
1285
+ domdecOptions.numCells,
1286
+ inputrec.get(),
1287
+ globalState.get(),
1288
+ &observablesHistory,
1289
+ mdrunOptions.reproducible,
1290
+ mdModules_->notifiers(),
1291
+ modularSimulatorCheckpointData.get(),
1292
+ useModularSimulator);
1293
+ // TODO: (#3652) Synchronize filesystem state, SimulationInput contents, and program
1294
+ // invariants
1295
+ // on all code paths.
1296
+ // Write checkpoint or provide hook to update SimulationInput.
1297
+ // If there was a checkpoint file, SimulationInput contains more information
1298
+ // than if there wasn't. At this point, we have synchronized the in-memory
1299
+ // state with the filesystem state only for restarted simulations. We should
1300
+ // be calling applyLocalState unconditionally and expect that the completeness
1301
+ // of SimulationInput is not dependent on its creation method.
1302
+
1303
+ if (startingBehavior == StartingBehavior::RestartWithAppending && logFileHandle)
1304
+ {
1305
+ // Now we can start normal logging to the truncated log file.
1306
+ fplog = gmx_fio_getfp(logFileHandle);
1307
+ prepareLogAppending(fplog);
1308
+ logOwner = buildLogger(fplog, MAIN(cr));
1309
+ mdlog = logOwner.logger();
1310
+ }
1311
+ }
1312
+
1313
+ #if GMX_FAHCORE
1314
+ if (MAIN(cr))
1315
+ {
1316
+ fcRegisterSteps(inputrec->nsteps + inputrec->init_step, gen_first_step);
1317
+ }
1318
+ #endif
1319
+
1320
+ if (mdrunOptions.numStepsCommandline > -2)
1321
+ {
1322
+ GMX_LOG(mdlog.info)
1323
+ .asParagraph()
1324
+ .appendText(
1325
+ "The -nsteps functionality is deprecated, and may be removed in a future "
1326
+ "version. "
1327
+ "Consider using gmx convert-tpr -nsteps or changing the appropriate .mdp "
1328
+ "file field.");
1329
+ }
1330
+ /* override nsteps with value set on the commandline */
1331
+ override_nsteps_cmdline(mdlog, mdrunOptions.numStepsCommandline, inputrec.get());
1332
+
1333
+ matrix box;
1334
+ if (isSimulationMainRank)
1335
+ {
1336
+ copy_mat(globalState->box, box);
1337
+ }
1338
+
1339
+ if (PAR(cr))
1340
+ {
1341
+ gmx_bcast(sizeof(box), box, cr->mpiDefaultCommunicator);
1342
+ }
1343
+
1344
+ if (inputrec->cutoff_scheme != CutoffScheme::Verlet)
1345
+ {
1346
+ gmx_fatal(FARGS,
1347
+ "This group-scheme .tpr file can no longer be run by mdrun. Please update to the "
1348
+ "Verlet scheme, or use an earlier version of GROMACS if necessary.");
1349
+ }
1350
+ /* Update rlist and nstlist. */
1351
+ /* Note: prepare_verlet_scheme is calling increaseNstlist(...), which (while attempting to
1352
+ * increase rlist) tries to check if the newly chosen value fits with the DD scheme. As this is
1353
+ * run before any DD scheme is set up, this check is never executed. See #3334 for more details.
1354
+ */
1355
+ prepare_verlet_scheme(fplog,
1356
+ cr,
1357
+ inputrec.get(),
1358
+ nstlist_cmdline,
1359
+ mtop,
1360
+ MAIN(cr) ? globalState->x : gmx::ArrayRef<const gmx::RVec>(),
1361
+ box,
1362
+ useGpuForNonbonded || (emulateGpuNonbonded == EmulateGpuNonbonded::Yes),
1363
+ *hwinfo_->cpuInfo);
1364
+
1365
+ // We need to decide on update groups early, as this affects
1366
+ // inter-domain communication distances.
1367
+ auto updateGroupingsPerMoleculeTypeResult = makeUpdateGroupingsPerMoleculeType(mtop);
1368
+ UpdateGroups updateGroups;
1369
+ if (std::holds_alternative<std::string>(updateGroupingsPerMoleculeTypeResult))
1370
+ {
1371
+ GMX_LOG(mdlog.warning)
1372
+ .asParagraph()
1373
+ .appendTextFormatted("Update groups can not be used for this system because %s",
1374
+ std::get<std::string>(updateGroupingsPerMoleculeTypeResult).c_str());
1375
+ }
1376
+ else
1377
+ {
1378
+ auto updateGroupingsPerMoleculeType =
1379
+ std::get<std::vector<RangePartitioning>>(updateGroupingsPerMoleculeTypeResult);
1380
+ const real maxUpdateGroupRadius = computeMaxUpdateGroupRadius(
1381
+ mtop, updateGroupingsPerMoleculeType, maxReferenceTemperature(*inputrec));
1382
+ const real cutoffMargin = std::sqrt(max_cutoff2(inputrec->pbcType, box)) - inputrec->rlist;
1383
+ updateGroups = makeUpdateGroups(mdlog,
1384
+ std::move(updateGroupingsPerMoleculeType),
1385
+ maxUpdateGroupRadius,
1386
+ doRerun,
1387
+ useDomainDecomposition,
1388
+ systemHasConstraintsOrVsites(mtop),
1389
+ cutoffMargin);
1390
+ }
1391
+
1392
+ try
1393
+ {
1394
+ const bool haveFrozenAtoms = inputrecFrozenAtoms(inputrec.get());
1395
+ /* PLUMED */
1396
+ bool usePlumed = 0;
1397
+ if(plumedswitch) usePlumed = 1;
1398
+ /* END PLUMED */
1399
+ useGpuForUpdate = decideWhetherToUseGpuForUpdate(useDomainDecomposition,
1400
+ updateGroups.useUpdateGroups(),
1401
+ pmeRunMode,
1402
+ domdecOptions.numPmeRanks > 0,
1403
+ useGpuForNonbonded,
1404
+ updateTarget,
1405
+ gpusWereDetected,
1406
+ *inputrec,
1407
+ mtop,
1408
+ doEssentialDynamics,
1409
+ gmx_mtop_ftype_count(mtop, F_ORIRES) > 0,
1410
+ haveFrozenAtoms,
1411
+ useModularSimulator,
1412
+ doRerun,
1413
+ usePlumed, /* PLUMED */
1414
+ mdlog);
1415
+ }
1416
+ GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
1417
+
1418
+ const bool canUseDirectGpuComm = decideWhetherDirectGpuCommunicationCanBeUsed(
1419
+ devFlags, inputrec->useMts, (inputrec->eSwapCoords != SwapType::No), mdlog);
1420
+
1421
+ bool useGpuDirectHalo = false;
1422
+
1423
+ if (useGpuForNonbonded)
1424
+ {
1425
+ // cr->npmenodes is not yet initialized.
1426
+ // domdecOptions.numPmeRanks == -1 results in 0 separate PME ranks when useGpuForNonbonded is true.
1427
+ // Todo: remove this assumption later once auto mode has support for separate PME rank
1428
+ const int numPmeRanks = domdecOptions.numPmeRanks > 0 ? domdecOptions.numPmeRanks : 0;
1429
+ bool havePPDomainDecomposition = (cr->sizeOfDefaultCommunicator - numPmeRanks) > 1;
1430
+ useGpuDirectHalo = decideWhetherToUseGpuForHalo(havePPDomainDecomposition,
1431
+ useGpuForNonbonded,
1432
+ canUseDirectGpuComm,
1433
+ useModularSimulator,
1434
+ doRerun,
1435
+ EI_ENERGY_MINIMIZATION(inputrec->eI),
1436
+ mdlog);
1437
+ }
1438
+
1439
+ // This builder is necessary while we have multi-part construction
1440
+ // of DD. Before DD is constructed, we use the existence of
1441
+ // the builder object to indicate that further construction of DD
1442
+ // is needed.
1443
+ std::unique_ptr<DomainDecompositionBuilder> ddBuilder;
1444
+ if (useDomainDecomposition)
1445
+ {
1446
+ // The DD builder will disable useGpuDirectHalo if the Y or Z component of any domain is
1447
+ // smaller than twice the communication distance, since GPU-direct communication presently
1448
+ // only works with a single pulse in these dimensions, and we want to avoid box scaling
1449
+ // resulting in fatal errors far into the simulation. Such small systems will not
1450
+ // perform well on multiple GPUs in any case, but it is important that our core functionality
1451
+ // (in particular for testing) does not break depending on GPU direct communication being enabled.
1452
+ ddBuilder = std::make_unique<DomainDecompositionBuilder>(
1453
+ mdlog,
1454
+ cr,
1455
+ domdecOptions,
1456
+ mdrunOptions,
1457
+ mtop,
1458
+ *inputrec,
1459
+ mdModules_->notifiers(),
1460
+ box,
1461
+ updateGroups.updateGroupingPerMoleculeType(),
1462
+ updateGroups.useUpdateGroups(),
1463
+ updateGroups.maxUpdateGroupRadius(),
1464
+ positionsFromStatePointer(globalState.get()),
1465
+ useGpuForNonbonded,
1466
+ useGpuForPme,
1467
+ useGpuForUpdate,
1468
+ useGpuDirectHalo,
1469
+ devFlags.enableGpuPmeDecomposition);
1470
+ }
1471
+ else
1472
+ {
1473
+ /* PME, if used, is done on all nodes with 1D decomposition */
1474
+ cr->mpi_comm_mygroup = cr->mpiDefaultCommunicator;
1475
+ cr->mpi_comm_mysim = cr->mpiDefaultCommunicator;
1476
+
1477
+ cr->nnodes = cr->sizeOfDefaultCommunicator;
1478
+ cr->sim_nodeid = cr->rankInDefaultCommunicator;
1479
+ cr->nodeid = cr->rankInDefaultCommunicator;
1480
+ cr->npmenodes = 0;
1481
+ cr->duty = (DUTY_PP | DUTY_PME);
1482
+
1483
+ if (inputrec->pbcType == PbcType::Screw)
1484
+ {
1485
+ gmx_fatal(FARGS, "pbc=screw is only implemented with domain decomposition");
1486
+ }
1487
+ }
1488
+
1489
+ // Produce the task assignment for all ranks on this node - done after DD is constructed
1490
+ GpuTaskAssignments gpuTaskAssignments = GpuTaskAssignmentsBuilder::build(
1491
+ availableDevices,
1492
+ userGpuTaskAssignment,
1493
+ *hwinfo_,
1494
+ simulationCommunicator,
1495
+ physicalNodeComm,
1496
+ nonbondedTarget,
1497
+ pmeTarget,
1498
+ bondedTarget,
1499
+ updateTarget,
1500
+ useGpuForNonbonded,
1501
+ useGpuForPme,
1502
+ thisRankHasDuty(cr, DUTY_PP),
1503
+ // TODO cr->duty & DUTY_PME should imply that a PME
1504
+ // algorithm is active, but currently does not.
1505
+ usingPme(inputrec->coulombtype) && thisRankHasDuty(cr, DUTY_PME));
1506
+
1507
+ // Get the device handle for the modules on this rank, nullptr
1508
+ // when no task is assigned.
1509
+ int deviceId = -1;
1510
+ DeviceInformation* deviceInfo = gpuTaskAssignments.initDevice(&deviceId);
1511
+
1512
+ // TODO Currently this is always built, yet DD partition code
1513
+ // checks if it is built before using it. Probably it should
1514
+ // become an MDModule that is made only when another module
1515
+ // requires it (e.g. pull, CompEl, density fitting), so that we
1516
+ // don't update the local atom sets unilaterally every step.
1517
+ LocalAtomSetManager atomSets;
1518
+
1519
+ // Local state and topology are declared (and perhaps constructed)
1520
+ // now, because DD needs them for the LocalTopologyChecker, but
1521
+ // they do not contain valid data until after the first DD
1522
+ // partition.
1523
+ std::unique_ptr<t_state> localStateInstance;
1524
+ t_state* localState;
1525
+ gmx_localtop_t localTopology(mtop.ffparams);
1526
+
1527
+ if (ddBuilder)
1528
+ {
1529
+ localStateInstance = std::make_unique<t_state>();
1530
+ localState = localStateInstance.get();
1531
+ // TODO Pass the GPU streams to ddBuilder to use in buffer
1532
+ // transfers (e.g. halo exchange)
1533
+ cr->setDD(ddBuilder->build(&atomSets, localTopology, *localState, &observablesReducerBuilder));
1534
+ // The builder's job is done, so destruct it
1535
+ ddBuilder.reset(nullptr);
1536
+ // Note that local state still does not exist yet.
1537
+ }
1538
+ else
1539
+ {
1540
+ // Without DD, the local state is merely an alias to the global state,
1541
+ // so we don't need to allocate anything.
1542
+ localState = globalState.get();
1543
+ }
1544
+
1545
+ // Ensure that all atoms within the same update group are in the
1546
+ // same periodic image. Otherwise, a simulation that did not use
1547
+ // update groups (e.g. a single-rank simulation) cannot always be
1548
+ // correctly restarted in a way that does use update groups
1549
+ // (e.g. a multi-rank simulation).
1550
+ if (isSimulationMainRank)
1551
+ {
1552
+ const bool useUpdateGroups = cr->dd ? ddUsesUpdateGroups(*cr->dd) : false;
1553
+ if (useUpdateGroups)
1554
+ {
1555
+ putUpdateGroupAtomsInSamePeriodicImage(*cr->dd, mtop, globalState->box, globalState->x);
1556
+ }
1557
+ }
1558
+
1559
+ const bool disableNonbondedCalculation = (getenv("GMX_NO_NONBONDED") != nullptr);
1560
+ if (disableNonbondedCalculation)
1561
+ {
1562
+ /* turn off non-bonded calculations */
1563
+ GMX_LOG(mdlog.warning)
1564
+ .asParagraph()
1565
+ .appendText(
1566
+ "Found environment variable GMX_NO_NONBONDED.\n"
1567
+ "Disabling nonbonded calculations.");
1568
+ }
1569
+
1570
+ const NumPmeDomains numPmeDomains = getNumPmeDomains(cr->dd);
1571
+ const bool useGpuPmeDecomposition = numPmeDomains.x * numPmeDomains.y > 1 && useGpuForPme;
1572
+ GMX_RELEASE_ASSERT(!useGpuPmeDecomposition || devFlags.enableGpuPmeDecomposition,
1573
+ "GPU PME decomposition works only in the cases where it is supported");
1574
+
1575
+ MdrunScheduleWorkload runScheduleWork;
1576
+
1577
+ // Also populates the simulation constant workload description.
1578
+ // Note: currently the default duty is DUTY_PP | DUTY_PME for all simulations, including those without PME,
1579
+ // so this boolean is sufficient on all ranks to determine whether separate PME ranks are used,
1580
+ // but this will no longer be the case if cr->duty is changed for !usingPme(fr->ic->eeltype).
1581
+ const bool haveSeparatePmeRank = (!thisRankHasDuty(cr, DUTY_PP) || !thisRankHasDuty(cr, DUTY_PME));
1582
+ runScheduleWork.simulationWork = createSimulationWorkload(*inputrec,
1583
+ disableNonbondedCalculation,
1584
+ devFlags,
1585
+ havePPDomainDecomposition(cr),
1586
+ haveSeparatePmeRank,
1587
+ useGpuForNonbonded,
1588
+ pmeRunMode,
1589
+ useGpuForBonded,
1590
+ useGpuForUpdate,
1591
+ useGpuDirectHalo,
1592
+ canUseDirectGpuComm,
1593
+ useGpuPmeDecomposition);
1594
+
1595
+ if (runScheduleWork.simulationWork.useGpuDirectCommunication && GMX_GPU_CUDA)
1596
+ {
1597
+ // Don't enable event counting with GPU Direct comm, see #3988.
1598
+ gmx::internal::disableCudaEventConsumptionCounting();
1599
+ }
1600
+
1601
+ if (isSimulationMainRank && GMX_GPU_SYCL)
1602
+ {
1603
+ const SimulationWorkload& simWorkload = runScheduleWork.simulationWork;
1604
+ bool haveAnyGpuWork = simWorkload.useGpuPme || simWorkload.useGpuBonded
1605
+ || simWorkload.useGpuNonbonded || simWorkload.useGpuUpdate;
1606
+ if (haveAnyGpuWork)
1607
+ {
1608
+ GMX_LOG(mdlog.info)
1609
+ .asParagraph()
1610
+ .appendText(
1611
+ "\nNOTE: SYCL GPU support in GROMACS, and the compilers, libraries,\n"
1612
+ "and drivers that it depends on are fairly new.\n"
1613
+ "Please, pay extra attention to the correctness of your results,\n"
1614
+ "and update to the latest GROMACS patch version if warranted.");
1615
+ }
1616
+ }
1617
+
1618
+ const bool printHostName = (cr->nnodes > 1);
1619
+ gpuTaskAssignments.reportGpuUsage(mdlog, printHostName, pmeRunMode, runScheduleWork.simulationWork);
1620
+
1621
+ std::unique_ptr<DeviceStreamManager> deviceStreamManager = nullptr;
1622
+
1623
+ if (deviceInfo != nullptr)
1624
+ {
1625
+ if (runScheduleWork.simulationWork.havePpDomainDecomposition && thisRankHasDuty(cr, DUTY_PP))
1626
+ {
1627
+ dd_setup_dlb_resource_sharing(cr, deviceId);
1628
+ }
1629
+ const bool useGpuTiming = decideGpuTimingsUsage();
1630
+ deviceStreamManager = std::make_unique<DeviceStreamManager>(
1631
+ *deviceInfo, runScheduleWork.simulationWork, useGpuTiming);
1632
+ }
1633
+
1634
+ // If the user chose a task assignment, give them some hints
1635
+ // where appropriate.
1636
+ if (!userGpuTaskAssignment.empty())
1637
+ {
1638
+ gpuTaskAssignments.logPerformanceHints(mdlog, numAvailableDevices);
1639
+ }
1640
+
1641
+ if (PAR(cr))
1642
+ {
1643
+ /* After possible communicator splitting in make_dd_communicators.
1644
+ * we can set up the intra/inter node communication.
1645
+ */
1646
+ gmx_setup_nodecomm(fplog, cr);
1647
+ }
1648
+
1649
+ #if GMX_MPI
1650
+ if (isMultiSim(ms))
1651
+ {
1652
+ GMX_LOG(mdlog.warning)
1653
+ .asParagraph()
1654
+ .appendTextFormatted(
1655
+ "This is simulation %d out of %d running as a composite GROMACS\n"
1656
+ "multi-simulation job. Setup for this simulation:\n",
1657
+ ms->simulationIndex_,
1658
+ ms->numSimulations_);
1659
+ }
1660
+ GMX_LOG(mdlog.warning)
1661
+ .appendTextFormatted("Using %d MPI %s\n",
1662
+ cr->nnodes,
1663
+ # if GMX_THREAD_MPI
1664
+ cr->nnodes == 1 ? "thread" : "threads"
1665
+ # else
1666
+ cr->nnodes == 1 ? "process" : "processes"
1667
+ # endif
1668
+ );
1669
+ fflush(stderr);
1670
+ #endif
1671
+
1672
+ // If mdrun -pin auto honors any affinity setting that already
1673
+ // exists. If so, it is nice to provide feedback about whether
1674
+ // that existing affinity setting was from OpenMP or something
1675
+ // else, so we run this code both before and after we initialize
1676
+ // the OpenMP support.
1677
+ gmx_check_thread_affinity_set(
1678
+ mdlog, &hw_opt, hwinfo_->hardwareTopology->maxThreads(), FALSE, libraryWorldCommunicator);
1679
+ /* Check and update the number of OpenMP threads requested */
1680
+ checkAndUpdateRequestedNumOpenmpThreads(
1681
+ &hw_opt, *hwinfo_, cr, ms, physicalNodeComm.size_, pmeRunMode, mtop, *inputrec);
1682
+
1683
+ gmx_omp_nthreads_init(mdlog,
1684
+ cr,
1685
+ hwinfo_->hardwareTopology->maxThreads(),
1686
+ physicalNodeComm.size_,
1687
+ hw_opt.nthreads_omp,
1688
+ hw_opt.nthreads_omp_pme,
1689
+ !thisRankHasDuty(cr, DUTY_PP));
1690
+
1691
+ const bool bEnableFPE = gmxShouldEnableFPExceptions();
1692
+ // FIXME - reconcile with gmx_feenableexcept() call from CommandLineModuleManager::run()
1693
+ if (bEnableFPE)
1694
+ {
1695
+ gmx_feenableexcept();
1696
+ }
1697
+
1698
+ /* Now that we know the setup is consistent, check for efficiency */
1699
+ check_resource_division_efficiency(hwinfo_, gpuTaskAssignments.thisRankHasAnyGpuTask(), cr, mdlog);
1700
+
1701
+ /* getting number of PP/PME threads on this MPI / tMPI rank.
1702
+ PME: env variable should be read only on one node to make sure it is
1703
+ identical everywhere;
1704
+ */
1705
+ const int numThreadsOnThisRank = thisRankHasDuty(cr, DUTY_PP)
1706
+ ? gmx_omp_nthreads_get(ModuleMultiThread::Nonbonded)
1707
+ : gmx_omp_nthreads_get(ModuleMultiThread::Pme);
1708
+ checkHardwareOversubscription(
1709
+ numThreadsOnThisRank, cr->nodeid, *hwinfo_->hardwareTopology, physicalNodeComm, mdlog);
1710
+
1711
+ // Enable Peer access between GPUs where available
1712
+ // Only for DD, only main PP rank needs to perform setup, and only if thread MPI plus
1713
+ // any of the GPU communication features are active.
1714
+ if (haveDDAtomOrdering(*cr) && MAIN(cr) && thisRankHasDuty(cr, DUTY_PP) && GMX_THREAD_MPI
1715
+ && (runScheduleWork.simulationWork.useGpuHaloExchange
1716
+ || runScheduleWork.simulationWork.useGpuPmePpCommunication))
1717
+ {
1718
+ setupGpuDevicePeerAccess(gpuTaskAssignments.deviceIdsAssigned(), mdlog);
1719
+ }
1720
+
1721
+ if (mdrunOptions.timingOptions.resetStep > -1)
1722
+ {
1723
+ GMX_LOG(mdlog.info)
1724
+ .asParagraph()
1725
+ .appendText(
1726
+ "The -resetstep functionality is deprecated, and may be removed in a "
1727
+ "future version.");
1728
+ }
1729
+ std::unique_ptr<gmx_wallcycle> wcycle =
1730
+ wallcycle_init(fplog, mdrunOptions.timingOptions.resetStep, cr);
1731
+
1732
+ if (PAR(cr))
1733
+ {
1734
+ /* Main synchronizes its value of reset_counters with all nodes
1735
+ * including PME only nodes */
1736
+ int64_t reset_counters = wcycle_get_reset_counters(wcycle.get());
1737
+ gmx_bcast(sizeof(reset_counters), &reset_counters, cr->mpi_comm_mysim);
1738
+ wcycle_set_reset_counters(wcycle.get(), reset_counters);
1739
+ }
1740
+
1741
+ // Membrane embedding must be initialized before we call init_forcerec()
1742
+ membedHolder.initializeMembed(fplog,
1743
+ filenames.size(),
1744
+ filenames.data(),
1745
+ &mtop,
1746
+ inputrec.get(),
1747
+ globalState.get(),
1748
+ cr,
1749
+ &mdrunOptions.checkpointOptions.period);
1750
+
1751
+ const bool thisRankHasPmeGpuTask = gpuTaskAssignments.thisRankHasPmeGpuTask();
1752
+ std::unique_ptr<BoxDeformation> deform;
1753
+ std::unique_ptr<MDAtoms> mdAtoms;
1754
+ std::unique_ptr<VirtualSitesHandler> vsite;
1755
+
1756
+ t_nrnb nrnb;
1757
+ if (thisRankHasDuty(cr, DUTY_PP))
1758
+ {
1759
+ setupNotifier.notify(*cr);
1760
+ setupNotifier.notify(&atomSets);
1761
+ setupNotifier.notify(mtop);
1762
+ setupNotifier.notify(inputrec->pbcType);
1763
+ setupNotifier.notify(SimulationTimeStep{ inputrec->delta_t });
1764
+ /* Initiate forcerecord */
1765
+ fr = std::make_unique<t_forcerec>();
1766
+ fr->forceProviders = mdModules_->initForceProviders();
1767
+ init_forcerec(fplog,
1768
+ mdlog,
1769
+ runScheduleWork.simulationWork,
1770
+ fr.get(),
1771
+ *inputrec,
1772
+ mtop,
1773
+ cr,
1774
+ box,
1775
+ opt2fn("-table", filenames.size(), filenames.data()),
1776
+ opt2fn("-tablep", filenames.size(), filenames.data()),
1777
+ opt2fns("-tableb", filenames.size(), filenames.data()),
1778
+ pforce);
1779
+ // Dirty hack, for fixing disres and orires should be made mdmodules
1780
+ fr->fcdata->disres = disresdata;
1781
+ if (gmx_mtop_ftype_count(mtop, F_ORIRES) > 0)
1782
+ {
1783
+ fr->fcdata->orires = std::make_unique<t_oriresdata>(
1784
+ fplog, mtop, *inputrec, ms, globalState.get(), &atomSets);
1785
+ }
1786
+
1787
+ deform = buildBoxDeformation(globalState != nullptr
1788
+ ? createMatrix3x3FromLegacyMatrix(globalState->box)
1789
+ : diagonalMatrix<real, 3, 3>(0.0),
1790
+ MAIN(cr) ? DDRole::Main : DDRole::Agent,
1791
+ PAR(cr) ? NumRanks::Multiple : NumRanks::Single,
1792
+ cr->mpi_comm_mygroup,
1793
+ *inputrec);
1794
+
1795
+ // Save a handle to device stream manager to use elsewhere in the code
1796
+ // TODO: Forcerec is not a correct place to store it.
1797
+ fr->deviceStreamManager = deviceStreamManager.get();
1798
+
1799
+ if (runScheduleWork.simulationWork.useGpuPmePpCommunication && !thisRankHasDuty(cr, DUTY_PME))
1800
+ {
1801
+ GMX_RELEASE_ASSERT(
1802
+ deviceStreamManager != nullptr,
1803
+ "GPU device stream manager should be valid in order to use PME-PP direct "
1804
+ "communications.");
1805
+ GMX_RELEASE_ASSERT(
1806
+ deviceStreamManager->streamIsValid(DeviceStreamType::PmePpTransfer),
1807
+ "GPU PP-PME stream should be valid in order to use GPU PME-PP direct "
1808
+ "communications.");
1809
+ fr->pmePpCommGpu = std::make_unique<gmx::PmePpCommGpu>(
1810
+ cr->mpi_comm_mysim,
1811
+ cr->dd->pme_nodeid,
1812
+ &cr->dd->pmeForceReceiveBuffer,
1813
+ deviceStreamManager->context(),
1814
+ deviceStreamManager->stream(DeviceStreamType::PmePpTransfer));
1815
+ }
1816
+
1817
+ fr->nbv = Nbnxm::init_nb_verlet(
1818
+ mdlog,
1819
+ *inputrec,
1820
+ *fr,
1821
+ cr,
1822
+ *hwinfo_,
1823
+ runScheduleWork.simulationWork.useGpuNonbonded,
1824
+ deviceStreamManager.get(),
1825
+ mtop,
1826
+ PAR(cr) ? &observablesReducerBuilder : nullptr,
1827
+ isSimulationMainRank ? globalState->x : gmx::ArrayRef<const gmx::RVec>(),
1828
+ box,
1829
+ wcycle.get());
1830
+ // TODO: Move the logic below to a GPU bonded builder
1831
+ if (runScheduleWork.simulationWork.useGpuBonded)
1832
+ {
1833
+ GMX_RELEASE_ASSERT(deviceStreamManager != nullptr,
1834
+ "GPU device stream manager should be valid in order to use GPU "
1835
+ "version of bonded forces.");
1836
+ fr->listedForcesGpu = std::make_unique<ListedForcesGpu>(mtop.ffparams,
1837
+ fr->ic->epsfac * fr->fudgeQQ,
1838
+ *deviceInfo,
1839
+ deviceStreamManager->context(),
1840
+ deviceStreamManager->bondedStream(),
1841
+ wcycle.get());
1842
+ }
1843
+ fr->longRangeNonbondeds = std::make_unique<CpuPpLongRangeNonbondeds>(fr->n_tpi,
1844
+ fr->ic->ewaldcoeff_q,
1845
+ fr->ic->epsilon_r,
1846
+ fr->qsum,
1847
+ fr->ic->eeltype,
1848
+ fr->ic->vdwtype,
1849
+ *inputrec,
1850
+ &nrnb,
1851
+ wcycle.get(),
1852
+ fplog);
1853
+
1854
+ /* Initialize the mdAtoms structure.
1855
+ * mdAtoms is not filled with atom data,
1856
+ * as this can not be done now with domain decomposition.
1857
+ */
1858
+ mdAtoms = makeMDAtoms(fplog, mtop, *inputrec, thisRankHasPmeGpuTask);
1859
+ if (globalState && thisRankHasPmeGpuTask)
1860
+ {
1861
+ // The pinning of coordinates in the global state object works, because we only use
1862
+ // PME on GPU without DD or on a separate PME rank, and because the local state pointer
1863
+ // points to the global state object without DD.
1864
+ // FIXME: MD and EM separately set up the local state - this should happen in the same
1865
+ // function, which should also perform the pinning.
1866
+ changePinningPolicy(&globalState->x, pme_get_pinning_policy());
1867
+ }
1868
+
1869
+ /* Initialize the virtual site communication */
1870
+ vsite = makeVirtualSitesHandler(
1871
+ mtop, cr, fr->pbcType, updateGroups.updateGroupingPerMoleculeType());
1872
+
1873
+ calc_shifts(box, fr->shift_vec);
1874
+
1875
+ /* With periodic molecules the charge groups should be whole at start up
1876
+ * and the virtual sites should not be far from their proper positions.
1877
+ */
1878
+ if (!inputrec->bContinuation && MAIN(cr)
1879
+ && !(inputrec->pbcType != PbcType::No && inputrec->bPeriodicMols))
1880
+ {
1881
+ /* Make molecules whole at start of run */
1882
+ if (fr->pbcType != PbcType::No)
1883
+ {
1884
+ do_pbc_first_mtop(fplog, inputrec->pbcType, box, &mtop, globalState->x.rvec_array());
1885
+ }
1886
+ if (vsite)
1887
+ {
1888
+ /* Correct initial vsite positions are required
1889
+ * for the initial distribution in the domain decomposition
1890
+ * and for the initial shell prediction.
1891
+ */
1892
+ constructVirtualSitesGlobal(mtop, globalState->x);
1893
+ }
1894
+ }
1895
+ // Make the DD reverse topology, now that any vsites that are present are available
1896
+ if (haveDDAtomOrdering(*cr))
1897
+ {
1898
+ dd_make_reverse_top(fplog, cr->dd, mtop, vsite.get(), *inputrec, domdecOptions.ddBondedChecking);
1899
+ }
1900
+
1901
+ if (usingPme(fr->ic->eeltype) || usingLJPme(fr->ic->vdwtype))
1902
+ {
1903
+ ewaldcoeff_q = fr->ic->ewaldcoeff_q;
1904
+ ewaldcoeff_lj = fr->ic->ewaldcoeff_lj;
1905
+ }
1906
+ }
1907
+ else
1908
+ {
1909
+ /* This is a PME only node */
1910
+
1911
+ GMX_ASSERT(globalState == nullptr,
1912
+ "We don't need the state on a PME only rank and expect it to be unitialized");
1913
+
1914
+ ewaldcoeff_q = calc_ewaldcoeff_q(inputrec->rcoulomb, inputrec->ewald_rtol);
1915
+ ewaldcoeff_lj = calc_ewaldcoeff_lj(inputrec->rvdw, inputrec->ewald_rtol_lj);
1916
+ }
1917
+
1918
+ gmx_pme_t* sepPmeData = nullptr;
1919
+ // This reference hides the fact that PME data is owned by runner on PME-only ranks and by forcerec on other ranks
1920
+ GMX_ASSERT(thisRankHasDuty(cr, DUTY_PP) == (fr != nullptr),
1921
+ "Double-checking that only PME-only ranks have no forcerec");
1922
+ gmx_pme_t*& pmedata = fr ? fr->pmedata : sepPmeData;
1923
+
1924
+ // TODO should live in ewald module once its testing is improved
1925
+ //
1926
+ // Later, this program could contain kernels that might be later
1927
+ // re-used as auto-tuning progresses, or subsequent simulations
1928
+ // are invoked.
1929
+ PmeGpuProgramStorage pmeGpuProgram;
1930
+ if (thisRankHasPmeGpuTask)
1931
+ {
1932
+ GMX_RELEASE_ASSERT(
1933
+ (deviceStreamManager != nullptr),
1934
+ "GPU device stream manager should be initialized in order to use GPU for PME.");
1935
+ GMX_RELEASE_ASSERT((deviceInfo != nullptr),
1936
+ "GPU device should be initialized in order to use GPU for PME.");
1937
+ pmeGpuProgram = buildPmeGpuProgram(deviceStreamManager->context());
1938
+ }
1939
+
1940
+ /* Initiate PME if necessary,
1941
+ * either on all nodes or on dedicated PME nodes only. */
1942
+ if (usingPme(inputrec->coulombtype) || usingLJPme(inputrec->vdwtype))
1943
+ {
1944
+ if (mdAtoms && mdAtoms->mdatoms())
1945
+ {
1946
+ nChargePerturbed = mdAtoms->mdatoms()->nChargePerturbed;
1947
+ if (usingLJPme(inputrec->vdwtype))
1948
+ {
1949
+ nTypePerturbed = mdAtoms->mdatoms()->nTypePerturbed;
1950
+ }
1951
+ }
1952
+ if (cr->npmenodes > 0)
1953
+ {
1954
+ /* The PME only nodes need to know nChargePerturbed(FEP on Q) and nTypePerturbed(FEP on LJ)*/
1955
+ gmx_bcast(sizeof(nChargePerturbed), &nChargePerturbed, cr->mpi_comm_mysim);
1956
+ gmx_bcast(sizeof(nTypePerturbed), &nTypePerturbed, cr->mpi_comm_mysim);
1957
+ }
1958
+
1959
+ if (thisRankHasDuty(cr, DUTY_PME))
1960
+ {
1961
+ try
1962
+ {
1963
+ // TODO: This should be in the builder.
1964
+ GMX_RELEASE_ASSERT(!runScheduleWork.simulationWork.useGpuPme
1965
+ || (deviceStreamManager != nullptr),
1966
+ "Device stream manager should be valid in order to use GPU "
1967
+ "version of PME.");
1968
+ GMX_RELEASE_ASSERT(
1969
+ !runScheduleWork.simulationWork.useGpuPme
1970
+ || deviceStreamManager->streamIsValid(DeviceStreamType::Pme),
1971
+ "GPU PME stream should be valid in order to use GPU version of PME.");
1972
+
1973
+ const DeviceContext* deviceContext = runScheduleWork.simulationWork.useGpuPme
1974
+ ? &deviceStreamManager->context()
1975
+ : nullptr;
1976
+ const DeviceStream* pmeStream =
1977
+ runScheduleWork.simulationWork.useGpuPme
1978
+ ? &deviceStreamManager->stream(DeviceStreamType::Pme)
1979
+ : nullptr;
1980
+
1981
+ const t_inputrec* ir = inputrec.get();
1982
+ /* For each atom we allow a relative (cut-off) error of up to ewald_rtol.
1983
+ * Thus we can also tolerate an error of an order of magnitude less due to
1984
+ * atoms being slightly outside the halo extent. This will only cause a fraction
1985
+ * of the charge to be missing on the grid. So we pass ewald_rtol as the allowed
1986
+ * chance per atom (ChanceTarget::Atom) to be outside the halo extent.
1987
+ */
1988
+ const real haloExtentForAtomDisplacement =
1989
+ updateGroups.maxUpdateGroupRadius()
1990
+ + minCellSizeForAtomDisplacement(mtop,
1991
+ *ir,
1992
+ updateGroups.updateGroupingPerMoleculeType(),
1993
+ ir->ewald_rtol,
1994
+ ChanceTarget::Atom);
1995
+ pmedata = gmx_pme_init(cr,
1996
+ getNumPmeDomains(cr->dd),
1997
+ ir,
1998
+ box,
1999
+ haloExtentForAtomDisplacement,
2000
+ nChargePerturbed != 0,
2001
+ nTypePerturbed != 0,
2002
+ mdrunOptions.reproducible,
2003
+ ewaldcoeff_q,
2004
+ ewaldcoeff_lj,
2005
+ gmx_omp_nthreads_get(ModuleMultiThread::Pme),
2006
+ pmeRunMode,
2007
+ nullptr,
2008
+ deviceContext,
2009
+ pmeStream,
2010
+ pmeGpuProgram.get(),
2011
+ mdlog);
2012
+ }
2013
+ GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
2014
+ }
2015
+ }
2016
+
2017
+ /* Set thread affinity after gmx_pme_init(), otherwise with cuFFTMp the NVSHMEM helper thread
2018
+ * can be pinned to the same core as the PME thread, causing performance degradation.
2019
+ */
2020
+ if (hw_opt.threadAffinity != ThreadAffinity::Off)
2021
+ {
2022
+ /* Before setting affinity, check whether the affinity has changed
2023
+ * - which indicates that probably the OpenMP library has changed it
2024
+ * since we first checked).
2025
+ */
2026
+ gmx_check_thread_affinity_set(
2027
+ mdlog, &hw_opt, hwinfo_->hardwareTopology->maxThreads(), TRUE, libraryWorldCommunicator);
2028
+
2029
+ int numThreadsOnThisNode, intraNodeThreadOffset;
2030
+ analyzeThreadsOnThisNode(
2031
+ physicalNodeComm, numThreadsOnThisRank, &numThreadsOnThisNode, &intraNodeThreadOffset);
2032
+
2033
+ /* Set the CPU affinity */
2034
+ gmx_set_thread_affinity(mdlog,
2035
+ cr,
2036
+ &hw_opt,
2037
+ *hwinfo_->hardwareTopology,
2038
+ numThreadsOnThisRank,
2039
+ numThreadsOnThisNode,
2040
+ intraNodeThreadOffset,
2041
+ nullptr);
2042
+ }
2043
+
2044
+ if (EI_DYNAMICS(inputrec->eI))
2045
+ {
2046
+ /* Turn on signal handling on all nodes */
2047
+ /*
2048
+ * (A user signal from the PME nodes (if any)
2049
+ * is communicated to the PP nodes.
2050
+ */
2051
+ signal_handler_install();
2052
+ }
2053
+
2054
+ pull_t* pull_work = nullptr;
2055
+ if (thisRankHasDuty(cr, DUTY_PP))
2056
+ {
2057
+ /* Assumes uniform use of the number of OpenMP threads */
2058
+ walltime_accounting = walltime_accounting_init(gmx_omp_nthreads_get(ModuleMultiThread::Default));
2059
+
2060
+ if (inputrec->bPull)
2061
+ {
2062
+ /* Initialize pull code */
2063
+ pull_work = init_pull(fplog,
2064
+ inputrec->pull.get(),
2065
+ inputrec.get(),
2066
+ mtop,
2067
+ cr,
2068
+ &atomSets,
2069
+ inputrec->fepvals->init_lambda);
2070
+ if (inputrec->pull->bXOutAverage || inputrec->pull->bFOutAverage)
2071
+ {
2072
+ initPullHistory(pull_work, &observablesHistory);
2073
+ }
2074
+ if (EI_DYNAMICS(inputrec->eI) && MAIN(cr))
2075
+ {
2076
+ init_pull_output_files(pull_work, filenames.size(), filenames.data(), oenv, startingBehavior);
2077
+ }
2078
+ }
2079
+
2080
+ std::unique_ptr<EnforcedRotation> enforcedRotation;
2081
+ if (inputrec->bRot)
2082
+ {
2083
+ /* Initialize enforced rotation code */
2084
+ enforcedRotation = init_rot(fplog,
2085
+ inputrec.get(),
2086
+ filenames.size(),
2087
+ filenames.data(),
2088
+ cr,
2089
+ &atomSets,
2090
+ globalState.get(),
2091
+ mtop,
2092
+ oenv,
2093
+ mdrunOptions,
2094
+ startingBehavior);
2095
+ }
2096
+
2097
+ t_swap* swap = nullptr;
2098
+ if (inputrec->eSwapCoords != SwapType::No)
2099
+ {
2100
+ /* Initialize ion swapping code */
2101
+ swap = init_swapcoords(fplog,
2102
+ inputrec.get(),
2103
+ opt2fn_main("-swap", filenames.size(), filenames.data(), cr),
2104
+ mtop,
2105
+ globalState.get(),
2106
+ &observablesHistory,
2107
+ cr,
2108
+ &atomSets,
2109
+ oenv,
2110
+ mdrunOptions,
2111
+ startingBehavior);
2112
+ }
2113
+
2114
+ /* Let makeConstraints know whether we have essential dynamics constraints. */
2115
+ auto constr = makeConstraints(mtop,
2116
+ *inputrec,
2117
+ pull_work,
2118
+ pull_work != nullptr ? pull_have_constraint(*pull_work) : false,
2119
+ doEssentialDynamics,
2120
+ fplog,
2121
+ cr,
2122
+ updateGroups.useUpdateGroups(),
2123
+ ms,
2124
+ &nrnb,
2125
+ wcycle.get(),
2126
+ fr->bMolPBC,
2127
+ PAR(cr) ? &observablesReducerBuilder : nullptr);
2128
+
2129
+ /* Energy terms and groups */
2130
+ gmx_enerdata_t enerd(mtop.groups.groups[SimulationAtomGroupType::EnergyOutput].size(),
2131
+ &inputrec->fepvals->all_lambda);
2132
+
2133
+ // cos acceleration is only supported by md, but older tpr
2134
+ // files might still combine it with other integrators
2135
+ GMX_RELEASE_ASSERT(inputrec->cos_accel == 0.0 || inputrec->eI == IntegrationAlgorithm::MD,
2136
+ "cos_acceleration is only supported by integrator=md");
2137
+
2138
+ /* Kinetic energy data */
2139
+ gmx_ekindata_t ekind(gmx::constArrayRefFromArray(inputrec->opts.ref_t, inputrec->opts.ngtc),
2140
+ inputrec->ensembleTemperatureSetting,
2141
+ inputrec->ensembleTemperature,
2142
+ inputrec->cos_accel,
2143
+ gmx_omp_nthreads_get(ModuleMultiThread::Update));
2144
+
2145
+ /* Set up interactive MD (IMD) */
2146
+ auto imdSession = makeImdSession(inputrec.get(),
2147
+ cr,
2148
+ wcycle.get(),
2149
+ &enerd,
2150
+ ms,
2151
+ mtop,
2152
+ mdlog,
2153
+ MAIN(cr) ? globalState->x : gmx::ArrayRef<gmx::RVec>(),
2154
+ filenames.size(),
2155
+ filenames.data(),
2156
+ oenv,
2157
+ mdrunOptions.imdOptions,
2158
+ startingBehavior);
2159
+
2160
+ if (haveDDAtomOrdering(*cr))
2161
+ {
2162
+ GMX_RELEASE_ASSERT(fr, "fr was NULL while cr->duty was DUTY_PP");
2163
+ /* This call is not included in init_domain_decomposition
2164
+ * because fr->atomInfoForEachMoleculeBlock is set later.
2165
+ */
2166
+ makeBondedLinks(cr->dd, mtop, fr->atomInfoForEachMoleculeBlock);
2167
+ }
2168
+
2169
+ if (runScheduleWork.simulationWork.useGpuFBufferOps)
2170
+ {
2171
+ fr->gpuForceReduction[gmx::AtomLocality::Local] = std::make_unique<gmx::GpuForceReduction>(
2172
+ deviceStreamManager->context(),
2173
+ deviceStreamManager->stream(gmx::DeviceStreamType::NonBondedLocal),
2174
+ wcycle.get());
2175
+ fr->gpuForceReduction[gmx::AtomLocality::NonLocal] = std::make_unique<gmx::GpuForceReduction>(
2176
+ deviceStreamManager->context(),
2177
+ deviceStreamManager->stream(gmx::DeviceStreamType::NonBondedNonLocal),
2178
+ wcycle.get());
2179
+
2180
+ if (runScheduleWork.simulationWork.useMdGpuGraph)
2181
+ {
2182
+ fr->mdGraph[MdGraphEvenOrOddStep::EvenStep] =
2183
+ std::make_unique<gmx::MdGpuGraph>(*fr->deviceStreamManager,
2184
+ runScheduleWork.simulationWork,
2185
+ cr->mpi_comm_mygroup,
2186
+ MdGraphEvenOrOddStep::EvenStep,
2187
+ wcycle.get());
2188
+
2189
+ fr->mdGraph[MdGraphEvenOrOddStep::OddStep] =
2190
+ std::make_unique<gmx::MdGpuGraph>(*fr->deviceStreamManager,
2191
+ runScheduleWork.simulationWork,
2192
+ cr->mpi_comm_mygroup,
2193
+ MdGraphEvenOrOddStep::OddStep,
2194
+ wcycle.get());
2195
+
2196
+ fr->mdGraph[MdGraphEvenOrOddStep::EvenStep]->setAlternateStepPpTaskCompletionEvent(
2197
+ fr->mdGraph[MdGraphEvenOrOddStep::OddStep]->getPpTaskCompletionEvent());
2198
+ fr->mdGraph[MdGraphEvenOrOddStep::OddStep]->setAlternateStepPpTaskCompletionEvent(
2199
+ fr->mdGraph[MdGraphEvenOrOddStep::EvenStep]->getPpTaskCompletionEvent());
2200
+ }
2201
+ }
2202
+
2203
+ std::unique_ptr<gmx::StatePropagatorDataGpu> stateGpu;
2204
+ if (gpusWereDetected && gmx::needStateGpu(runScheduleWork.simulationWork))
2205
+ {
2206
+ GpuApiCallBehavior transferKind =
2207
+ (inputrec->eI == IntegrationAlgorithm::MD && !doRerun && !useModularSimulator)
2208
+ ? GpuApiCallBehavior::Async
2209
+ : GpuApiCallBehavior::Sync;
2210
+ GMX_RELEASE_ASSERT(deviceStreamManager != nullptr,
2211
+ "GPU device stream manager should be initialized to use GPU.");
2212
+ stateGpu = std::make_unique<gmx::StatePropagatorDataGpu>(
2213
+ *deviceStreamManager, transferKind, pme_gpu_get_block_size(fr->pmedata), wcycle.get());
2214
+ fr->stateGpu = stateGpu.get();
2215
+ }
2216
+
2217
+ GMX_ASSERT(stopHandlerBuilder_, "Runner must provide StopHandlerBuilder to simulator.");
2218
+ SimulatorBuilder simulatorBuilder;
2219
+
2220
+ simulatorBuilder.add(SimulatorStateData(
2221
+ globalState.get(), localState, &observablesHistory, &enerd, &ekind));
2222
+ simulatorBuilder.add(std::move(membedHolder));
2223
+ simulatorBuilder.add(std::move(stopHandlerBuilder_));
2224
+ simulatorBuilder.add(SimulatorConfig(mdrunOptions, startingBehavior, &runScheduleWork));
2225
+
2226
+
2227
+ simulatorBuilder.add(SimulatorEnv(fplog, cr, ms, mdlog, oenv, &observablesReducerBuilder));
2228
+ simulatorBuilder.add(Profiling(&nrnb, walltime_accounting, wcycle.get()));
2229
+ simulatorBuilder.add(ConstraintsParam(
2230
+ constr.get(), enforcedRotation ? enforcedRotation->getLegacyEnfrot() : nullptr, vsite.get()));
2231
+ // TODO: Separate `fr` to a separate add, and make the `build` handle the coupling sensibly.
2232
+ simulatorBuilder.add(LegacyInput(
2233
+ static_cast<int>(filenames.size()), filenames.data(), inputrec.get(), fr.get()));
2234
+ simulatorBuilder.add(ReplicaExchangeParameters(replExParams));
2235
+ simulatorBuilder.add(InteractiveMD(imdSession.get()));
2236
+ simulatorBuilder.add(SimulatorModules(mdModules_->outputProvider(), mdModules_->notifiers()));
2237
+ simulatorBuilder.add(CenterOfMassPulling(pull_work));
2238
+ // Todo move to an MDModule
2239
+ simulatorBuilder.add(IonSwapping(swap));
2240
+ simulatorBuilder.add(TopologyData(mtop, &localTopology, mdAtoms.get()));
2241
+ simulatorBuilder.add(BoxDeformationHandle(deform.get()));
2242
+ simulatorBuilder.add(std::move(modularSimulatorCheckpointData));
2243
+
2244
+ /* PLUMED */
2245
+ if(plumedswitch){
2246
+ if(useModularSimulator) gmx_fatal(FARGS, "PLUMED is not yet compatible with GROMACS new modular simulator");
2247
+ /* detect plumed API version */
2248
+ int pversion=0;
2249
+ plumed_cmd(plumedmain,"getApiVersion",&pversion);
2250
+ if(pversion>5) {
2251
+ int nth = gmx_omp_nthreads_get(ModuleMultiThread::Default);
2252
+ plumed_cmd(plumedmain,"setNumOMPthreads",&nth);
2253
+ }
2254
+ /* set GPU device id */
2255
+ if(pversion>9) {
2256
+ plumed_cmd(plumedmain,"setGpuDeviceId", &deviceId);
2257
+ }
2258
+ if(useGpuForUpdate) {
2259
+ GMX_LOG(mdlog.warning)
2260
+ .asParagraph()
2261
+ .appendTextFormatted(
2262
+ "This simulation is resident on GPU (-update gpu)\n"
2263
+ "but also runs PLUMED (-plumed ). Unless plumed actions are performed\n"
2264
+ "only on neighbour list search and/or file writing steps, this will lead to WRONG RESULTS.\n"
2265
+ "Stop it and run it again with -update cpu.\n");
2266
+ }
2267
+ }
2268
+ /* END PLUMED */
2269
+
2270
+ // build and run simulator object based on user-input
2271
+ auto simulator = simulatorBuilder.build(useModularSimulator);
2272
+ simulator->run();
2273
+
2274
+ if (fr->pmePpCommGpu)
2275
+ {
2276
+ // destroy object since it is no longer required. (This needs to be done while the GPU context still exists.)
2277
+ fr->pmePpCommGpu.reset();
2278
+ }
2279
+
2280
+ if (inputrec->bPull)
2281
+ {
2282
+ finish_pull(pull_work);
2283
+ }
2284
+ finish_swapcoords(swap);
2285
+ }
2286
+ else
2287
+ {
2288
+ GMX_RELEASE_ASSERT(pmedata, "pmedata was NULL while cr->duty was not DUTY_PP");
2289
+ /* do PME only */
2290
+ walltime_accounting = walltime_accounting_init(gmx_omp_nthreads_get(ModuleMultiThread::Pme));
2291
+ gmx_pmeonly(&pmedata,
2292
+ cr,
2293
+ &nrnb,
2294
+ wcycle.get(),
2295
+ walltime_accounting,
2296
+ inputrec.get(),
2297
+ pmeRunMode,
2298
+ runScheduleWork.simulationWork.useGpuPmePpCommunication,
2299
+ deviceStreamManager.get());
2300
+ }
2301
+
2302
+ wallcycle_stop(wcycle.get(), WallCycleCounter::Run);
2303
+
2304
+ /* Finish up, write some stuff
2305
+ * if rerunMD, don't write last frame again
2306
+ */
2307
+ finish_run(fplog,
2308
+ mdlog,
2309
+ cr,
2310
+ *inputrec,
2311
+ &nrnb,
2312
+ wcycle.get(),
2313
+ walltime_accounting,
2314
+ fr ? fr->nbv.get() : nullptr,
2315
+ pmedata,
2316
+ EI_DYNAMICS(inputrec->eI) && !isMultiSim(ms));
2317
+
2318
+ // Free PME data
2319
+ if (pmedata)
2320
+ {
2321
+ gmx_pme_destroy(pmedata);
2322
+ pmedata = nullptr;
2323
+ }
2324
+
2325
+ // FIXME: this is only here to manually unpin mdAtoms->chargeA_ and state->x,
2326
+ // before we destroy the GPU context(s)
2327
+ // Pinned buffers are associated with contexts in CUDA.
2328
+ // As soon as we destroy GPU contexts after mdrunner() exits, these lines should go.
2329
+ cr->destroyDD();
2330
+ mdAtoms.reset(nullptr);
2331
+ globalState.reset(nullptr);
2332
+ localStateInstance.reset(nullptr);
2333
+ mdModules_.reset(nullptr); // destruct force providers here as they might also use the GPU
2334
+ fr.reset(nullptr); // destruct forcerec before gpu
2335
+ // TODO convert to C++ so we can get rid of these frees
2336
+ sfree(disresdata);
2337
+
2338
+ // Destroy streams after all the structures using them
2339
+ deviceStreamManager.reset(nullptr);
2340
+
2341
+ if (!hwinfo_->deviceInfoList.empty())
2342
+ {
2343
+ /* stop the GPU profiler (only CUDA) */
2344
+ stopGpuProfiler();
2345
+ }
2346
+
2347
+ /* With tMPI we need to wait for all ranks to finish deallocation before
2348
+ * destroying the CUDA context as some tMPI ranks may be sharing
2349
+ * GPU and context.
2350
+ *
2351
+ * This is not a concern in OpenCL where we use one context per rank.
2352
+ *
2353
+ * Note: it is safe to not call the barrier on the ranks which do not use GPU,
2354
+ * but it is easier and more futureproof to call it on the whole node.
2355
+ *
2356
+ * Note that this function needs to be called even if GPUs are not used
2357
+ * in this run because the PME ranks have no knowledge of whether GPUs
2358
+ * are used or not, but all ranks need to enter the barrier below.
2359
+ * \todo Remove this physical node barrier after making sure
2360
+ * that it's not needed anymore (with a shared GPU run).
2361
+ */
2362
+ if (GMX_THREAD_MPI)
2363
+ {
2364
+ physicalNodeComm.barrier();
2365
+ }
2366
+
2367
+ const bool haveDetectedOrForcedCudaAwareMpi =
2368
+ (gmx::checkMpiCudaAwareSupport() == gmx::GpuAwareMpiStatus::Supported
2369
+ || gmx::checkMpiCudaAwareSupport() == gmx::GpuAwareMpiStatus::Forced);
2370
+ if (!haveDetectedOrForcedCudaAwareMpi)
2371
+ {
2372
+ // Don't reset GPU in case of GPU-AWARE MPI
2373
+ // UCX creates GPU buffers which are cleaned-up as part of MPI_Finalize()
2374
+ // resetting the device before MPI_Finalize() results in crashes inside UCX
2375
+ // This can also cause issues in tests that invoke mdrunner() multiple
2376
+ // times in the same process; ref #3952.
2377
+ releaseDevice(deviceInfo);
2378
+ }
2379
+
2380
+ /* Does what it says */
2381
+ print_date_and_time(fplog, cr->nodeid, "Finished mdrun", gmx_gettime());
2382
+ walltime_accounting_destroy(walltime_accounting);
2383
+
2384
+ /* PLUMED */
2385
+ if(plumedswitch){
2386
+ plumed_finalize(plumedmain);
2387
+ }
2388
+ /* END PLUMED */
2389
+
2390
+ // Ensure log file content is written
2391
+ if (logFileHandle)
2392
+ {
2393
+ gmx_fio_flush(logFileHandle);
2394
+ }
2395
+
2396
+ /* Reset FPEs (important for unit tests) by disabling them. Assumes no
2397
+ * exceptions were enabled before function was called. */
2398
+ if (bEnableFPE)
2399
+ {
2400
+ gmx_fedisableexcept();
2401
+ }
2402
+
2403
+ auto rc = static_cast<int>(gmx_get_stop_condition());
2404
+
2405
+ #if GMX_THREAD_MPI
2406
+ /* we need to join all threads. The sub-threads join when they
2407
+ exit this function, but the main thread needs to be told to
2408
+ wait for that. */
2409
+ if (MAIN(cr))
2410
+ {
2411
+ tMPI_Finalize();
2412
+ }
2413
+ #endif
2414
+ return rc;
2415
+ } // Mdrunner::mdrunner
2416
+
2417
+ Mdrunner::~Mdrunner()
2418
+ {
2419
+ // Clean up of the Manager.
2420
+ // This will end up getting called on every thread-MPI rank, which is unnecessary,
2421
+ // but okay as long as threads synchronize some time before adding or accessing
2422
+ // a new set of restraints.
2423
+ if (restraintManager_)
2424
+ {
2425
+ restraintManager_->clear();
2426
+ GMX_ASSERT(restraintManager_->countRestraints() == 0,
2427
+ "restraints added during runner life time should be cleared at runner "
2428
+ "destruction.");
2429
+ }
2430
+ }
2431
+
2432
+ void Mdrunner::addPotential(std::shared_ptr<gmx::IRestraintPotential> puller, const std::string& name)
2433
+ {
2434
+ GMX_ASSERT(restraintManager_, "Mdrunner must have a restraint manager.");
2435
+ // Not sure if this should be logged through the md logger or something else,
2436
+ // but it is helpful to have some sort of INFO level message sent somewhere.
2437
+ // std::cout << "Registering restraint named " << name << std::endl;
2438
+
2439
+ // When multiple restraints are used, it may be wasteful to register them separately.
2440
+ // Maybe instead register an entire Restraint Manager as a force provider.
2441
+ restraintManager_->addToSpec(std::move(puller), name);
2442
+ }
2443
+
2444
+ Mdrunner::Mdrunner(std::unique_ptr<MDModules> mdModules) : mdModules_(std::move(mdModules)) {}
2445
+
2446
+ Mdrunner::Mdrunner(Mdrunner&&) noexcept = default;
2447
+
2448
+ Mdrunner& Mdrunner::operator=(Mdrunner&& /*handle*/) noexcept = default;
2449
+
2450
+ class Mdrunner::BuilderImplementation
2451
+ {
2452
+ public:
2453
+ BuilderImplementation() = delete;
2454
+ BuilderImplementation(std::unique_ptr<MDModules> mdModules, compat::not_null<SimulationContext*> context);
2455
+ ~BuilderImplementation();
2456
+
2457
+ BuilderImplementation& setExtraMdrunOptions(const MdrunOptions& options,
2458
+ real forceWarningThreshold,
2459
+ StartingBehavior startingBehavior);
2460
+
2461
+ void addHardwareDetectionResult(const gmx_hw_info_t* hwinfo);
2462
+
2463
+ void addDomdec(const DomdecOptions& options);
2464
+
2465
+ void addInput(SimulationInputHandle inputHolder);
2466
+
2467
+ void addVerletList(int nstlist);
2468
+
2469
+ void addReplicaExchange(const ReplicaExchangeParameters& params);
2470
+
2471
+ void addNonBonded(const char* nbpu_opt);
2472
+
2473
+ void addPME(const char* pme_opt_, const char* pme_fft_opt_);
2474
+
2475
+ void addBondedTaskAssignment(const char* bonded_opt);
2476
+
2477
+ void addUpdateTaskAssignment(const char* update_opt);
2478
+
2479
+ void addHardwareOptions(const gmx_hw_opt_t& hardwareOptions);
2480
+
2481
+ void addFilenames(ArrayRef<const t_filenm> filenames);
2482
+
2483
+ void addOutputEnvironment(gmx_output_env_t* outputEnvironment);
2484
+
2485
+ void addLogFile(t_fileio* logFileHandle);
2486
+
2487
+ void addStopHandlerBuilder(std::unique_ptr<StopHandlerBuilder> builder);
2488
+
2489
+ Mdrunner build();
2490
+
2491
+ private:
2492
+ // Default parameters copied from runner.h
2493
+ // \todo Clarify source(s) of default parameters.
2494
+
2495
+ const char* nbpu_opt_ = nullptr;
2496
+ const char* pme_opt_ = nullptr;
2497
+ const char* pme_fft_opt_ = nullptr;
2498
+ const char* bonded_opt_ = nullptr;
2499
+ const char* update_opt_ = nullptr;
2500
+
2501
+ MdrunOptions mdrunOptions_;
2502
+
2503
+ DomdecOptions domdecOptions_;
2504
+
2505
+ ReplicaExchangeParameters replicaExchangeParameters_;
2506
+
2507
+ //! Command-line override for the duration of a neighbor list with the Verlet scheme.
2508
+ int nstlist_ = 0;
2509
+
2510
+ //! World communicator, used for hardware detection and task assignment
2511
+ MPI_Comm libraryWorldCommunicator_ = MPI_COMM_NULL;
2512
+
2513
+ //! Multisim communicator handle.
2514
+ gmx_multisim_t* multiSimulation_;
2515
+
2516
+ //! mdrun communicator
2517
+ MPI_Comm simulationCommunicator_ = MPI_COMM_NULL;
2518
+
2519
+ //! Print a warning if any force is larger than this (in kJ/mol nm).
2520
+ real forceWarningThreshold_ = -1;
2521
+
2522
+ //! Whether the simulation will start afresh, or restart with/without appending.
2523
+ StartingBehavior startingBehavior_ = StartingBehavior::NewSimulation;
2524
+
2525
+ //! The modules that comprise the functionality of mdrun.
2526
+ std::unique_ptr<MDModules> mdModules_;
2527
+
2528
+ //! Detected hardware.
2529
+ const gmx_hw_info_t* hwinfo_ = nullptr;
2530
+
2531
+ //! \brief Parallelism information.
2532
+ gmx_hw_opt_t hardwareOptions_;
2533
+
2534
+ //! filename options for simulation.
2535
+ ArrayRef<const t_filenm> filenames_;
2536
+
2537
+ /*! \brief Handle to output environment.
2538
+ *
2539
+ * \todo gmx_output_env_t needs lifetime management.
2540
+ */
2541
+ gmx_output_env_t* outputEnvironment_ = nullptr;
2542
+
2543
+ /*! \brief Non-owning handle to MD log file.
2544
+ *
2545
+ * \todo Context should own output facilities for client.
2546
+ * \todo Improve log file handle management.
2547
+ * \internal
2548
+ * Code managing the FILE* relies on the ability to set it to
2549
+ * nullptr to check whether the filehandle is valid.
2550
+ */
2551
+ t_fileio* logFileHandle_ = nullptr;
2552
+
2553
+ /*!
2554
+ * \brief Builder for simulation stop signal handler.
2555
+ */
2556
+ std::unique_ptr<StopHandlerBuilder> stopHandlerBuilder_ = nullptr;
2557
+
2558
+ /*!
2559
+ * \brief Sources for initial simulation state.
2560
+ *
2561
+ * See issue #3652 for near-term refinements to the SimulationInput interface.
2562
+ *
2563
+ * See issue #3379 for broader discussion on API aspects of simulation inputs and outputs.
2564
+ */
2565
+ SimulationInputHandle inputHolder_;
2566
+ };
2567
+
2568
+ Mdrunner::BuilderImplementation::BuilderImplementation(std::unique_ptr<MDModules> mdModules,
2569
+ compat::not_null<SimulationContext*> context) :
2570
+ mdModules_(std::move(mdModules))
2571
+ {
2572
+ libraryWorldCommunicator_ = context->libraryWorldCommunicator_;
2573
+ simulationCommunicator_ = context->simulationCommunicator_;
2574
+ multiSimulation_ = context->multiSimulation_.get();
2575
+ }
2576
+
2577
+ Mdrunner::BuilderImplementation::~BuilderImplementation() = default;
2578
+
2579
+ Mdrunner::BuilderImplementation&
2580
+ Mdrunner::BuilderImplementation::setExtraMdrunOptions(const MdrunOptions& options,
2581
+ const real forceWarningThreshold,
2582
+ const StartingBehavior startingBehavior)
2583
+ {
2584
+ mdrunOptions_ = options;
2585
+ forceWarningThreshold_ = forceWarningThreshold;
2586
+ startingBehavior_ = startingBehavior;
2587
+ return *this;
2588
+ }
2589
+
2590
+ void Mdrunner::BuilderImplementation::addDomdec(const DomdecOptions& options)
2591
+ {
2592
+ domdecOptions_ = options;
2593
+ }
2594
+
2595
+ void Mdrunner::BuilderImplementation::addVerletList(int nstlist)
2596
+ {
2597
+ nstlist_ = nstlist;
2598
+ }
2599
+
2600
+ void Mdrunner::BuilderImplementation::addReplicaExchange(const ReplicaExchangeParameters& params)
2601
+ {
2602
+ replicaExchangeParameters_ = params;
2603
+ }
2604
+
2605
+ Mdrunner Mdrunner::BuilderImplementation::build()
2606
+ {
2607
+ auto newRunner = Mdrunner(std::move(mdModules_));
2608
+
2609
+ newRunner.mdrunOptions = mdrunOptions_;
2610
+ newRunner.pforce = forceWarningThreshold_;
2611
+ newRunner.startingBehavior = startingBehavior_;
2612
+ newRunner.domdecOptions = domdecOptions_;
2613
+
2614
+ // \todo determine an invariant to check or confirm that all gmx_hw_opt_t objects are valid
2615
+ newRunner.hw_opt = hardwareOptions_;
2616
+
2617
+ // No invariant to check. This parameter exists to optionally override other behavior.
2618
+ newRunner.nstlist_cmdline = nstlist_;
2619
+
2620
+ newRunner.replExParams = replicaExchangeParameters_;
2621
+
2622
+ newRunner.filenames = filenames_;
2623
+
2624
+ newRunner.libraryWorldCommunicator = libraryWorldCommunicator_;
2625
+
2626
+ newRunner.simulationCommunicator = simulationCommunicator_;
2627
+
2628
+ // nullptr is a valid value for the multisim handle
2629
+ newRunner.ms = multiSimulation_;
2630
+
2631
+ if (hwinfo_)
2632
+ {
2633
+ newRunner.hwinfo_ = hwinfo_;
2634
+ }
2635
+ else
2636
+ {
2637
+ GMX_THROW(gmx::APIError(
2638
+ "MdrunnerBuilder::addHardwareDetectionResult() is required before build()"));
2639
+ }
2640
+
2641
+ if (inputHolder_)
2642
+ {
2643
+ newRunner.inputHolder_ = std::move(inputHolder_);
2644
+ }
2645
+ else
2646
+ {
2647
+ GMX_THROW(gmx::APIError("MdrunnerBuilder::addInput() is required before build()."));
2648
+ }
2649
+
2650
+ // \todo Clarify ownership and lifetime management for gmx_output_env_t
2651
+ // \todo Update sanity checking when output environment has clearly specified invariants.
2652
+ // Initialization and default values for oenv are not well specified in the current version.
2653
+ if (outputEnvironment_)
2654
+ {
2655
+ newRunner.oenv = outputEnvironment_;
2656
+ }
2657
+ else
2658
+ {
2659
+ GMX_THROW(gmx::APIError(
2660
+ "MdrunnerBuilder::addOutputEnvironment() is required before build()"));
2661
+ }
2662
+
2663
+ newRunner.logFileHandle = logFileHandle_;
2664
+
2665
+ if (nbpu_opt_)
2666
+ {
2667
+ newRunner.nbpu_opt = nbpu_opt_;
2668
+ }
2669
+ else
2670
+ {
2671
+ GMX_THROW(gmx::APIError("MdrunnerBuilder::addNonBonded() is required before build()"));
2672
+ }
2673
+
2674
+ if (pme_opt_ && pme_fft_opt_)
2675
+ {
2676
+ newRunner.pme_opt = pme_opt_;
2677
+ newRunner.pme_fft_opt = pme_fft_opt_;
2678
+ }
2679
+ else
2680
+ {
2681
+ GMX_THROW(gmx::APIError("MdrunnerBuilder::addElectrostatics() is required before build()"));
2682
+ }
2683
+
2684
+ if (bonded_opt_)
2685
+ {
2686
+ newRunner.bonded_opt = bonded_opt_;
2687
+ }
2688
+ else
2689
+ {
2690
+ GMX_THROW(gmx::APIError(
2691
+ "MdrunnerBuilder::addBondedTaskAssignment() is required before build()"));
2692
+ }
2693
+
2694
+ if (update_opt_)
2695
+ {
2696
+ newRunner.update_opt = update_opt_;
2697
+ }
2698
+ else
2699
+ {
2700
+ GMX_THROW(gmx::APIError(
2701
+ "MdrunnerBuilder::addUpdateTaskAssignment() is required before build() "));
2702
+ }
2703
+
2704
+
2705
+ newRunner.restraintManager_ = std::make_unique<gmx::RestraintManager>();
2706
+
2707
+ if (stopHandlerBuilder_)
2708
+ {
2709
+ newRunner.stopHandlerBuilder_ = std::move(stopHandlerBuilder_);
2710
+ }
2711
+ else
2712
+ {
2713
+ newRunner.stopHandlerBuilder_ = std::make_unique<StopHandlerBuilder>();
2714
+ }
2715
+
2716
+ return newRunner;
2717
+ }
2718
+
2719
+ void Mdrunner::BuilderImplementation::addHardwareDetectionResult(const gmx_hw_info_t* hwinfo)
2720
+ {
2721
+ hwinfo_ = hwinfo;
2722
+ }
2723
+
2724
+ void Mdrunner::BuilderImplementation::addNonBonded(const char* nbpu_opt)
2725
+ {
2726
+ nbpu_opt_ = nbpu_opt;
2727
+ }
2728
+
2729
+ void Mdrunner::BuilderImplementation::addPME(const char* pme_opt, const char* pme_fft_opt)
2730
+ {
2731
+ pme_opt_ = pme_opt;
2732
+ pme_fft_opt_ = pme_fft_opt;
2733
+ }
2734
+
2735
+ void Mdrunner::BuilderImplementation::addBondedTaskAssignment(const char* bonded_opt)
2736
+ {
2737
+ bonded_opt_ = bonded_opt;
2738
+ }
2739
+
2740
+ void Mdrunner::BuilderImplementation::addUpdateTaskAssignment(const char* update_opt)
2741
+ {
2742
+ update_opt_ = update_opt;
2743
+ }
2744
+
2745
+ void Mdrunner::BuilderImplementation::addHardwareOptions(const gmx_hw_opt_t& hardwareOptions)
2746
+ {
2747
+ hardwareOptions_ = hardwareOptions;
2748
+ }
2749
+
2750
+ void Mdrunner::BuilderImplementation::addFilenames(ArrayRef<const t_filenm> filenames)
2751
+ {
2752
+ filenames_ = filenames;
2753
+ }
2754
+
2755
+ void Mdrunner::BuilderImplementation::addOutputEnvironment(gmx_output_env_t* outputEnvironment)
2756
+ {
2757
+ outputEnvironment_ = outputEnvironment;
2758
+ }
2759
+
2760
+ void Mdrunner::BuilderImplementation::addLogFile(t_fileio* logFileHandle)
2761
+ {
2762
+ logFileHandle_ = logFileHandle;
2763
+ }
2764
+
2765
+ void Mdrunner::BuilderImplementation::addStopHandlerBuilder(std::unique_ptr<StopHandlerBuilder> builder)
2766
+ {
2767
+ stopHandlerBuilder_ = std::move(builder);
2768
+ }
2769
+
2770
+ void Mdrunner::BuilderImplementation::addInput(SimulationInputHandle inputHolder)
2771
+ {
2772
+ inputHolder_ = std::move(inputHolder);
2773
+ }
2774
+
2775
+ MdrunnerBuilder::MdrunnerBuilder(std::unique_ptr<MDModules> mdModules,
2776
+ compat::not_null<SimulationContext*> context) :
2777
+ impl_{ std::make_unique<Mdrunner::BuilderImplementation>(std::move(mdModules), context) }
2778
+ {
2779
+ }
2780
+
2781
+ MdrunnerBuilder::~MdrunnerBuilder() = default;
2782
+
2783
+ MdrunnerBuilder& MdrunnerBuilder::addHardwareDetectionResult(const gmx_hw_info_t* hwinfo)
2784
+ {
2785
+ impl_->addHardwareDetectionResult(hwinfo);
2786
+ return *this;
2787
+ }
2788
+
2789
+ MdrunnerBuilder& MdrunnerBuilder::addSimulationMethod(const MdrunOptions& options,
2790
+ real forceWarningThreshold,
2791
+ const StartingBehavior startingBehavior)
2792
+ {
2793
+ impl_->setExtraMdrunOptions(options, forceWarningThreshold, startingBehavior);
2794
+ return *this;
2795
+ }
2796
+
2797
+ MdrunnerBuilder& MdrunnerBuilder::addDomainDecomposition(const DomdecOptions& options)
2798
+ {
2799
+ impl_->addDomdec(options);
2800
+ return *this;
2801
+ }
2802
+
2803
+ MdrunnerBuilder& MdrunnerBuilder::addNeighborList(int nstlist)
2804
+ {
2805
+ impl_->addVerletList(nstlist);
2806
+ return *this;
2807
+ }
2808
+
2809
+ MdrunnerBuilder& MdrunnerBuilder::addReplicaExchange(const ReplicaExchangeParameters& params)
2810
+ {
2811
+ impl_->addReplicaExchange(params);
2812
+ return *this;
2813
+ }
2814
+
2815
+ MdrunnerBuilder& MdrunnerBuilder::addNonBonded(const char* nbpu_opt)
2816
+ {
2817
+ impl_->addNonBonded(nbpu_opt);
2818
+ return *this;
2819
+ }
2820
+
2821
+ MdrunnerBuilder& MdrunnerBuilder::addElectrostatics(const char* pme_opt, const char* pme_fft_opt)
2822
+ {
2823
+ // The builder method may become more general in the future, but in this version,
2824
+ // parameters for PME electrostatics are both required and the only parameters
2825
+ // available.
2826
+ if (pme_opt && pme_fft_opt)
2827
+ {
2828
+ impl_->addPME(pme_opt, pme_fft_opt);
2829
+ }
2830
+ else
2831
+ {
2832
+ GMX_THROW(
2833
+ gmx::InvalidInputError("addElectrostatics() arguments must be non-null pointers."));
2834
+ }
2835
+ return *this;
2836
+ }
2837
+
2838
+ MdrunnerBuilder& MdrunnerBuilder::addBondedTaskAssignment(const char* bonded_opt)
2839
+ {
2840
+ impl_->addBondedTaskAssignment(bonded_opt);
2841
+ return *this;
2842
+ }
2843
+
2844
+ MdrunnerBuilder& MdrunnerBuilder::addUpdateTaskAssignment(const char* update_opt)
2845
+ {
2846
+ impl_->addUpdateTaskAssignment(update_opt);
2847
+ return *this;
2848
+ }
2849
+
2850
+ Mdrunner MdrunnerBuilder::build()
2851
+ {
2852
+ return impl_->build();
2853
+ }
2854
+
2855
+ MdrunnerBuilder& MdrunnerBuilder::addHardwareOptions(const gmx_hw_opt_t& hardwareOptions)
2856
+ {
2857
+ impl_->addHardwareOptions(hardwareOptions);
2858
+ return *this;
2859
+ }
2860
+
2861
+ MdrunnerBuilder& MdrunnerBuilder::addFilenames(ArrayRef<const t_filenm> filenames)
2862
+ {
2863
+ impl_->addFilenames(filenames);
2864
+ return *this;
2865
+ }
2866
+
2867
+ MdrunnerBuilder& MdrunnerBuilder::addOutputEnvironment(gmx_output_env_t* outputEnvironment)
2868
+ {
2869
+ impl_->addOutputEnvironment(outputEnvironment);
2870
+ return *this;
2871
+ }
2872
+
2873
+ MdrunnerBuilder& MdrunnerBuilder::addLogFile(t_fileio* logFileHandle)
2874
+ {
2875
+ impl_->addLogFile(logFileHandle);
2876
+ return *this;
2877
+ }
2878
+
2879
+ MdrunnerBuilder& MdrunnerBuilder::addStopHandlerBuilder(std::unique_ptr<StopHandlerBuilder> builder)
2880
+ {
2881
+ impl_->addStopHandlerBuilder(std::move(builder));
2882
+ return *this;
2883
+ }
2884
+
2885
+ MdrunnerBuilder& MdrunnerBuilder::addInput(SimulationInputHandle input)
2886
+ {
2887
+ impl_->addInput(std::move(input));
2888
+ return *this;
2889
+ }
2890
+
2891
+ MdrunnerBuilder::MdrunnerBuilder(MdrunnerBuilder&&) noexcept = default;
2892
+
2893
+ MdrunnerBuilder& MdrunnerBuilder::operator=(MdrunnerBuilder&&) noexcept = default;
2894
+
2895
+ } // namespace gmx