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