version.c 9.47 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
#ifdef HAVE_FFTW
37
#include <fftw3.h>
Matthieu Schaller's avatar
Matthieu Schaller committed
38
39
#endif

40
/* Some standard headers. */
41
#include <stdio.h>
42
#include <stdlib.h>
43
#include <string.h>
Matthieu Schaller's avatar
Matthieu Schaller committed
44
#include <unistd.h>
45
46

/* This object's header. */
47
#include "error.h"
48
#include "version.h"
49

Matthieu Schaller's avatar
Matthieu Schaller committed
50
51
52
/* Local headers. */
#include "version_string.h"

53
54
55
56
57
58
59
60
61
62
63
64
/**
 * @brief Return the hostname
 *
 * Will return the name of the host.
 *
 * @result the hostname.
 */
const char *hostname(void) {
  static char buf[256];
  static int initialised = 0;
  if (!initialised) {
    buf[255] = '\0';
James Willis's avatar
James Willis committed
65
    if (gethostname(buf, 255)) sprintf(buf, "%s", "Unknown host");
66
67
68
69
70
    initialised = 1;
  }
  return buf;
}

71
72
73
/**
 * @brief Return the source code git revision
 *
74
 * The SHA of the code checked out when the library was last built.
75
 * Will include -dirty if they are local modifications.
76
77
 *
 * @result the git version.
78
 */
79
const char *git_revision(void) {
80
81
  static char buf[256];
  static int initialised = 0;
82
  static const char *revision = GIT_REVISION;
83
84
  if (!initialised) {
    if (strlen(revision) == 0)
85
      sprintf(buf, "%s", "unknown");
86
    else
87
      sprintf(buf, "%s", revision);
88
89
90
    initialised = 1;
  }
  return buf;
91
}
92

93
94
95
/**
 * @brief Return the source code git branch
 *
96
97
98
 * The name of the current branch when the code was last built.
 *
 * @result git branch
99
100
 */
const char *git_branch(void) {
101
102
  static char buf[256];
  static int initialised = 0;
103
  static const char *branch = GIT_BRANCH;
104
105
  if (!initialised) {
    if (strlen(branch) == 0)
106
      sprintf(buf, "%s", "unknown");
107
    else
108
      sprintf(buf, "%s", branch);
109
110
111
    initialised = 1;
  }
  return buf;
112
113
}

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
 * @brief Return the date of the commit in the git repository
 *
 * The date of the commit of the code we are running.
 *
 * @result git branch
 */
const char *git_date(void) {
  static char buf[256];
  static int initialised = 0;
  static const char *date = GIT_DATE;
  if (!initialised) {
    if (strlen(date) == 0)
      sprintf(buf, "%s", "unknown");
    else
      sprintf(buf, "%s", date);
    initialised = 1;
  }
  return buf;
}

135
136
137
138
139
140
141
142
143
144
/**
 * @brief Return the options passed to the 'configure' script
 *
 * @result List of configuration options within simple quotes (').
 */
const char *configuration_options(void) {
  static char buf[1024];
  static int initialised = 0;
  static const char *config = SWIFT_CONFIG_FLAGS;
  if (!initialised) {
145
    snprintf(buf, 1024, "'%s'", config);
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
    initialised = 1;
  }
  return buf;
}

/**
 * @brief Return the CFLAGS the code was compiled with
 *
 * @result List of CFLAGS within simple quotes (').
 */
const char *compilation_cflags(void) {
  static char buf[1024];
  static int initialised = 0;
  static const char *cflags = SWIFT_CFLAGS;
  if (!initialised) {
161
    snprintf(buf, 1024, "'%s'", cflags);
162
163
164
165
166
    initialised = 1;
  }
  return buf;
}

167
168
/**
 * @brief The version of SWIFT
169
170
 *
 * @result the package version
171
 */
172
173
174
const char *package_version(void) {
  static const char *version = PACKAGE_VERSION;
  return version;
175
176
177
178
}

/**
 * @brief A description of the package version and code status.
179
180
 *
 * @result description of the package version
181
 */
182
183
184
185
const char *package_description(void) {
  static char buf[256];
  static int initialised = 0;
  if (!initialised) {
186
    sprintf(buf, "SWIFT version: %s, at revision: %s, branch: %s",
187
            PACKAGE_VERSION, GIT_REVISION, GIT_BRANCH);
188
189
190
    initialised = 1;
  }
  return buf;
191
}
192

193
194
195
196
197
/**
 * @brief return the name of the compiler used to build SWIFT.
 *
 * @result description of the compiler.
 */
198
const char *compiler_name(void) {
199
  static char compiler[256] = {0};
200
#if defined(__INTEL_COMPILER)
201
  sprintf(compiler, "ICC");
202
#elif defined(__clang__)
203
  sprintf(compiler, "LLVM/Clang");
204
#elif defined(__xlc__)
205
  sprintf(compiler, "IBM XL");
206
#elif defined(__GNUC__)
207
  sprintf(compiler, "GCC");
208
#endif
209
  if (strlen(compiler) == 0) sprintf(compiler, "Unknown compiler");
210
211
212
  return compiler;
}

213
214
215
216
217
/**
 * @brief return compiler version used to build SWIFT.
 *
 * @result description of the compiler.
 */
218
const char *compiler_version(void) {
219
  static char version[256] = {0};
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#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
235
  if (strlen(version) == 0) sprintf(version, "Unknown version");
236
237
238
  return version;
}

239
240
241
242
243
244
/**
 * @brief return the MPI version, runtime if possible otherwise that used when
 *        built.
 *
 * @result description of the MPI version.
 */
245
const char *mpi_version(void) {
246
247
  static char version[80] = {0};

248
#ifdef WITH_MPI
249
250
  int std_version, std_subversion;

251
/* Check that the library implements the version string routine */
252
253
#ifdef MPI_MAX_LIBRARY_VERSION_STRING
  static char lib_version[MPI_MAX_LIBRARY_VERSION_STRING] = {0};
254
  int len;
255
  MPI_Get_library_version(lib_version, &len);
256

257
  /* Find first \n and truncate string to this length, can get many lines from
258
259
260
261
   * some MPIs (MPICH). */
  char *ptr = strchr(lib_version, '\n');
  if (ptr != NULL) *ptr = '\0';

262
263
  /* Also arbitrarily truncate to keep down to one line, Open MPI,
   * check for last comma and keep to ~60 chars max. */
264
  strcpy(lib_version + 60, "...");
265
266
267
  ptr = strrchr(lib_version, ',');
  if (ptr != NULL) *ptr = '\0';

268
#else
269
  /* Use autoconf guessed value. */
270
271
  static char lib_version[60] = {0};
  snprintf(lib_version, 60, "%s", SWIFT_MPI_LIBRARY);
272
#endif
273
274

  /* Numeric version. */
275
  MPI_Get_version(&std_version, &std_subversion);
276
277
  snprintf(version, 80, "%s (MPI std v%i.%i)", lib_version, std_version,
           std_subversion);
278
279
280
281
282
283
#else
  sprintf(version, "Code was not compiled with MPI support");
#endif
  return version;
}

284
285
286
287
288
/**
 * @brief return the HDF5 version in use at runtime.
 *
 * @result description of the current HDF5 version.
 */
289
290
291
292
293
const char *hdf5_version(void) {

  static char version[256] = {0};
#ifdef HAVE_HDF5
  unsigned int majnum, minnum, relnum;
294
  H5get_libversion(&majnum, &minnum, &relnum);
295
  sprintf(version, "%u.%u.%u", majnum, minnum, relnum);
296
#else
297
  sprintf(version, "Unknown version");
298
299
300
301
#endif
  return version;
}

302
303
304
305
306
/**
 * @brief return the METIS version used when SWIFT was built.
 *
 * @result description of the METIS version.
 */
307
308
309
310
311
312
313
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
314
  sprintf(version, "Unknown version");
315
316
317
318
#endif
  return version;
}

Matthieu Schaller's avatar
Matthieu Schaller committed
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/**
 * @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;
}

335
/**
336
337
 * @brief Prints a greeting message to the standard output containing code
 * version and revision number
338
 */
339
340
void greetings(void) {

341
  printf(" Welcome to the cosmological hydrodynamical code\n");
342
343
344
345
346
  printf("    ______       _________________\n");
  printf("   / ___/ |     / /  _/ ___/_  __/\n");
  printf("   \\__ \\| | /| / // // /_   / /   \n");
  printf("  ___/ /| |/ |/ // // __/  / /    \n");
  printf(" /____/ |__/|__/___/_/    /_/     \n");
347
  printf(" SPH With Inter-dependent Fine-grained Tasking\n\n");
348

349
  printf(" Version : %s\n", package_version());
350
351
  printf(" Revision: %s, Branch: %s, Date: %s\n", git_revision(), git_branch(),
         git_date());
352
353
  printf(" Webpage : %s\n\n", PACKAGE_URL);
  printf(" Config. options: %s\n\n", configuration_options());
354
  printf(" Compiler: %s, Version: %s\n", compiler_name(), compiler_version());
355
356
  printf(" CFLAGS  : %s\n", compilation_cflags());
  printf("\n");
357
358
359
#ifdef HAVE_HDF5
  printf(" HDF5 library version: %s\n", hdf5_version());
#endif
Matthieu Schaller's avatar
Matthieu Schaller committed
360
361
362
#ifdef HAVE_FFTW
  printf(" FFTW library version: %s\n", fftw3_version());
#endif
363
364
#ifdef WITH_MPI
  printf(" MPI library: %s\n", mpi_version());
365
#ifdef HAVE_METIS
Matthieu Schaller's avatar
Matthieu Schaller committed
366
  printf(" METIS library version: %s\n", metis_version());
367
#endif
368
369
#endif
  printf("\n");
370
}