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