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