Add environment variable that changes the meaning of '-update auto'
[alexxy/gromacs.git] / admin / builds / gromacs.py
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2015,2016,2017,2018,2019, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34
35 import os.path
36
37 # Policy global variables
38 use_stdlib_through_env_vars = False
39
40 # These are accessible later in the script, just like other declared
41 # options, via e.g. context.opts.release.  Keep these in alphabetical
42 # order for more convenient rebasing
43 extra_options = {
44     'asan': Option.simple,
45     'buildfftw': Option.simple,
46     'clang_cuda': Option.bool,
47     'double': Option.simple,
48     'fftpack': Option.simple,
49     'gpu_id': Option.string,
50     'hwloc': Option.bool,
51     'mdrun-only': Option.simple,
52     'mkl': Option.simple,
53     'mpiinplace': Option.bool,
54     'npme': Option.string,
55     'nranks': Option.string,
56     'openmp': Option.bool,
57     'reference': Option.simple,
58     'release': Option.simple,
59     'release-with-assert': Option.simple,
60     'release-with-debug-info': Option.simple,
61     'static': Option.simple,
62     'thread-mpi': Option.bool,
63     'tng' : Option.bool,
64     # The following options cater for testing code in Jenkins that is
65     # currently behind feature flags in master branch.
66     'gpubufferops' : Option.bool,
67     'gpucomm': Option.bool,
68     'gpuupdate': Option.bool,
69 }
70
71 extra_projects = [Project.REGRESSIONTESTS]
72
73 def do_build(context):
74     cmake_opts = dict()
75     cmake_opts['GMX_COMPILER_WARNINGS'] = 'ON'
76     cmake_opts['GMX_DEFAULT_SUFFIX'] = 'OFF'
77     cmake_opts['CMAKE_BUILD_TYPE'] = 'Debug'
78     cmake_opts['GMX_USE_RDTSCP'] = 'DETECT'
79
80     if not context.opts.msvc and not context.opts.mdrun_only and not context.opts.static:
81         cmake_opts['GMXAPI'] = 'ON'
82
83     if context.opts.reference:
84         cmake_opts['CMAKE_BUILD_TYPE'] = 'Reference'
85     elif context.opts['release']:
86         cmake_opts['CMAKE_BUILD_TYPE'] = 'Release'
87     elif context.opts['release-with-assert']:
88         cmake_opts['CMAKE_BUILD_TYPE'] = 'RelWithAssert'
89     elif context.opts['release-with-debug-info']:
90         cmake_opts['CMAKE_BUILD_TYPE'] = 'RelWithDebInfo'
91     elif context.opts.asan:
92         cmake_opts['CMAKE_BUILD_TYPE'] = 'ASAN'
93     elif context.opts.tsan:
94         cmake_opts['CMAKE_BUILD_TYPE'] = 'TSAN'
95
96     if context.opts.static:
97         cmake_opts['BUILD_SHARED_LIBS'] = 'OFF'
98
99     if context.opts.phi:
100         cmake_opts['CMAKE_TOOLCHAIN_FILE'] = 'Platform/XeonPhi'
101
102     if context.opts.double:
103         cmake_opts['GMX_DOUBLE'] = 'ON'
104
105     if context.opts.simd is None:
106         cmake_opts['GMX_SIMD'] = 'None'
107     else:
108         cmake_opts['GMX_SIMD'] = context.opts.simd
109     if context.opts.cuda or context.opts.opencl:
110         cmake_opts['GMX_GPU'] = 'ON'
111         if context.opts.opencl:
112             context.env.set_env_var('CUDA_PATH', context.env.cuda_root)
113             cmake_opts['GMX_USE_OPENCL'] = 'ON'
114         else:
115             cmake_opts['CUDA_TOOLKIT_ROOT_DIR'] = context.env.cuda_root
116             if context.opts.clang_cuda:
117                 cmake_opts['GMX_CLANG_CUDA'] = 'ON'
118             else:
119                 cmake_opts['CUDA_HOST_COMPILER'] = context.env.cuda_host_compiler
120     else:
121         cmake_opts['GMX_GPU'] = 'OFF'
122     if context.opts.thread_mpi is False:
123         cmake_opts['GMX_THREAD_MPI'] = 'OFF'
124     if context.opts.mpi:
125         cmake_opts['GMX_MPI'] = 'ON'
126     if context.opts.mpiinplace is False:
127         cmake_opts['GMX_MPI_IN_PLACE'] = 'OFF'
128     if context.opts.openmp is False:
129         cmake_opts['GMX_OPENMP'] = 'OFF'
130     if context.opts.tng is False:
131         cmake_opts['GMX_USE_TNG'] = 'OFF'
132
133     if context.opts.mkl:
134         cmake_opts['GMX_FFT_LIBRARY'] = 'mkl'
135     elif context.opts.fftpack:
136         cmake_opts['GMX_FFT_LIBRARY'] = 'fftpack'
137     elif context.opts.buildfftw:
138         cmake_opts['GMX_BUILD_OWN_FFTW'] = 'ON'
139         cmake_opts['GMX_BUILD_OWN_FFTW_URL'] = 'ftp://ftp.gromacs.org/misc/fftw-3.3.8.tar.gz'
140         cmake_opts['GMX_BUILD_OWN_FFTW_MD5'] = '8aac833c943d8e90d51b697b27d4384d'
141     if context.opts.mkl or context.opts.atlas or context.opts.armpl:
142         cmake_opts['GMX_EXTERNAL_BLAS'] = 'ON'
143         cmake_opts['GMX_EXTERNAL_LAPACK'] = 'ON'
144     if context.opts.clFFT:
145         cmake_opts['GMX_EXTERNAL_CLFFT'] = 'ON'
146         cmake_opts['clFFT_ROOT'] = context.env.clFFT_root
147
148     if context.opts.armpl:
149         cmake_opts['FFTWF_LIBRARY']     = os.path.join(context.env.armpl_dir, 'lib/libarmpl_lp64.so')
150         cmake_opts['FFTWF_INCLUDE_DIR'] = os.path.join(context.env.armpl_dir, 'include')
151         cmake_opts['GMX_BLAS_USER']     = os.path.join(context.env.armpl_dir, 'lib/libarmpl_lp64.so')
152         cmake_opts['GMX_LAPACK_USER']   = os.path.join(context.env.armpl_dir, 'lib/libarmpl_lp64.so')
153
154     if context.opts.hwloc is False:
155         cmake_opts['GMX_HWLOC'] = 'OFF'
156     elif context.opts.hwloc is True:
157         cmake_opts['GMX_HWLOC'] = 'ON'
158     else:
159         cmake_opts['GMX_HWLOC'] = 'AUTO'
160
161     if context.opts.tng is False:
162         cmake_opts['GMX_USE_TNG'] = 'OFF'
163
164     if context.opts.x11:
165         cmake_opts['GMX_X11'] = 'ON'
166
167     if context.opts.tidy:
168         cmake_opts['GMX_CLANG_TIDY'] = 'ON'
169         cmake_opts['CLANG_TIDY'] = context.env.cxx_compiler.replace("clang++", "clang-tidy")
170
171     # At least hwloc on Jenkins produces a massive amount of reports about
172     # memory leaks, which cannot be reasonably suppressed because ASAN cannot
173     # produce a reasonable stack trace for them.
174     if context.opts.asan:
175         cmake_opts['GMX_HWLOC'] = 'OFF'
176
177     if context.opts.gpubufferops:
178         context.env.set_env_var('GMX_USE_GPU_BUFFER_OPS', "1")
179
180     # GPU comm flag enables both DD and PP-PME comm as well as buffer ops (hard dependency)
181     if context.opts.gpucomm:
182         context.env.set_env_var('GMX_USE_GPU_BUFFER_OPS', "1")
183         context.env.set_env_var('GMX_GPU_DD_COMMS', "1")
184         context.env.set_env_var('GMX_GPU_PME_PP_COMMS', "1")
185
186     # GPU update flag enables GPU update+constraints as well as buffer ops (dependency)
187     if context.opts.gpuupdate:
188         context.env.set_env_var('GMX_USE_GPU_BUFFER_OPS', "1")
189         context.env.set_env_var('GMX_FORCE_UPDATE_DEFAULT_GPU', "1")
190
191     regressiontests_path = context.workspace.get_project_dir(Project.REGRESSIONTESTS)
192
193     if context.job_type == JobType.RELEASE:
194         cmake_opts['REGRESSIONTEST_PATH'] = regressiontests_path
195     else:
196         if context.opts.mdrun_only:
197             cmake_opts['GMX_BUILD_MDRUN_ONLY'] = 'ON'
198
199     # The build configuration has constructed the environment of the
200     # context so that a particular c++ standard library can be used,
201     # which may come from a different installation of gcc. Here, we
202     # tell CMake how to react to this.
203     #
204     # TODO Once gerrit 9051 and 9053 are both submitted on master,
205     # remove the hasattr part of the predicate, which will then be
206     # redundant.
207     if hasattr(context.env, 'gcc_exe') and context.env.gcc_exe is not None:
208         cmake_opts['GMX_GPLUSPLUS_PATH'] = context.env.gcc_exe
209         # TODO are these needed?
210         # gcc_exe_dirname = os.path.dirname(self.gcc_exe)
211         # gcc_toolchain_path = os.path.join(gcc_exe_dirname, '..')
212         # format_for_linker_flags="-Wl,-rpath,{gcctoolchain}/lib64 -L{gcctoolchain}/lib64"
213         # cmake_opts['CMAKE_CXX_LINK_FLAGS'] = format_for_linker_flags.format(gcctoolchain=gcc_toolchain_path)
214
215     context.env.set_env_var('GMX_NO_TERM', '1')
216
217     context.run_cmake(cmake_opts)
218     context.build_target(target=None, keep_going=True)
219
220     # TODO: Consider if it would be better to split this into a separate build
221     # script, since it is somewhat different, even though it benefits from some
222     # of the same build options.
223     if context.job_type == JobType.RELEASE:
224         context.build_target(target='check', keep_going=True)
225         context.build_target(target='install')
226         if context.opts.mdrun_only:
227             context.workspace.clean_build_dir()
228             cmake_opts['REGRESSIONTEST_PATH'] = None
229             cmake_opts['GMX_BUILD_MDRUN_ONLY'] = 'ON'
230             context.run_cmake(cmake_opts)
231             context.build_target(target=None, keep_going=True)
232             context.build_target(target='check', keep_going=True)
233             context.build_target(target='install')
234         gmxrc_cmd = '. ' + os.path.join(context.workspace.install_dir, 'bin', 'GMXRC')
235         context.env.run_env_script(gmxrc_cmd)
236         cmd = [os.path.join(regressiontests_path, 'gmxtest.pl'), '-nosuffix', 'all']
237         if context.opts.mpi:
238             cmd += ['-np', '1']
239         if context.opts.double:
240             cmd += ['-double']
241         if context.opts.mdrun_only:
242             cmd += ['-mdrun', 'mdrun']
243         context.run_cmd(cmd, failure_message='Regression tests failed to execute')
244         # TODO: Add testing for building the template.
245         # TODO: Generalize the machinery here such that it can easily be used
246         # also for non-release builds.
247     else:
248         context.build_target(target='tests', keep_going=True)
249
250         context.run_ctest(args=['--output-on-failure', '--label-exclude', 'SlowTest'], memcheck=context.opts.asan)
251
252         context.build_target(target='install')
253         # TODO: Consider what could be tested about the installed binaries.
254
255         if not context.opts.mdrun_only:
256             context.env.prepend_path_env(os.path.join(context.workspace.build_dir, 'bin'))
257             context.chdir(regressiontests_path)
258
259             use_tmpi = not context.opts.mpi and context.opts.thread_mpi is not False
260
261             cmd = 'perl gmxtest.pl -mpirun mpirun -xml -nosuffix all'
262
263             # setting this stuff below is just a temporary solution,
264             # it should all be passed as a proper the runconf from outside
265             # The whole mechanism should be rethought in #1587.
266             if context.opts.phi:
267                 cmd += ' -ntomp 28'
268             elif context.opts.openmp:
269                 # OpenMP should always work when compiled in! Currently not set if
270                 # not explicitly set
271                 cmd += ' -ntomp 2'
272
273             if context.opts.gpuhw == Gpuhw.NONE:
274                 context.env.set_env_var('GMX_DISABLE_GPU_DETECTION', '1')
275
276             if context.opts.gpu_id:
277                 cmd += ' -gpu_id ' + context.opts.gpu_id
278
279             if context.opts.nranks:
280                 nranks = context.opts.nranks
281             else:
282                 nranks = '2'
283
284             if context.opts.npme:
285                 cmd += ' -npme ' + context.opts.npme
286
287             if context.opts.mpi:
288                 cmd += ' -np ' + nranks
289             elif use_tmpi:
290                 cmd += ' -nt ' + nranks
291             if context.opts.double:
292                 cmd += ' -double'
293             if context.opts.asan:
294                 context.env.set_env_var('ASAN_OPTIONS', 'detect_leaks=0')
295             context.run_cmd(cmd, shell=True, failure_message='Regression tests failed to execute')