Split lines with many copyright years
[alexxy/gromacs.git] / src / gromacs / utility / binaryinformation.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
7  * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
8  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9  * and including many others, as listed in the AUTHORS file in the
10  * top-level source directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 /*! \internal \file
39  * \brief Implements functionality for printing information about the
40  * currently running binary
41  *
42  * \ingroup module_utility
43  */
44 #include "gmxpre.h"
45
46 #include "binaryinformation.h"
47
48 #include "config.h"
49
50 #if GMX_FFT_FFTW3 || GMX_FFT_ARMPL_FFTW3
51 // Needed for construction of the FFT library description string
52 #    include <fftw3.h>
53 #endif
54
55 #ifdef HAVE_LIBMKL
56 #    include <mkl.h>
57 #endif
58
59 #if HAVE_EXTRAE
60 #    include <extrae_user_events.h>
61 #endif
62
63 #if GMX_USE_HWLOC
64 #    include <hwloc.h>
65 #endif
66
67 #include <cstdio>
68 #include <cstdlib>
69 #include <cstring>
70
71 #include <algorithm>
72 #include <array>
73 #include <string>
74
75 /* This file is completely threadsafe - keep it that way! */
76
77 #include "buildinfo.h"
78 #include "gromacs/utility/arraysize.h"
79 #include "gromacs/utility/baseversion.h"
80 #include "gromacs/utility/exceptions.h"
81 #include "gromacs/utility/gmxassert.h"
82 #include "gromacs/utility/path.h"
83 #include "gromacs/utility/programcontext.h"
84 #include "gromacs/utility/stringutil.h"
85 #include "gromacs/utility/sysinfo.h"
86 #include "gromacs/utility/textwriter.h"
87
88 #include "cuda_version_information.h"
89
90 namespace
91 {
92
93 using gmx::formatString;
94
95 //! \cond Doxygen does not need to care about most of this stuff, and the macro usage is painful to document
96
97 int centeringOffset(int width, int length)
98 {
99     return std::max(width - length, 0) / 2;
100 }
101
102 std::string formatCentered(int width, const char* text)
103 {
104     const int offset = centeringOffset(width, std::strlen(text));
105     return formatString("%*s%s", offset, "", text);
106 }
107
108 void printCopyright(gmx::TextWriter* writer)
109 {
110     static const char* const Contributors[] = {
111         "Emile Apol",         "Rossen Apostolov",   "Paul Bauer",         "Herman J.C. Berendsen",
112         "Par Bjelkmar",       "Christian Blau",     "Viacheslav Bolnykh", "Kevin Boyd",
113         "Aldert van Buuren",  "Rudi van Drunen",    "Anton Feenstra",     "Alan Gray",
114         "Gerrit Groenhof",    "Anca Hamuraru",      "Vincent Hindriksen", "M. Eric Irrgang",
115         "Aleksei Iupinov",    "Christoph Junghans", "Joe Jordan",         "Dimitrios Karkoulis",
116         "Peter Kasson",       "Jiri Kraus",         "Carsten Kutzner",    "Per Larsson",
117         "Justin A. Lemkul",   "Viveca Lindahl",     "Magnus Lundborg",    "Erik Marklund",
118         "Pascal Merz",        "Pieter Meulenhoff",  "Teemu Murtola",      "Szilard Pall",
119         "Sander Pronk",       "Roland Schulz",      "Michael Shirts",     "Alexey Shvetsov",
120         "Alfons Sijbers",     "Peter Tieleman",     "Jon Vincent",        "Teemu Virolainen",
121         "Christian Wennberg", "Maarten Wolf",       "Artem Zhmurov"
122     };
123     static const char* const CopyrightText[] = {
124         "Copyright (c) 1991-2000, University of Groningen, The Netherlands.",
125         "Copyright (c) 2001-2019, The GROMACS development team at",
126         "Uppsala University, Stockholm University and", "the Royal Institute of Technology, Sweden.",
127         "check out http://www.gromacs.org for more information."
128     };
129
130 #define NCONTRIBUTORS static_cast<int>(asize(Contributors))
131 #define NCR static_cast<int>(asize(CopyrightText))
132
133     // TODO a centering behaviour of TextWriter could be useful here
134     writer->writeLine(formatCentered(78, "GROMACS is written by:"));
135     for (int i = 0; i < NCONTRIBUTORS;)
136     {
137         for (int j = 0; j < 4 && i < NCONTRIBUTORS; ++j, ++i)
138         {
139             const int            width = 18;
140             std::array<char, 30> buf;
141             const int            offset = centeringOffset(width, strlen(Contributors[i]));
142             GMX_RELEASE_ASSERT(static_cast<int>(strlen(Contributors[i])) + offset < gmx::ssize(buf),
143                                "Formatting buffer is not long enough");
144             std::fill(buf.begin(), buf.begin() + offset, ' ');
145             std::strncpy(buf.data() + offset, Contributors[i], gmx::ssize(buf) - offset);
146             writer->writeString(formatString(" %-*s", width, buf.data()));
147         }
148         writer->ensureLineBreak();
149     }
150     writer->writeLine(formatCentered(78, "and the project leaders:"));
151     writer->writeLine(
152             formatCentered(78, "Mark Abraham, Berk Hess, Erik Lindahl, and David van der Spoel"));
153     writer->ensureEmptyLine();
154     for (int i = 0; i < NCR; ++i)
155     {
156         writer->writeLine(CopyrightText[i]);
157     }
158     writer->ensureEmptyLine();
159
160     // Folding At Home has different licence to allow digital
161     // signatures in GROMACS, so does not need to show the normal
162     // license statement.
163     if (!GMX_FAHCORE)
164     {
165         writer->writeLine("GROMACS is free software; you can redistribute it and/or modify it");
166         writer->writeLine("under the terms of the GNU Lesser General Public License");
167         writer->writeLine("as published by the Free Software Foundation; either version 2.1");
168         writer->writeLine("of the License, or (at your option) any later version.");
169     }
170 }
171
172 // Construct a string that describes the library that provides FFT support to this build
173 const char* getFftDescriptionString()
174 {
175 // Define the FFT description string
176 #if GMX_FFT_FFTW3 || GMX_FFT_ARMPL_FFTW3
177 #    if GMX_NATIVE_WINDOWS
178     // Don't buy trouble
179     return "fftw3";
180 #    else
181     // Use the version string provided by libfftw3
182 #        if GMX_DOUBLE
183     return fftw_version;
184 #        else
185     return fftwf_version;
186 #        endif
187 #    endif
188 #endif
189 #if GMX_FFT_MKL
190     return "Intel MKL";
191 #endif
192 #if GMX_FFT_FFTPACK
193     return "fftpack (built-in)";
194 #endif
195 };
196
197 void gmx_print_version_info(gmx::TextWriter* writer)
198 {
199     writer->writeLine(formatString("GROMACS version:    %s", gmx_version()));
200     const char* const git_hash = gmx_version_git_full_hash();
201     if (git_hash[0] != '\0')
202     {
203         writer->writeLine(formatString("GIT SHA1 hash:      %s", git_hash));
204     }
205     const char* const base_hash = gmx_version_git_central_base_hash();
206     if (base_hash[0] != '\0')
207     {
208         writer->writeLine(formatString("Branched from:      %s", base_hash));
209     }
210     const char* const releaseSourceChecksum = gmxReleaseSourceChecksum();
211     const char* const currentSourceChecksum = gmxCurrentSourceChecksum();
212     if (releaseSourceChecksum[0] != '\0')
213     {
214         if (std::strcmp(releaseSourceChecksum, "NoChecksumFile") == 0)
215         {
216             writer->writeLine(formatString(
217                     "The source code this program was compiled from has not been verified because "
218                     "the reference checksum was missing during compilation. This means you have an "
219                     "incomplete GROMACS distribution, please make sure to download an intact "
220                     "source distribution and compile that before proceeding."));
221             writer->writeLine(formatString("Computed checksum: %s", currentSourceChecksum));
222         }
223         else if (std::strcmp(releaseSourceChecksum, "NoPythonAvailable") == 0)
224         {
225             writer->writeLine(
226                     formatString("Build source could not be verified, because the checksum could "
227                                  "not be computed."));
228         }
229         else if (std::strcmp(releaseSourceChecksum, currentSourceChecksum) != 0)
230         {
231             writer->writeLine(formatString(
232                     "This program has been built from source code that has been altered and does "
233                     "not match the code released as part of the official GROMACS version %s. If "
234                     "you did not intend to use an altered GROMACS version, make sure to download "
235                     "an intact source distribution and compile that before proceeding.",
236                     gmx_version()));
237             writer->writeLine(formatString(
238                     "If you have modified the source code, you are strongly encouraged to set your "
239                     "custom version suffix (using -DGMX_VERSION_STRING_OF_FORK) which will can "
240                     "help later with scientific reproducibility but also when reporting bugs."));
241             writer->writeLine(formatString("Release checksum: %s", releaseSourceChecksum));
242             writer->writeLine(formatString("Computed checksum: %s", currentSourceChecksum));
243         }
244         else
245         {
246             writer->writeLine(formatString("Verified release checksum is %s", releaseSourceChecksum));
247         }
248     }
249
250
251 #if GMX_DOUBLE
252     writer->writeLine("Precision:          double");
253 #else
254     writer->writeLine("Precision:          single");
255 #endif
256     writer->writeLine(formatString("Memory model:       %u bit", static_cast<unsigned>(8 * sizeof(void*))));
257
258 #if GMX_THREAD_MPI
259     writer->writeLine("MPI library:        thread_mpi");
260 #elif GMX_MPI
261     writer->writeLine("MPI library:        MPI");
262 #else
263     writer->writeLine("MPI library:        none");
264 #endif
265 #if GMX_OPENMP
266     writer->writeLine(formatString("OpenMP support:     enabled (GMX_OPENMP_MAX_THREADS = %d)",
267                                    GMX_OPENMP_MAX_THREADS));
268 #else
269     writer->writeLine("OpenMP support:     disabled");
270 #endif
271     writer->writeLine(formatString("GPU support:        %s", getGpuImplementationString()));
272     writer->writeLine(formatString("SIMD instructions:  %s", GMX_SIMD_STRING));
273     writer->writeLine(formatString("FFT library:        %s", getFftDescriptionString()));
274     writer->writeLine(formatString("RDTSCP usage:       %s", HAVE_RDTSCP ? "enabled" : "disabled"));
275 #if GMX_USE_TNG
276     writer->writeLine("TNG support:        enabled");
277 #else
278     writer->writeLine("TNG support:        disabled");
279 #endif
280 #if GMX_USE_HWLOC
281     writer->writeLine(formatString("Hwloc support:      hwloc-%s", HWLOC_VERSION));
282 #else
283     writer->writeLine("Hwloc support:      disabled");
284 #endif
285 #if HAVE_EXTRAE
286     unsigned major, minor, revision;
287     Extrae_get_version(&major, &minor, &revision);
288     writer->writeLine(formatString("Tracing support:    enabled. Using Extrae-%d.%d.%d", major,
289                                    minor, revision));
290 #else
291     writer->writeLine("Tracing support:    disabled");
292 #endif
293
294
295     /* TODO: The below strings can be quite long, so it would be nice to wrap
296      * them. Can wait for later, as the master branch has ready code to do all
297      * that. */
298     writer->writeLine(formatString("C compiler:         %s", BUILD_C_COMPILER));
299     writer->writeLine(formatString("C compiler flags:   %s", BUILD_CFLAGS));
300     writer->writeLine(formatString("C++ compiler:       %s", BUILD_CXX_COMPILER));
301     writer->writeLine(formatString("C++ compiler flags: %s", BUILD_CXXFLAGS));
302 #ifdef HAVE_LIBMKL
303     /* MKL might be used for LAPACK/BLAS even if FFTs use FFTW, so keep it separate */
304     writer->writeLine(formatString("Linked with Intel MKL version %d.%d.%d.", __INTEL_MKL__,
305                                    __INTEL_MKL_MINOR__, __INTEL_MKL_UPDATE__));
306 #endif
307 #if GMX_GPU == GMX_GPU_OPENCL
308     writer->writeLine(formatString("OpenCL include dir: %s", OPENCL_INCLUDE_DIR));
309     writer->writeLine(formatString("OpenCL library:     %s", OPENCL_LIBRARY));
310     writer->writeLine(formatString("OpenCL version:     %s", OPENCL_VERSION_STRING));
311 #endif
312 #if GMX_GPU == GMX_GPU_CUDA
313     writer->writeLine(formatString("CUDA compiler:      %s", CUDA_COMPILER_INFO));
314     writer->writeLine(formatString("CUDA compiler flags:%s", CUDA_COMPILER_FLAGS));
315     writer->writeLine("CUDA driver:        " + gmx::getCudaDriverVersionString());
316     writer->writeLine("CUDA runtime:       " + gmx::getCudaRuntimeVersionString());
317 #endif
318 }
319
320 //! \endcond
321
322 } // namespace
323
324 namespace gmx
325 {
326
327 BinaryInformationSettings::BinaryInformationSettings() :
328     bExtendedInfo_(false),
329     bCopyright_(false),
330     bProcessId_(false),
331     bGeneratedByHeader_(false),
332     prefix_(""),
333     suffix_("")
334 {
335 }
336
337 void printBinaryInformation(FILE* fp, const IProgramContext& programContext)
338 {
339     TextWriter writer(fp);
340     printBinaryInformation(&writer, programContext, BinaryInformationSettings());
341 }
342
343 void printBinaryInformation(FILE*                            fp,
344                             const IProgramContext&           programContext,
345                             const BinaryInformationSettings& settings)
346 {
347     try
348     {
349         TextWriter writer(fp);
350         printBinaryInformation(&writer, programContext, settings);
351     }
352     GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
353 }
354
355 void printBinaryInformation(TextWriter*                      writer,
356                             const IProgramContext&           programContext,
357                             const BinaryInformationSettings& settings)
358 {
359     // TODO Perhaps the writer could be configured with the prefix and
360     // suffix strings from the settings?
361     const char* prefix          = settings.prefix_;
362     const char* suffix          = settings.suffix_;
363     const char* precisionString = "";
364 #if GMX_DOUBLE
365     precisionString = " (double precision)";
366 #endif
367     const char* const name = programContext.displayName();
368     if (settings.bGeneratedByHeader_)
369     {
370         writer->writeLine(formatString("%sCreated by:%s", prefix, suffix));
371     }
372     // TODO: It would be nice to know here whether we are really running a
373     // Gromacs binary or some other binary that is calling Gromacs; we
374     // could then print "%s is part of GROMACS" or some alternative text.
375     std::string title = formatString(":-) GROMACS - %s, %s%s (-:", name, gmx_version(), precisionString);
376     const int indent =
377             centeringOffset(78 - std::strlen(prefix) - std::strlen(suffix), title.length()) + 1;
378     writer->writeLine(formatString("%s%*c%s%s", prefix, indent, ' ', title.c_str(), suffix));
379     writer->writeLine(formatString("%s%s", prefix, suffix));
380     if (settings.bCopyright_)
381     {
382         GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',
383                            "Prefix/suffix not supported with copyright");
384         printCopyright(writer);
385         writer->ensureEmptyLine();
386         // This line is printed again after the copyright notice to make it
387         // appear together with all the other information, so that it is not
388         // necessary to read stuff above the copyright notice.
389         // The line above the copyright notice puts the copyright notice is
390         // context, though.
391         writer->writeLine(formatString("%sGROMACS:      %s, version %s%s%s", prefix, name,
392                                        gmx_version(), precisionString, suffix));
393     }
394     const char* const binaryPath = programContext.fullBinaryPath();
395     if (!gmx::isNullOrEmpty(binaryPath))
396     {
397         writer->writeLine(formatString("%sExecutable:   %s%s", prefix, binaryPath, suffix));
398     }
399     const gmx::InstallationPrefixInfo installPrefix = programContext.installationPrefix();
400     if (!gmx::isNullOrEmpty(installPrefix.path))
401     {
402         writer->writeLine(formatString("%sData prefix:  %s%s%s", prefix, installPrefix.path,
403                                        installPrefix.bSourceLayout ? " (source tree)" : "", suffix));
404     }
405     const std::string workingDir = Path::getWorkingDirectory();
406     if (!workingDir.empty())
407     {
408         writer->writeLine(formatString("%sWorking dir:  %s%s", prefix, workingDir.c_str(), suffix));
409     }
410     if (settings.bProcessId_)
411     {
412         writer->writeLine(formatString("%sProcess ID:   %d%s", prefix, gmx_getpid(), suffix));
413     }
414     const char* const commandLine = programContext.commandLine();
415     if (!gmx::isNullOrEmpty(commandLine))
416     {
417         writer->writeLine(formatString("%sCommand line:%s\n%s  %s%s", prefix, suffix, prefix,
418                                        commandLine, suffix));
419     }
420     if (settings.bExtendedInfo_)
421     {
422         GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',
423                            "Prefix/suffix not supported with extended info");
424         writer->ensureEmptyLine();
425         gmx_print_version_info(writer);
426     }
427 }
428
429 } // namespace gmx