version.c 5.02 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
27
28
/* Config parameters. */
#include "../config.h"

/* MPI headers. */
#ifdef WITH_MPI
#include <mpi.h>
#endif

29
/* Some standard headers. */
30
#include <stdio.h>
31
#include <string.h>
32
33

/* This object's header. */
34
#include "version.h"
35

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

56
57
58
59
60
61
/**
 * @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) {
62
63
  static char buf[256];
  static int initialised = 0;
64
  static const char *branch = GIT_BRANCH;
65
66
  if(!initialised) {
    if(strlen(branch) == 0)
67
      sprintf(buf, "%s", "unknown");
68
    else
69
      sprintf(buf, "%s", branch);
70
71
72
    initialised = 1;
  }
  return buf;
73
74
}

75
76
77
/**
 * @brief The version of SWIFT
 */
78
79
80
const char *package_version(void) {
  static const char *version = PACKAGE_VERSION;
  return version;
81
82
83
84
85
}

/**
 * @brief A description of the package version and code status.
 */
86
87
88
89
const char *package_description(void) {
  static char buf[256];
  static int initialised = 0;
  if (!initialised) {
90
    sprintf(buf, "SWIFT version: %s, at revision: %s, branch: %s",
91
            PACKAGE_VERSION, GIT_REVISION, GIT_BRANCH);
92
93
94
    initialised = 1;
  }
  return buf;
95
}
96

97
const char *compiler_name(void) {
98
  static char compiler[256] = {0};
99
#if defined(__INTEL_COMPILER)
100
  sprintf(compiler, "ICC");
101
#elif defined(__clang__)
102
  sprintf(compiler, "LLVM/Clang");
103
#elif defined(__xlc__)
104
  sprintf(compiler, "IBM XL");
105
#elif defined(__GNUC__)
106
  sprintf(compiler, "GCC");
107
#endif
108
  if (strlen(compiler) == 0) sprintf(compiler, "Unknown compiler");
109
110
111
112
  return compiler;
}

const char *compiler_version(void) {
113
  static char version[256] = {0};
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#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
129
  if (strlen(version) == 0) sprintf(version, "Unknown version");
130
131
132
  return version;
}

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

const char *mpi_version(void) {
  static char version[256] = {0};
#ifdef WITH_MPI
  static char lib_version[MPI_MAX_LIBRARY_VERSION_STRING] = {0};
  int len, std_version, std_subversion;
  MPI_Get_library_lib_version(version, &len);
  MPI_Get_version(&std_version, &std_subversion);
  sprintf("%s (standard v %i.%i)", lib_version, std_version, std_subversion);
#else
  sprintf(version, "Code was not compiled with MPI support");
#endif
  return version;
}

148
/**
149
150
 * @brief Prints a greeting message to the standard output containing code
 * version and revision number
151
 */
152
153
void greetings(void) {

154
  printf(" Welcome to the cosmological code\n");
155
156
157
158
159
  printf("    ______       _________________\n");
  printf("   / ___/ |     / /  _/ ___/_  __/\n");
  printf("   \\__ \\| | /| / // // /_   / /   \n");
  printf("  ___/ /| |/ |/ // // __/  / /    \n");
  printf(" /____/ |__/|__/___/_/    /_/     \n");
160
  printf(" SPH With Inter-dependent Fine-grained Tasking\n\n");
161

162
  printf(" Version : %s\n", package_version());
163
164
  printf(" Revision: %s, Branch: %s\n", git_revision(), git_branch());
  printf(" Webpage : www.swiftsim.com\n");
165
166
167
168
169
  printf(" Compiler: %s, Version: %s\n", compiler_name(), compiler_version());
#ifdef WITH_MPI
  printf(" MPI library: %s\n", mpi_version());
#endif
  printf("\n");
170
}