Merge branch release-2018
[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, 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 # These are accessible later in the script, just like other
38 # declared options, via e.g. context.opts.release.
39 extra_options = {
40     'mdrun-only': Option.simple,
41     'static': Option.simple,
42     'reference': Option.simple,
43     'release': Option.simple,
44     'release-with-assert': Option.simple,
45     'release-with-debug-info': Option.simple,
46     'asan': Option.simple,
47     'tng' : Option.bool,
48     'mkl': Option.simple,
49     'fftpack': Option.simple,
50     'double': Option.simple,
51     'thread-mpi': Option.bool,
52     'gpu': Option.bool,
53     'opencl': Option.bool,
54     'clang_cuda': Option.bool,
55     'openmp': Option.bool,
56     'nranks': Option.string,
57     'npme': Option.string,
58     'gpu_id': Option.string,
59     'hwloc': Option.bool
60 }
61
62 extra_projects = [Project.REGRESSIONTESTS]
63
64 def do_build(context):
65     cmake_opts = dict()
66     cmake_opts['GMX_COMPILER_WARNINGS'] = 'ON'
67     cmake_opts['GMX_DEFAULT_SUFFIX'] = 'OFF'
68     cmake_opts['CMAKE_BUILD_TYPE'] = 'Debug'
69     cmake_opts['GMX_USE_RDTSCP'] = 'DETECT'
70
71     if context.opts.reference:
72         cmake_opts['CMAKE_BUILD_TYPE'] = 'Reference'
73     elif context.opts['release']:
74         cmake_opts['CMAKE_BUILD_TYPE'] = 'Release'
75     elif context.opts['release-with-assert']:
76         cmake_opts['CMAKE_BUILD_TYPE'] = 'RelWithAssert'
77     elif context.opts['release-with-debug-info']:
78         cmake_opts['CMAKE_BUILD_TYPE'] = 'RelWithDebInfo'
79     elif context.opts.asan:
80         cmake_opts['CMAKE_BUILD_TYPE'] = 'ASAN'
81     elif context.opts.tsan:
82         cmake_opts['CMAKE_BUILD_TYPE'] = 'TSAN'
83
84     if context.opts.static:
85         cmake_opts['BUILD_SHARED_LIBS'] = 'OFF'
86
87     if context.opts.phi:
88         cmake_opts['CMAKE_TOOLCHAIN_FILE'] = 'Platform/XeonPhi'
89
90     if context.opts.double:
91         cmake_opts['GMX_DOUBLE'] = 'ON'
92
93     if context.opts.simd is None:
94         cmake_opts['GMX_SIMD'] = 'None'
95     else:
96         cmake_opts['GMX_SIMD'] = context.opts.simd
97     if context.opts.gpu or context.opts.opencl:
98         cmake_opts['GMX_GPU'] = 'ON'
99         if context.opts.opencl:
100             context.env.set_env_var('CUDA_PATH', context.env.cuda_root)
101             context.env.set_env_var('AMDAPPSDKROOT', context.env.amdappsdk_root)
102             cmake_opts['GMX_USE_OPENCL'] = 'ON'
103         else:
104             cmake_opts['CUDA_TOOLKIT_ROOT_DIR'] = context.env.cuda_root
105             if context.opts.clang_cuda:
106                 cmake_opts['GMX_CLANG_CUDA'] = 'ON'
107             else:
108                 cmake_opts['CUDA_HOST_COMPILER'] = context.env.cuda_host_compiler
109     else:
110         cmake_opts['GMX_GPU'] = 'OFF'
111     if context.opts.thread_mpi is False:
112         cmake_opts['GMX_THREAD_MPI'] = 'OFF'
113     if context.opts.mpi:
114         cmake_opts['GMX_MPI'] = 'ON'
115     if context.opts.openmp is False:
116         cmake_opts['GMX_OPENMP'] = 'OFF'
117     if context.opts.tng is False:
118         cmake_opts['GMX_USE_TNG'] = 'OFF'
119
120     if context.opts.mkl:
121         cmake_opts['GMX_FFT_LIBRARY'] = 'mkl'
122     elif context.opts.fftpack:
123         cmake_opts['GMX_FFT_LIBRARY'] = 'fftpack'
124     if context.opts.mkl or context.opts.atlas:
125         cmake_opts['GMX_EXTERNAL_BLAS'] = 'ON'
126         cmake_opts['GMX_EXTERNAL_LAPACK'] = 'ON'
127     if context.opts.clFFT:
128         cmake_opts['GMX_EXTERNAL_CLFFT'] = 'ON'
129         cmake_opts['clFFT_ROOT'] = context.env.clFFT_root
130
131     if context.opts.hwloc is False:
132         cmake_opts['GMX_HWLOC'] = 'OFF'
133
134     if context.opts.x11:
135         cmake_opts['GMX_X11'] = 'ON'
136
137     if context.opts.tidy:
138         cmake_opts['GMX_CLANG_TIDY'] = 'ON'
139         cmake_opts['CLANG_TIDY'] = context.env.cxx_compiler.replace("clang++", "clang-tidy")
140
141     # At least hwloc on Jenkins produces a massive amount of reports about
142     # memory leaks, which cannot be reasonably suppressed because ASAN cannot
143     # produce a reasonable stack trace for them.
144     if context.opts.asan:
145         cmake_opts['GMX_HWLOC'] = 'OFF'
146
147     regressiontests_path = context.workspace.get_project_dir(Project.REGRESSIONTESTS)
148
149     if context.job_type == JobType.RELEASE:
150         cmake_opts['REGRESSIONTEST_PATH'] = regressiontests_path
151     else:
152         if context.opts.mdrun_only:
153             cmake_opts['GMX_BUILD_MDRUN_ONLY'] = 'ON'
154
155     context.env.set_env_var('GMX_NO_TERM', '1')
156
157     context.run_cmake(cmake_opts)
158     context.build_target(target=None, keep_going=True)
159
160     # TODO: Consider if it would be better to split this into a separate build
161     # script, since it is somewhat different, even though it benefits from some
162     # of the same build options.
163     if context.job_type == JobType.RELEASE:
164         context.build_target(target='check', keep_going=True)
165         context.build_target(target='install')
166         if context.opts.mdrun_only:
167             context.workspace.clean_build_dir()
168             cmake_opts['REGRESSIONTEST_PATH'] = None
169             cmake_opts['GMX_BUILD_MDRUN_ONLY'] = 'ON'
170             context.run_cmake(cmake_opts)
171             context.build_target(target=None, keep_going=True)
172             context.build_target(target='check', keep_going=True)
173             context.build_target(target='install')
174         gmxrc_cmd = '. ' + os.path.join(context.workspace.install_dir, 'bin', 'GMXRC')
175         context.env.run_env_script(gmxrc_cmd)
176         cmd = [os.path.join(regressiontests_path, 'gmxtest.pl'), '-nosuffix', 'all']
177         if context.opts.mpi:
178             cmd += ['-np', '1']
179         if context.opts.double:
180             cmd += ['-double']
181         if context.opts.mdrun_only:
182             cmd += ['-mdrun', 'mdrun']
183         context.run_cmd(cmd, failure_message='Regression tests failed to execute')
184         # TODO: Add testing for building the template.
185         # TODO: Generalize the machinery here such that it can easily be used
186         # also for non-release builds.
187     else:
188         context.build_target(target='tests', keep_going=True)
189
190         context.run_ctest(args=['--output-on-failure', '--label-exclude', 'SlowTest'], memcheck=context.opts.asan)
191
192         context.build_target(target='install')
193         # TODO: Consider what could be tested about the installed binaries.
194
195         if not context.opts.mdrun_only:
196             context.env.prepend_path_env(os.path.join(context.workspace.build_dir, 'bin'))
197             context.chdir(regressiontests_path)
198
199             use_tmpi = not context.opts.mpi and context.opts.thread_mpi is not False
200
201             cmd = 'perl gmxtest.pl -mpirun mpirun -xml -nosuffix all'
202
203             # setting this stuff below is just a temporary solution,
204             # it should all be passed as a proper the runconf from outside
205             # The whole mechanism should be rethought in #1587.
206             if context.opts.phi:
207                 cmd += ' -ntomp 28'
208             elif context.opts.openmp:
209                 # OpenMP should always work when compiled in! Currently not set if
210                 # not explicitly set
211                 cmd += ' -ntomp 2'
212
213             if context.opts.gpu_id:
214                 cmd += ' -gpu_id ' + context.opts.gpu_id
215
216             if context.opts.nranks:
217                 nranks = context.opts.nranks
218             else:
219                 nranks = '2'
220
221             if context.opts.npme:
222                 cmd += ' -npme ' + context.opts.npme
223
224             if context.opts.mpi:
225                 cmd += ' -np ' + nranks
226             elif use_tmpi:
227                 cmd += ' -nt ' + nranks
228             if context.opts.double:
229                 cmd += ' -double'
230             if context.opts.asan:
231                 context.env.set_env_var('ASAN_OPTIONS', 'detect_leaks=0')
232             context.run_cmd(cmd, shell=True, failure_message='Regression tests failed to execute')