version.c 9.66 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
 * @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) {
    if (strlen(config) < 1024 - 2)
      sprintf(buf, "'%s'", config);
    else
      error("SWIFT_CONFIG_FLAGS string longer than buffer");
    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) {
    if (strlen(cflags) < 1024 - 2)
      sprintf(buf, "'%s'", cflags);
    else
      error("SWIFT_CFLAGS string longer than buffer");
    initialised = 1;
  }
  return buf;
}

173
174
/**
 * @brief The version of SWIFT
175
176
 *
 * @result the package version
177
 */
178
179
180
const char *package_version(void) {
  static const char *version = PACKAGE_VERSION;
  return version;
181
182
183
184
}

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

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

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

245
246
247
248
249
250
/**
 * @brief return the MPI version, runtime if possible otherwise that used when
 *        built.
 *
 * @result description of the MPI version.
 */
251
const char *mpi_version(void) {
252
253
  static char version[80] = {0};

254
#ifdef WITH_MPI
255
256
  int std_version, std_subversion;

257
/* Check that the library implements the version string routine */
258
259
#ifdef MPI_MAX_LIBRARY_VERSION_STRING
  static char lib_version[MPI_MAX_LIBRARY_VERSION_STRING] = {0};
260
  int len;
261
  MPI_Get_library_version(lib_version, &len);
262

263
  /* Find first \n and truncate string to this length, can get many lines from
264
265
266
267
   * some MPIs (MPICH). */
  char *ptr = strchr(lib_version, '\n');
  if (ptr != NULL) *ptr = '\0';

268
269
  /* Also arbitrarily truncate to keep down to one line, Open MPI,
   * check for last comma and keep to ~60 chars max. */
270
  strcpy(lib_version + 60, "...");
271
272
273
  ptr = strrchr(lib_version, ',');
  if (ptr != NULL) *ptr = '\0';

274
#else
275
  /* Use autoconf guessed value. */
276
277
  static char lib_version[60] = {0};
  snprintf(lib_version, 60, "%s", SWIFT_MPI_LIBRARY);
278
#endif
279
280

  /* Numeric version. */
281
  MPI_Get_version(&std_version, &std_subversion);
282
283
  snprintf(version, 80, "%s (MPI std v%i.%i)", lib_version, std_version,
           std_subversion);
284
285
286
287
288
289
#else
  sprintf(version, "Code was not compiled with MPI support");
#endif
  return version;
}

290
291
292
293
294
/**
 * @brief return the HDF5 version in use at runtime.
 *
 * @result description of the current HDF5 version.
 */
295
296
297
298
299
const char *hdf5_version(void) {

  static char version[256] = {0};
#ifdef HAVE_HDF5
  unsigned int majnum, minnum, relnum;
300
  H5get_libversion(&majnum, &minnum, &relnum);
301
  sprintf(version, "%u.%u.%u", majnum, minnum, relnum);
302
#else
303
  sprintf(version, "Unknown version");
304
305
306
307
#endif
  return version;
}

308
309
310
311
312
/**
 * @brief return the METIS version used when SWIFT was built.
 *
 * @result description of the METIS version.
 */
313
314
315
316
317
318
319
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
320
  sprintf(version, "Unknown version");
321
322
323
324
#endif
  return version;
}

Matthieu Schaller's avatar
Matthieu Schaller committed
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/**
 * @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;
}

341
/**
342
343
 * @brief Prints a greeting message to the standard output containing code
 * version and revision number
344
 */
345
346
void greetings(void) {

347
  printf(" Welcome to the cosmological hydrodynamical code\n");
348
349
350
351
352
  printf("    ______       _________________\n");
  printf("   / ___/ |     / /  _/ ___/_  __/\n");
  printf("   \\__ \\| | /| / // // /_   / /   \n");
  printf("  ___/ /| |/ |/ // // __/  / /    \n");
  printf(" /____/ |__/|__/___/_/    /_/     \n");
353
  printf(" SPH With Inter-dependent Fine-grained Tasking\n\n");
354

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