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