Add conserved quantity for Berendsen P-couple
[gromacs.git] / src / gromacs / utility / binaryinformation.cpp
blobf805b1f003ee681b9dfef83d2088888755056fb2
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
37 /*! \internal \file
38 * \brief Implements functionality for printing information about the
39 * currently running binary
41 * \ingroup module_utility
43 #include "gmxpre.h"
45 #include "binaryinformation.h"
47 #include "config.h"
49 #if GMX_FFT_FFTW3
50 // Needed for construction of the FFT library description string
51 #include <fftw3.h>
52 #endif
54 #ifdef HAVE_LIBMKL
55 #include <mkl.h>
56 #endif
58 #if HAVE_EXTRAE
59 #include <extrae_user_events.h>
60 #endif
62 #if GMX_HWLOC
63 #include <hwloc.h>
64 #endif
66 #include <cstdio>
67 #include <cstdlib>
68 #include <cstring>
70 #include <algorithm>
71 #include <string>
73 /* This file is completely threadsafe - keep it that way! */
75 #include "buildinfo.h"
76 #include "gromacs/utility/arraysize.h"
77 #include "gromacs/utility/baseversion.h"
78 #include "gromacs/utility/exceptions.h"
79 #include "gromacs/utility/gmxassert.h"
80 #include "gromacs/utility/path.h"
81 #include "gromacs/utility/programcontext.h"
82 #include "gromacs/utility/stringutil.h"
83 #include "gromacs/utility/textwriter.h"
85 #include "cuda_version_information.h"
87 namespace
90 using gmx::formatString;
92 //! \cond Doxygen does not need to care about most of this stuff, and the macro usage is painful to document
94 int centeringOffset(int width, int length)
96 return std::max(width - length, 0) / 2;
99 std::string formatCentered(int width, const char *text)
101 const int offset = centeringOffset(width, std::strlen(text));
102 return formatString("%*s%s", offset, "", text);
105 void printCopyright(gmx::TextWriter *writer)
107 static const char * const Contributors[] = {
108 "Emile Apol",
109 "Rossen Apostolov",
110 "Herman J.C. Berendsen",
111 "Par Bjelkmar",
112 "Aldert van Buuren",
113 "Rudi van Drunen",
114 "Anton Feenstra",
115 "Gerrit Groenhof",
116 "Christoph Junghans",
117 "Anca Hamuraru",
118 "Vincent Hindriksen",
119 "Dimitrios Karkoulis",
120 "Peter Kasson",
121 "Jiri Kraus",
122 "Carsten Kutzner",
123 "Per Larsson",
124 "Justin A. Lemkul",
125 "Magnus Lundborg",
126 "Pieter Meulenhoff",
127 "Erik Marklund",
128 "Teemu Murtola",
129 "Szilard Pall",
130 "Sander Pronk",
131 "Roland Schulz",
132 "Alexey Shvetsov",
133 "Michael Shirts",
134 "Alfons Sijbers",
135 "Peter Tieleman",
136 "Teemu Virolainen",
137 "Christian Wennberg",
138 "Maarten Wolf"
140 static const char * const CopyrightText[] = {
141 "Copyright (c) 1991-2000, University of Groningen, The Netherlands.",
142 "Copyright (c) 2001-2017, The GROMACS development team at",
143 "Uppsala University, Stockholm University and",
144 "the Royal Institute of Technology, Sweden.",
145 "check out http://www.gromacs.org for more information."
147 static const char * const LicenseText[] = {
148 "GROMACS is free software; you can redistribute it and/or modify it",
149 "under the terms of the GNU Lesser General Public License",
150 "as published by the Free Software Foundation; either version 2.1",
151 "of the License, or (at your option) any later version."
154 #define NCONTRIBUTORS (int)asize(Contributors)
155 #define NCR (int)asize(CopyrightText)
157 // FAH has an exception permission from LGPL to allow digital signatures in Gromacs.
158 #ifdef GMX_FAHCORE
159 #define NLICENSE 0
160 #else
161 #define NLICENSE (int)asize(LicenseText)
162 #endif
164 // TODO a centering behaviour of TextWriter could be useful here
165 writer->writeLine(formatCentered(78, "GROMACS is written by:"));
166 for (int i = 0; i < NCONTRIBUTORS; )
168 for (int j = 0; j < 4 && i < NCONTRIBUTORS; ++j, ++i)
170 const int width = 18;
171 char buf[30];
172 const int offset = centeringOffset(width, strlen(Contributors[i]));
173 GMX_RELEASE_ASSERT(strlen(Contributors[i]) + offset < asize(buf),
174 "Formatting buffer is not long enough");
175 std::fill(buf, buf+width, ' ');
176 std::strcpy(buf+offset, Contributors[i]);
177 writer->writeString(formatString(" %-*s", width, buf));
179 writer->ensureLineBreak();
181 writer->writeLine(formatCentered(78, "and the project leaders:"));
182 writer->writeLine(formatCentered(78, "Mark Abraham, Berk Hess, Erik Lindahl, and David van der Spoel"));
183 writer->ensureEmptyLine();
184 for (int i = 0; i < NCR; ++i)
186 writer->writeLine(CopyrightText[i]);
188 writer->ensureEmptyLine();
189 for (int i = 0; i < NLICENSE; ++i)
191 writer->writeLine(LicenseText[i]);
195 // Construct a string that describes the library that provides FFT support to this build
196 const char *getFftDescriptionString()
198 // Define the FFT description string
199 #if GMX_FFT_FFTW3
200 # if GMX_NATIVE_WINDOWS
201 // Don't buy trouble
202 return "fftw3";
203 # else
204 // Use the version string provided by libfftw3
205 # if GMX_DOUBLE
206 return fftw_version;
207 # else
208 return fftwf_version;
209 # endif
210 # endif
211 #endif
212 #if GMX_FFT_MKL
213 return "Intel MKL";
214 #endif
215 #if GMX_FFT_FFTPACK
216 return "fftpack (built-in)";
217 #endif
220 void gmx_print_version_info(gmx::TextWriter *writer)
222 writer->writeLine(formatString("GROMACS version: %s", gmx_version()));
223 const char *const git_hash = gmx_version_git_full_hash();
224 if (git_hash[0] != '\0')
226 writer->writeLine(formatString("GIT SHA1 hash: %s", git_hash));
228 const char *const base_hash = gmx_version_git_central_base_hash();
229 if (base_hash[0] != '\0')
231 writer->writeLine(formatString("Branched from: %s", base_hash));
234 #if GMX_DOUBLE
235 writer->writeLine("Precision: double");
236 #else
237 writer->writeLine("Precision: single");
238 #endif
239 writer->writeLine(formatString("Memory model: %u bit", (unsigned)(8*sizeof(void *))));
241 #if GMX_THREAD_MPI
242 writer->writeLine("MPI library: thread_mpi");
243 #elif GMX_MPI
244 writer->writeLine("MPI library: MPI");
245 #else
246 writer->writeLine("MPI library: none");
247 #endif
248 #if GMX_OPENMP
249 writer->writeLine(formatString("OpenMP support: enabled (GMX_OPENMP_MAX_THREADS = %d)", GMX_OPENMP_MAX_THREADS));
250 #else
251 writer->writeLine("OpenMP support: disabled");
252 #endif
253 writer->writeLine(formatString("GPU support: %s", getGpuImplementationString()));
254 writer->writeLine(formatString("SIMD instructions: %s", GMX_SIMD_STRING));
255 writer->writeLine(formatString("FFT library: %s", getFftDescriptionString()));
256 #ifdef HAVE_RDTSCP
257 writer->writeLine("RDTSCP usage: enabled");
258 #else
259 writer->writeLine("RDTSCP usage: disabled");
260 #endif
261 #ifdef GMX_USE_TNG
262 writer->writeLine("TNG support: enabled");
263 #else
264 writer->writeLine("TNG support: disabled");
265 #endif
266 #if GMX_HWLOC
267 writer->writeLine(formatString("Hwloc support: hwloc-%d.%d.%d",
268 HWLOC_API_VERSION>>16,
269 (HWLOC_API_VERSION>>8) & 0xFF,
270 HWLOC_API_VERSION & 0xFF));
271 #else
272 writer->writeLine("Hwloc support: disabled");
273 #endif
274 #if HAVE_EXTRAE
275 unsigned major, minor, revision;
276 Extrae_get_version(&major, &minor, &revision);
277 writer->writeLine(formatString("Tracing support: enabled. Using Extrae-%d.%d.%d", major, minor, revision));
278 #else
279 writer->writeLine("Tracing support: disabled");
280 #endif
283 writer->writeLine(formatString("Built on: %s", BUILD_TIME));
284 writer->writeLine(formatString("Built by: %s", BUILD_USER));
285 writer->writeLine(formatString("Build OS/arch: %s", BUILD_HOST));
286 writer->writeLine(formatString("Build CPU vendor: %s", BUILD_CPU_VENDOR));
287 writer->writeLine(formatString("Build CPU brand: %s", BUILD_CPU_BRAND));
288 writer->writeLine(formatString("Build CPU family: %d Model: %d Stepping: %d",
289 BUILD_CPU_FAMILY, BUILD_CPU_MODEL, BUILD_CPU_STEPPING));
290 /* TODO: The below strings can be quite long, so it would be nice to wrap
291 * them. Can wait for later, as the master branch has ready code to do all
292 * that. */
293 writer->writeLine(formatString("Build CPU features: %s", BUILD_CPU_FEATURES));
294 writer->writeLine(formatString("C compiler: %s", BUILD_C_COMPILER));
295 writer->writeLine(formatString("C compiler flags: %s", BUILD_CFLAGS));
296 writer->writeLine(formatString("C++ compiler: %s", BUILD_CXX_COMPILER));
297 writer->writeLine(formatString("C++ compiler flags: %s", BUILD_CXXFLAGS));
298 #ifdef HAVE_LIBMKL
299 /* MKL might be used for LAPACK/BLAS even if FFTs use FFTW, so keep it separate */
300 writer->writeLine(formatString("Linked with Intel MKL version %d.%d.%d.",
301 __INTEL_MKL__, __INTEL_MKL_MINOR__, __INTEL_MKL_UPDATE__));
302 #endif
303 #if GMX_GPU == GMX_GPU_OPENCL
304 writer->writeLine(formatString("OpenCL include dir: %s", OPENCL_INCLUDE_DIR));
305 writer->writeLine(formatString("OpenCL library: %s", OPENCL_LIBRARY));
306 writer->writeLine(formatString("OpenCL version: %s", OPENCL_VERSION_STRING));
307 #endif
308 #if GMX_GPU == GMX_GPU_CUDA
309 writer->writeLine(formatString("CUDA compiler: %s\n", CUDA_NVCC_COMPILER_INFO));
310 writer->writeLine(formatString("CUDA compiler flags:%s\n", CUDA_NVCC_COMPILER_FLAGS));
311 auto driverVersion = gmx::getCudaDriverVersion();
312 writer->writeLine(formatString("CUDA driver: %d.%d\n", driverVersion.first, driverVersion.second));
313 auto runtimeVersion = gmx::getCudaRuntimeVersion();
314 writer->writeLine(formatString("CUDA runtime: %d.%d\n", runtimeVersion.first, runtimeVersion.second));
315 #endif
318 //! \endcond
320 } // namespace
322 namespace gmx
325 BinaryInformationSettings::BinaryInformationSettings()
326 : bExtendedInfo_(false), bCopyright_(false),
327 bGeneratedByHeader_(false), prefix_(""), suffix_("")
331 void printBinaryInformation(FILE *fp,
332 const IProgramContext &programContext)
334 TextWriter writer(fp);
335 printBinaryInformation(&writer, programContext, BinaryInformationSettings());
338 void printBinaryInformation(FILE *fp,
339 const IProgramContext &programContext,
340 const BinaryInformationSettings &settings)
344 TextWriter writer(fp);
345 printBinaryInformation(&writer, programContext, settings);
347 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
350 void printBinaryInformation(TextWriter *writer,
351 const IProgramContext &programContext,
352 const BinaryInformationSettings &settings)
354 // TODO Perhaps the writer could be configured with the prefix and
355 // suffix strings from the settings?
356 const char *prefix = settings.prefix_;
357 const char *suffix = settings.suffix_;
358 const char *precisionString = "";
359 #if GMX_DOUBLE
360 precisionString = " (double precision)";
361 #endif
362 const char *const name = programContext.displayName();
363 if (settings.bGeneratedByHeader_)
365 writer->writeLine(formatString("%sCreated by:%s", prefix, suffix));
367 // TODO: It would be nice to know here whether we are really running a
368 // Gromacs binary or some other binary that is calling Gromacs; we
369 // could then print "%s is part of GROMACS" or some alternative text.
370 std::string title
371 = formatString(":-) GROMACS - %s, %s%s (-:", name, gmx_version(), precisionString);
372 const int indent
373 = centeringOffset(78 - std::strlen(prefix) - std::strlen(suffix), title.length()) + 1;
374 writer->writeLine(formatString("%s%*c%s%s", prefix, indent, ' ', title.c_str(), suffix));
375 writer->writeLine(formatString("%s%s", prefix, suffix));
376 if (settings.bCopyright_)
378 GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',
379 "Prefix/suffix not supported with copyright");
380 printCopyright(writer);
381 writer->ensureEmptyLine();
382 // This line is printed again after the copyright notice to make it
383 // appear together with all the other information, so that it is not
384 // necessary to read stuff above the copyright notice.
385 // The line above the copyright notice puts the copyright notice is
386 // context, though.
387 writer->writeLine(formatString("%sGROMACS: %s, version %s%s%s", prefix, name,
388 gmx_version(), precisionString, suffix));
390 const char *const binaryPath = programContext.fullBinaryPath();
391 if (!gmx::isNullOrEmpty(binaryPath))
393 writer->writeLine(formatString("%sExecutable: %s%s", prefix, binaryPath, suffix));
395 const gmx::InstallationPrefixInfo installPrefix = programContext.installationPrefix();
396 if (!gmx::isNullOrEmpty(installPrefix.path))
398 writer->writeLine(formatString("%sData prefix: %s%s%s", prefix, installPrefix.path,
399 installPrefix.bSourceLayout ? " (source tree)" : "", suffix));
401 const std::string workingDir = Path::getWorkingDirectory();
402 if (!workingDir.empty())
404 writer->writeLine(formatString("%sWorking dir: %s%s", prefix, workingDir.c_str(), suffix));
406 const char *const commandLine = programContext.commandLine();
407 if (!gmx::isNullOrEmpty(commandLine))
409 writer->writeLine(formatString("%sCommand line:%s\n%s %s%s",
410 prefix, suffix, prefix, commandLine, suffix));
412 if (settings.bExtendedInfo_)
414 GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',
415 "Prefix/suffix not supported with extended info");
416 writer->ensureEmptyLine();
417 gmx_print_version_info(writer);
421 } // namespace gmx