version.c 7.76 KB
Newer Older
1
2
/*******************************************************************************
 * This file is part of SWIFT.
3
4
 * Copyright (C) 2012 Matthieu Schaller (matthieu.schaller@durham.ac.uk).
 * Copyright (C) 2015 Peter W. Draper (p.w.draper@durham.ac.uk).
5
 *
6
7
8
9
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
10
 *
11
12
13
14
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
15
 *
16
17
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 *
19
20
 ******************************************************************************/

21
22
23
24
25
26
/* Config parameters. */
#include "../config.h"

/* MPI headers. */
#ifdef WITH_MPI
#include <mpi.h>
27
28
29
#ifdef HAVE_METIS
#include <metis.h>
#endif
30
31
#endif

32
33
34
35
#ifdef HAVE_HDF5
#include <hdf5.h>
#endif

Matthieu Schaller's avatar
Matthieu Schaller committed
36
37
38
39
#ifdef HAVE_FFTW
#include <fftw.h>
#endif

40
/* Some standard headers. */
41
#include <stdio.h>
42
#include <string.h>
43
44

/* This object's header. */
45
#include "version.h"
46

Matthieu Schaller's avatar
Matthieu Schaller committed
47
48
49
/* Local headers. */
#include "version_string.h"

50
51
52
/**
 * @brief Return the source code git revision
 *
53
 * The SHA of the code checked out when the library was last built.
54
 * Will include -dirty if they are local modifications.
55
56
 *
 * @result the git version.
57
 */
58
const char *git_revision(void) {
59
60
  static char buf[256];
  static int initialised = 0;
61
  static const char *revision = GIT_REVISION;
62
63
  if (!initialised) {
    if (strlen(revision) == 0)
64
      sprintf(buf, "%s", "unknown");
65
    else
66
      sprintf(buf, "%s", revision);
67
68
69
    initialised = 1;
  }
  return buf;
70
}
71

72
73
74
/**
 * @brief Return the source code git branch
 *
75
76
77
 * The name of the current branch when the code was last built.
 *
 * @result git branch
78
79
 */
const char *git_branch(void) {
80
81
  static char buf[256];
  static int initialised = 0;
82
  static const char *branch = GIT_BRANCH;
83
84
  if (!initialised) {
    if (strlen(branch) == 0)
85
      sprintf(buf, "%s", "unknown");
86
    else
87
      sprintf(buf, "%s", branch);
88
89
90
    initialised = 1;
  }
  return buf;
91
92
}

93
94
/**
 * @brief The version of SWIFT
95
96
 *
 * @result the package version
97
 */
98
99
100
const char *package_version(void) {
  static const char *version = PACKAGE_VERSION;
  return version;
101
102
103
104
}

/**
 * @brief A description of the package version and code status.
105
106
 *
 * @result description of the package version
107
 */
108
109
110
111
const char *package_description(void) {
  static char buf[256];
  static int initialised = 0;
  if (!initialised) {
112
    sprintf(buf, "SWIFT version: %s, at revision: %s, branch: %s",
113
            PACKAGE_VERSION, GIT_REVISION, GIT_BRANCH);
114
115
116
    initialised = 1;
  }
  return buf;
117
}
118

119
120
121
122
123
/**
 * @brief return the name of the compiler used to build SWIFT.
 *
 * @result description of the compiler.
 */
124
const char *compiler_name(void) {
125
  static char compiler[256] = {0};
126
#if defined(__INTEL_COMPILER)
127
  sprintf(compiler, "ICC");
128
#elif defined(__clang__)
129
  sprintf(compiler, "LLVM/Clang");
130
#elif defined(__xlc__)
131
  sprintf(compiler, "IBM XL");
132
#elif defined(__GNUC__)
133
  sprintf(compiler, "GCC");
134
#endif
135
  if (strlen(compiler) == 0) sprintf(compiler, "Unknown compiler");
136
137
138
  return compiler;
}

139
140
141
142
143
/**
 * @brief return compiler version used to build SWIFT.
 *
 * @result description of the compiler.
 */
144
const char *compiler_version(void) {
145
  static char version[256] = {0};
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#if defined(__INTEL_COMPILER)
  const int major = __INTEL_COMPILER / 100;
  const int minor = __INTEL_COMPILER - major * 100;
  sprintf(version, "%i.%i.%i", major, minor, __INTEL_COMPILER_BUILD_DATE);
#elif defined(__clang__)
  sprintf(version, "%i.%i.%i", __clang_major__, __clang_minor__,
          __clang_patchlevel__);
#elif defined(__xlc__)
  const int major = __IBMC__ / 100;
  const int minor = (__IBMC__ - major * 100) / 10;
  const int patch = (__IBMC__ - major * 100 - minor * 10);
  sprintf(version, "%i.%i.%i", major, minor, patch);
#elif defined(__GNUC__)
  sprintf(version, "%i.%i.%i", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#endif
161
  if (strlen(version) == 0) sprintf(version, "Unknown version");
162
163
164
  return version;
}

165
166
167
168
169
170
/**
 * @brief return the MPI version, runtime if possible otherwise that used when
 *        built.
 *
 * @result description of the MPI version.
 */
171
const char *mpi_version(void) {
172
173
  static char version[80] = {0};

174
#ifdef WITH_MPI
175
176
  int std_version, std_subversion;

177
/* Check that the library implements the version string routine */
178
179
#ifdef MPI_MAX_LIBRARY_VERSION_STRING
  static char lib_version[MPI_MAX_LIBRARY_VERSION_STRING] = {0};
180
  int len;
181
  MPI_Get_library_version(lib_version, &len);
182

183
  /* Find first \n and truncate string to this length, can get many lines from
184
185
186
187
   * some MPIs (MPICH). */
  char *ptr = strchr(lib_version, '\n');
  if (ptr != NULL) *ptr = '\0';

188
189
  /* Also arbitrarily truncate to keep down to one line, Open MPI,
   * check for last comma and keep to ~60 chars max. */
190
  strcpy(lib_version + 60, "...");
191
192
193
  ptr = strrchr(lib_version, ',');
  if (ptr != NULL) *ptr = '\0';

194
#else
195
  /* Use autoconf guessed value. */
196
197
  static char lib_version[60] = {0};
  snprintf(lib_version, 60, "%s", SWIFT_MPI_LIBRARY);
198
#endif
199
200

  /* Numeric version. */
201
  MPI_Get_version(&std_version, &std_subversion);
202
203
  snprintf(version, 80, "%s (MPI std v%i.%i)", lib_version, std_version,
           std_subversion);
204
205
206
207
208
209
#else
  sprintf(version, "Code was not compiled with MPI support");
#endif
  return version;
}

210
211
212
213
214
/**
 * @brief return the HDF5 version in use at runtime.
 *
 * @result description of the current HDF5 version.
 */
215
216
217
218
219
const char *hdf5_version(void) {

  static char version[256] = {0};
#ifdef HAVE_HDF5
  unsigned int majnum, minnum, relnum;
220
  H5get_libversion(&majnum, &minnum, &relnum);
221
222
  sprintf(version, "%i.%i.%i", majnum, minnum, relnum);
#else
223
  sprintf(version, "Unknown version");
224
225
226
227
#endif
  return version;
}

228
229
230
231
232
/**
 * @brief return the METIS version used when SWIFT was built.
 *
 * @result description of the METIS version.
 */
233
234
235
236
237
238
239
const char *metis_version(void) {

  static char version[256] = {0};
#if defined(WITH_MPI) && defined(HAVE_METIS)
  sprintf(version, "%i.%i.%i", METIS_VER_MAJOR, METIS_VER_MINOR,
          METIS_VER_SUBMINOR);
#else
240
  sprintf(version, "Unknown version");
241
242
243
244
#endif
  return version;
}

Matthieu Schaller's avatar
Matthieu Schaller committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/**
 * @brief return the FFTW version used when SWIFT was built.
 *
 * @result description of the FFTW version.
 */
const char *fftw3_version(void) {

  static char version[256] = {0};
#if defined(HAVE_FFTW)
  sprintf(version, "%s", "3.x (details not available)");
#else
  sprintf(version, "Unknown version");
#endif
  return version;
}

261
/**
262
263
 * @brief Prints a greeting message to the standard output containing code
 * version and revision number
264
 */
265
266
void greetings(void) {

267
  printf(" Welcome to the cosmological hydrodynamical code\n");
268
269
270
271
272
  printf("    ______       _________________\n");
  printf("   / ___/ |     / /  _/ ___/_  __/\n");
  printf("   \\__ \\| | /| / // // /_   / /   \n");
  printf("  ___/ /| |/ |/ // // __/  / /    \n");
  printf(" /____/ |__/|__/___/_/    /_/     \n");
273
  printf(" SPH With Inter-dependent Fine-grained Tasking\n\n");
274

275
  printf(" Version : %s\n", package_version());
276
  printf(" Revision: %s, Branch: %s\n", git_revision(), git_branch());
277
  printf(" Webpage : www.swiftsim.com\n\n");
278
  printf(" Compiler: %s, Version: %s\n", compiler_name(), compiler_version());
279
280
281
#ifdef HAVE_HDF5
  printf(" HDF5 library version: %s\n", hdf5_version());
#endif
Matthieu Schaller's avatar
Matthieu Schaller committed
282
283
284
#ifdef HAVE_FFTW
  printf(" FFTW library version: %s\n", fftw3_version());
#endif
285
286
#ifdef WITH_MPI
  printf(" MPI library: %s\n", mpi_version());
287
#ifdef HAVE_METIS
Matthieu Schaller's avatar
Matthieu Schaller committed
288
  printf(" METIS library version: %s\n", metis_version());
289
#endif
290
291
#endif
  printf("\n");
292
}