Remove unused function generate_excls and make clean_excls static
[gromacs.git] / src / gromacs / utility / binaryinformation.cpp
blob390a0385e972f23986e6e545829277cc5b22c84f
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,2018,2019, 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 || GMX_FFT_ARMPL_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_USE_HWLOC
63 #include <hwloc.h>
64 #endif
66 #include <cstdio>
67 #include <cstdlib>
68 #include <cstring>
70 #include <algorithm>
71 #include <array>
72 #include <string>
74 /* This file is completely threadsafe - keep it that way! */
76 #include "buildinfo.h"
77 #include "gromacs/utility/arraysize.h"
78 #include "gromacs/utility/baseversion.h"
79 #include "gromacs/utility/exceptions.h"
80 #include "gromacs/utility/gmxassert.h"
81 #include "gromacs/utility/path.h"
82 #include "gromacs/utility/programcontext.h"
83 #include "gromacs/utility/stringutil.h"
84 #include "gromacs/utility/sysinfo.h"
85 #include "gromacs/utility/textwriter.h"
87 #include "cuda_version_information.h"
89 namespace
92 using gmx::formatString;
94 //! \cond Doxygen does not need to care about most of this stuff, and the macro usage is painful to document
96 int centeringOffset(int width, int length)
98 return std::max(width - length, 0) / 2;
101 std::string formatCentered(int width, const char *text)
103 const int offset = centeringOffset(width, std::strlen(text));
104 return formatString("%*s%s", offset, "", text);
107 void printCopyright(gmx::TextWriter *writer)
109 static const char * const Contributors[] = {
110 "Emile Apol",
111 "Rossen Apostolov",
112 "Paul Bauer",
113 "Herman J.C. Berendsen",
114 "Par Bjelkmar",
115 "Christian Blau",
116 "Viacheslav Bolnykh",
117 "Kevin Boyd",
118 "Aldert van Buuren",
119 "Rudi van Drunen",
120 "Anton Feenstra",
121 "Alan Gray",
122 "Gerrit Groenhof",
123 "Anca Hamuraru",
124 "Vincent Hindriksen",
125 "M. Eric Irrgang",
126 "Aleksei Iupinov",
127 "Christoph Junghans",
128 "Joe Jordan",
129 "Dimitrios Karkoulis",
130 "Peter Kasson",
131 "Jiri Kraus",
132 "Carsten Kutzner",
133 "Per Larsson",
134 "Justin A. Lemkul",
135 "Viveca Lindahl",
136 "Magnus Lundborg",
137 "Erik Marklund",
138 "Pascal Merz",
139 "Pieter Meulenhoff",
140 "Teemu Murtola",
141 "Szilard Pall",
142 "Sander Pronk",
143 "Roland Schulz",
144 "Michael Shirts",
145 "Alexey Shvetsov",
146 "Alfons Sijbers",
147 "Peter Tieleman",
148 "Jon Vincent",
149 "Teemu Virolainen",
150 "Christian Wennberg",
151 "Maarten Wolf",
152 "Artem Zhmurov"
154 static const char * const CopyrightText[] = {
155 "Copyright (c) 1991-2000, University of Groningen, The Netherlands.",
156 "Copyright (c) 2001-2019, The GROMACS development team at",
157 "Uppsala University, Stockholm University and",
158 "the Royal Institute of Technology, Sweden.",
159 "check out http://www.gromacs.org for more information."
162 #define NCONTRIBUTORS static_cast<int>(asize(Contributors))
163 #define NCR static_cast<int>(asize(CopyrightText))
165 // TODO a centering behaviour of TextWriter could be useful here
166 writer->writeLine(formatCentered(78, "GROMACS is written by:"));
167 for (int i = 0; i < NCONTRIBUTORS; )
169 for (int j = 0; j < 4 && i < NCONTRIBUTORS; ++j, ++i)
171 const int width = 18;
172 std::array<char, 30> buf;
173 const int offset = centeringOffset(width, strlen(Contributors[i]));
174 GMX_RELEASE_ASSERT(static_cast<int>(strlen(Contributors[i])) + offset < gmx::ssize(buf),
175 "Formatting buffer is not long enough");
176 std::fill(buf.begin(), buf.begin()+offset, ' ');
177 std::strncpy(buf.data()+offset, Contributors[i], gmx::ssize(buf) - offset);
178 writer->writeString(formatString(" %-*s", width, buf.data()));
180 writer->ensureLineBreak();
182 writer->writeLine(formatCentered(78, "and the project leaders:"));
183 writer->writeLine(formatCentered(78, "Mark Abraham, Berk Hess, Erik Lindahl, and David van der Spoel"));
184 writer->ensureEmptyLine();
185 for (int i = 0; i < NCR; ++i)
187 writer->writeLine(CopyrightText[i]);
189 writer->ensureEmptyLine();
191 // Folding At Home has different licence to allow digital
192 // signatures in GROMACS, so does not need to show the normal
193 // license statement.
194 if (!GMX_FAHCORE)
196 writer->writeLine("GROMACS is free software; you can redistribute it and/or modify it");
197 writer->writeLine("under the terms of the GNU Lesser General Public License");
198 writer->writeLine("as published by the Free Software Foundation; either version 2.1");
199 writer->writeLine("of the License, or (at your option) any later version.");
203 // Construct a string that describes the library that provides FFT support to this build
204 const char *getFftDescriptionString()
206 // Define the FFT description string
207 #if GMX_FFT_FFTW3 || GMX_FFT_ARMPL_FFTW3
208 # if GMX_NATIVE_WINDOWS
209 // Don't buy trouble
210 return "fftw3";
211 # else
212 // Use the version string provided by libfftw3
213 # if GMX_DOUBLE
214 return fftw_version;
215 # else
216 return fftwf_version;
217 # endif
218 # endif
219 #endif
220 #if GMX_FFT_MKL
221 return "Intel MKL";
222 #endif
223 #if GMX_FFT_FFTPACK
224 return "fftpack (built-in)";
225 #endif
228 void gmx_print_version_info(gmx::TextWriter *writer)
230 writer->writeLine(formatString("GROMACS version: %s", gmx_version()));
231 const char *const git_hash = gmx_version_git_full_hash();
232 if (git_hash[0] != '\0')
234 writer->writeLine(formatString("GIT SHA1 hash: %s", git_hash));
236 const char *const base_hash = gmx_version_git_central_base_hash();
237 if (base_hash[0] != '\0')
239 writer->writeLine(formatString("Branched from: %s", base_hash));
242 #if GMX_DOUBLE
243 writer->writeLine("Precision: double");
244 #else
245 writer->writeLine("Precision: single");
246 #endif
247 writer->writeLine(formatString("Memory model: %u bit", static_cast<unsigned>(8*sizeof(void *))));
249 #if GMX_THREAD_MPI
250 writer->writeLine("MPI library: thread_mpi");
251 #elif GMX_MPI
252 writer->writeLine("MPI library: MPI");
253 #else
254 writer->writeLine("MPI library: none");
255 #endif
256 #if GMX_OPENMP
257 writer->writeLine(formatString("OpenMP support: enabled (GMX_OPENMP_MAX_THREADS = %d)", GMX_OPENMP_MAX_THREADS));
258 #else
259 writer->writeLine("OpenMP support: disabled");
260 #endif
261 writer->writeLine(formatString("GPU support: %s", getGpuImplementationString()));
262 writer->writeLine(formatString("SIMD instructions: %s", GMX_SIMD_STRING));
263 writer->writeLine(formatString("FFT library: %s", getFftDescriptionString()));
264 writer->writeLine(formatString("RDTSCP usage: %s", HAVE_RDTSCP ? "enabled" : "disabled"));
265 #if GMX_USE_TNG
266 writer->writeLine("TNG support: enabled");
267 #else
268 writer->writeLine("TNG support: disabled");
269 #endif
270 #if GMX_USE_HWLOC
271 writer->writeLine(formatString("Hwloc support: hwloc-%s", HWLOC_VERSION));
272 #else
273 writer->writeLine("Hwloc support: disabled");
274 #endif
275 #if HAVE_EXTRAE
276 unsigned major, minor, revision;
277 Extrae_get_version(&major, &minor, &revision);
278 writer->writeLine(formatString("Tracing support: enabled. Using Extrae-%d.%d.%d", major, minor, revision));
279 #else
280 writer->writeLine("Tracing support: disabled");
281 #endif
284 /* TODO: The below strings can be quite long, so it would be nice to wrap
285 * them. Can wait for later, as the master branch has ready code to do all
286 * that. */
287 writer->writeLine(formatString("C compiler: %s", BUILD_C_COMPILER));
288 writer->writeLine(formatString("C compiler flags: %s", BUILD_CFLAGS));
289 writer->writeLine(formatString("C++ compiler: %s", BUILD_CXX_COMPILER));
290 writer->writeLine(formatString("C++ compiler flags: %s", BUILD_CXXFLAGS));
291 #ifdef HAVE_LIBMKL
292 /* MKL might be used for LAPACK/BLAS even if FFTs use FFTW, so keep it separate */
293 writer->writeLine(formatString("Linked with Intel MKL version %d.%d.%d.",
294 __INTEL_MKL__, __INTEL_MKL_MINOR__, __INTEL_MKL_UPDATE__));
295 #endif
296 #if GMX_GPU == GMX_GPU_OPENCL
297 writer->writeLine(formatString("OpenCL include dir: %s", OPENCL_INCLUDE_DIR));
298 writer->writeLine(formatString("OpenCL library: %s", OPENCL_LIBRARY));
299 writer->writeLine(formatString("OpenCL version: %s", OPENCL_VERSION_STRING));
300 #endif
301 #if GMX_GPU == GMX_GPU_CUDA
302 writer->writeLine(formatString("CUDA compiler: %s", CUDA_COMPILER_INFO));
303 writer->writeLine(formatString("CUDA compiler flags:%s", CUDA_COMPILER_FLAGS));
304 writer->writeLine("CUDA driver: " + gmx::getCudaDriverVersionString());
305 writer->writeLine("CUDA runtime: " + gmx::getCudaRuntimeVersionString());
306 #endif
309 //! \endcond
311 } // namespace
313 namespace gmx
316 BinaryInformationSettings::BinaryInformationSettings()
317 : bExtendedInfo_(false), bCopyright_(false),
318 bProcessId_(false),
319 bGeneratedByHeader_(false), prefix_(""), suffix_("")
323 void printBinaryInformation(FILE *fp,
324 const IProgramContext &programContext)
326 TextWriter writer(fp);
327 printBinaryInformation(&writer, programContext, BinaryInformationSettings());
330 void printBinaryInformation(FILE *fp,
331 const IProgramContext &programContext,
332 const BinaryInformationSettings &settings)
336 TextWriter writer(fp);
337 printBinaryInformation(&writer, programContext, settings);
339 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
342 void printBinaryInformation(TextWriter *writer,
343 const IProgramContext &programContext,
344 const BinaryInformationSettings &settings)
346 // TODO Perhaps the writer could be configured with the prefix and
347 // suffix strings from the settings?
348 const char *prefix = settings.prefix_;
349 const char *suffix = settings.suffix_;
350 const char *precisionString = "";
351 #if GMX_DOUBLE
352 precisionString = " (double precision)";
353 #endif
354 const char *const name = programContext.displayName();
355 if (settings.bGeneratedByHeader_)
357 writer->writeLine(formatString("%sCreated by:%s", prefix, suffix));
359 // TODO: It would be nice to know here whether we are really running a
360 // Gromacs binary or some other binary that is calling Gromacs; we
361 // could then print "%s is part of GROMACS" or some alternative text.
362 std::string title
363 = formatString(":-) GROMACS - %s, %s%s (-:", name, gmx_version(), precisionString);
364 const int indent
365 = centeringOffset(78 - std::strlen(prefix) - std::strlen(suffix), title.length()) + 1;
366 writer->writeLine(formatString("%s%*c%s%s", prefix, indent, ' ', title.c_str(), suffix));
367 writer->writeLine(formatString("%s%s", prefix, suffix));
368 if (settings.bCopyright_)
370 GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',
371 "Prefix/suffix not supported with copyright");
372 printCopyright(writer);
373 writer->ensureEmptyLine();
374 // This line is printed again after the copyright notice to make it
375 // appear together with all the other information, so that it is not
376 // necessary to read stuff above the copyright notice.
377 // The line above the copyright notice puts the copyright notice is
378 // context, though.
379 writer->writeLine(formatString("%sGROMACS: %s, version %s%s%s", prefix, name,
380 gmx_version(), precisionString, suffix));
382 const char *const binaryPath = programContext.fullBinaryPath();
383 if (!gmx::isNullOrEmpty(binaryPath))
385 writer->writeLine(formatString("%sExecutable: %s%s", prefix, binaryPath, suffix));
387 const gmx::InstallationPrefixInfo installPrefix = programContext.installationPrefix();
388 if (!gmx::isNullOrEmpty(installPrefix.path))
390 writer->writeLine(formatString("%sData prefix: %s%s%s", prefix, installPrefix.path,
391 installPrefix.bSourceLayout ? " (source tree)" : "", suffix));
393 const std::string workingDir = Path::getWorkingDirectory();
394 if (!workingDir.empty())
396 writer->writeLine(formatString("%sWorking dir: %s%s", prefix, workingDir.c_str(), suffix));
398 if (settings.bProcessId_)
400 writer->writeLine(formatString("%sProcess ID: %d%s", prefix, gmx_getpid(), suffix));
402 const char *const commandLine = programContext.commandLine();
403 if (!gmx::isNullOrEmpty(commandLine))
405 writer->writeLine(formatString("%sCommand line:%s\n%s %s%s",
406 prefix, suffix, prefix, commandLine, suffix));
408 if (settings.bExtendedInfo_)
410 GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',
411 "Prefix/suffix not supported with extended info");
412 writer->ensureEmptyLine();
413 gmx_print_version_info(writer);
417 } // namespace gmx