version.c 6.21 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

36
/* Some standard headers. */
37
#include <stdio.h>
38
#include <string.h>
39
40

/* This object's header. */
41
#include "version.h"
42

43
44
45
/**
 * @brief Return the source code git revision
 *
46
 * @details The SHA of the code checked out when the library was last built.
47
48
 * Will include -dirty if they are local modifications.
 */
49
const char *git_revision(void) {
50
51
  static char buf[256];
  static int initialised = 0;
52
  static const char *revision = GIT_REVISION;
53
54
  if (!initialised) {
    if (strlen(revision) == 0)
55
      sprintf(buf, "%s", "unknown");
56
    else
57
      sprintf(buf, "%s", revision);
58
59
60
    initialised = 1;
  }
  return buf;
61
}
62

63
64
65
66
67
68
/**
 * @brief Return the source code git branch
 *
 * @details The name of the current branch when the code was last built.
 */
const char *git_branch(void) {
69
70
  static char buf[256];
  static int initialised = 0;
71
  static const char *branch = GIT_BRANCH;
72
73
  if (!initialised) {
    if (strlen(branch) == 0)
74
      sprintf(buf, "%s", "unknown");
75
    else
76
      sprintf(buf, "%s", branch);
77
78
79
    initialised = 1;
  }
  return buf;
80
81
}

82
83
84
/**
 * @brief The version of SWIFT
 */
85
86
87
const char *package_version(void) {
  static const char *version = PACKAGE_VERSION;
  return version;
88
89
90
91
92
}

/**
 * @brief A description of the package version and code status.
 */
93
94
95
96
const char *package_description(void) {
  static char buf[256];
  static int initialised = 0;
  if (!initialised) {
97
    sprintf(buf, "SWIFT version: %s, at revision: %s, branch: %s",
98
            PACKAGE_VERSION, GIT_REVISION, GIT_BRANCH);
99
100
101
    initialised = 1;
  }
  return buf;
102
}
103

104
const char *compiler_name(void) {
105
  static char compiler[256] = {0};
106
#if defined(__INTEL_COMPILER)
107
  sprintf(compiler, "ICC");
108
#elif defined(__clang__)
109
  sprintf(compiler, "LLVM/Clang");
110
#elif defined(__xlc__)
111
  sprintf(compiler, "IBM XL");
112
#elif defined(__GNUC__)
113
  sprintf(compiler, "GCC");
114
#endif
115
  if (strlen(compiler) == 0) sprintf(compiler, "Unknown compiler");
116
117
118
119
  return compiler;
}

const char *compiler_version(void) {
120
  static char version[256] = {0};
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#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
136
  if (strlen(version) == 0) sprintf(version, "Unknown version");
137
138
139
  return version;
}

140
141
142
const char *mpi_version(void) {
  static char version[256] = {0};
#ifdef WITH_MPI
143
  int len, std_version, std_subversion;
Matthieu Schaller's avatar
Matthieu Schaller committed
144
/* Check that the library implements the version string routine */
145
146
147
#ifdef MPI_MAX_LIBRARY_VERSION_STRING
  static char lib_version[MPI_MAX_LIBRARY_VERSION_STRING] = {0};
  MPI_Get_library_version(lib_version, &len);
Matthieu Schaller's avatar
Matthieu Schaller committed
148
149
  /* Intel-MPI adds a tailing '\n' at the end of the string that looks ugly. */
  if (lib_version[len - 1] == '\n') lib_version[len - 1] = ' ';
150
151
152
153
#else
  static char lib_version[256] = {0};
  sprintf(lib_version, "Unknow library");
#endif
154
  MPI_Get_version(&std_version, &std_subversion);
Matthieu Schaller's avatar
Matthieu Schaller committed
155
156
  sprintf(version, "%s (implementing MPI standard v %i.%i)", lib_version,
          std_version, std_subversion);
157
158
159
160
161
162
#else
  sprintf(version, "Code was not compiled with MPI support");
#endif
  return version;
}

163
164
165
166
167
const char *hdf5_version(void) {

  static char version[256] = {0};
#ifdef HAVE_HDF5
  unsigned int majnum, minnum, relnum;
168
  H5get_libversion(&majnum, &minnum, &relnum);
169
170
  sprintf(version, "%i.%i.%i", majnum, minnum, relnum);
#else
171
172
173
174
175
176
177
178
179
180
181
182
183
  sprintf(version, "Unknow version");
#endif
  return version;
}

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
  sprintf(version, "Unknow version");
184
185
186
187
#endif
  return version;
}

188
/**
189
190
 * @brief Prints a greeting message to the standard output containing code
 * version and revision number
191
 */
192
193
void greetings(void) {

194
  printf(" Welcome to the cosmological code\n");
195
196
197
198
199
  printf("    ______       _________________\n");
  printf("   / ___/ |     / /  _/ ___/_  __/\n");
  printf("   \\__ \\| | /| / // // /_   / /   \n");
  printf("  ___/ /| |/ |/ // // __/  / /    \n");
  printf(" /____/ |__/|__/___/_/    /_/     \n");
200
  printf(" SPH With Inter-dependent Fine-grained Tasking\n\n");
201

202
  printf(" Version : %s\n", package_version());
203
  printf(" Revision: %s, Branch: %s\n", git_revision(), git_branch());
204
  printf(" Webpage : www.swiftsim.com\n\n");
205
  printf(" Compiler: %s, Version: %s\n", compiler_name(), compiler_version());
206
207
208
#ifdef HAVE_HDF5
  printf(" HDF5 library version: %s\n", hdf5_version());
#endif
209
210
#ifdef WITH_MPI
  printf(" MPI library: %s\n", mpi_version());
211
#ifdef HAVE_METIS
Matthieu Schaller's avatar
Matthieu Schaller committed
212
  printf(" METIS library version: %s\n", metis_version());
213
#endif
214
215
#endif
  printf("\n");
216
}