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