Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
about.cpp
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Smith Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
8 #include "smith/smith_config.hpp"
9 
10 #include <format>
11 #include <string_view>
12 #include <vector>
13 
14 #include "mpi.h"
15 #include "axom/config.hpp"
16 #include "axom/core.hpp"
17 
18 #include "camp/config.hpp"
19 
20 #ifdef SMITH_USE_CALIPER
21 #include "caliper/caliper-config.h"
22 #endif
23 
24 #ifdef SMITH_USE_CONDUIT
25 #include "conduit_config.h"
26 #endif
27 
28 #ifdef SMITH_USE_HDF5
29 #include "hdf5.h"
30 #endif
31 
32 #ifdef SMITH_USE_LUA
33 #include "lua.h"
34 #endif
35 
36 #include "mfem.hpp"
37 
38 #ifdef SMITH_USE_RAJA
39 #include "RAJA/config.hpp"
40 #endif
41 
42 #ifdef SMITH_USE_UMPIRE
43 #include "umpire/Umpire.hpp"
44 #endif
45 
46 #ifdef SMITH_USE_TRIBOL
47 #include "tribol/config.hpp"
48 #endif
49 
50 #include "smith/smith_config.hpp"
51 #include "smith/infrastructure/git_sha.hpp"
53 
54 namespace smith {
55 
56 std::string about()
57 {
58  [[maybe_unused]] constexpr std::string_view on = "ON";
59  [[maybe_unused]] constexpr std::string_view off = "OFF";
60 
61  std::string about = "\n";
62 
63  // Version info
64  about += std::format("Smith Version: {0}\n", version());
65  about += "\n";
66 
67  // General configuration
68 #ifdef SMITH_DEBUG
69  about += std::format("Debug Build: {0}\n", on);
70 #else
71  about += std::format("Debug Build: {0}\n", off);
72 #endif
73 
74 #ifdef SMITH_USE_CUDA
75  about += std::format("CUDA: {0}\n", on);
76 #else
77  about += std::format("CUDA: {0}\n", off);
78 #endif
79 
80  about += "\n";
81 
82  //------------------------
83  // Libraries
84  //------------------------
85 
86  // Print out version of enabled libraries and list disabled ones by name
87 
88  std::vector<std::string> disabled_libs;
89 
90  about += "Enabled Libraries:\n";
91 
92  // Axom
93  about += std::format("Axom Version: {0}\n", axom::getVersion());
94 
95  // Camp
96  about += std::format("Camp Version: {0}\n", CAMP_VERSION);
97 
98  // Caliper
99 #ifdef SMITH_USE_CALIPER
100  about += std::format("Caliper Version: {0}\n", CALIPER_VERSION);
101 #else
102  disabled_libs.push_back("Caliper");
103 #endif
104 
105  // Conduit
106 #ifdef SMITH_USE_CONDUIT
107  about += std::format("Conduit Version: {0}\n", CONDUIT_VERSION);
108 #else
109  disabled_libs.push_back("Conduit");
110 #endif
111 
112  // HDF5
113 #ifdef SMITH_USE_HDF5
114  unsigned int h5_maj, h5_min, h5_rel;
115  std::string h5_version;
116  if (H5get_libversion(&h5_maj, &h5_min, &h5_rel) < 0) {
117  SLIC_ERROR("Failed to retrieve HDF5 version.");
118  } else {
119  h5_version = std::format("{0}.{1}.{2}", h5_maj, h5_min, h5_rel);
120  }
121  about += std::format("HDF5 Version: {0}\n", h5_version);
122 #else
123  disabled_libs.push_back("HDF5");
124 #endif
125 
126  // Lua
127 #ifdef SMITH_USE_LUA
128  std::string lua_version{LUA_RELEASE};
129  if (axom::utilities::string::startsWith(lua_version, "Lua ")) {
130  lua_version.erase(0, 4);
131  }
132  about += std::format("Lua Version: {0}\n", lua_version);
133 #else
134  disabled_libs.push_back("Lua");
135 #endif
136 
137  // MFEM
138  const char* mfem_version = mfem::GetVersionStr();
139  if (mfem_version == nullptr) {
140  SLIC_ERROR("Failed to retrieve MFEM version.");
141  }
142  const char* mfem_sha = mfem::GetGitStr();
143  if (mfem_sha == nullptr) {
144  SLIC_ERROR("Failed to retrieve MFEM Git SHA.");
145  }
146  std::string mfem_full_version = std::string(mfem_version);
147  if (axom::utilities::string::startsWith(mfem_full_version, "MFEM ")) {
148  mfem_full_version.erase(0, 5);
149  }
150  if (mfem_sha[0] != '\0') {
151  mfem_full_version += std::format(" (Git SHA: {0})", mfem_sha);
152  }
153  about += std::format("MFEM Version: {0}\n", mfem_full_version);
154 
155  // RAJA
156 #ifdef SMITH_USE_RAJA
157  about +=
158  std::format("RAJA Version: {0}.{1}.{2}\n", RAJA_VERSION_MAJOR, RAJA_VERSION_MINOR, RAJA_VERSION_PATCHLEVEL);
159 #else
160  disabled_libs.push_back("RAJA");
161 #endif
162 
163  // Tribol
164 #ifdef SMITH_USE_TRIBOL
165  about += std::format("Tribol Version: {0}\n", TRIBOL_VERSION_FULL);
166 #else
167  disabled_libs.push_back("Tribol");
168 #endif
169 
170  // Umpire
171 #ifdef SMITH_USE_UMPIRE
172  about += std::format("Umpire Version: {0}.{1}.{2}\n", umpire::get_major_version(), umpire::get_minor_version(),
173  umpire::get_patch_version());
174 #else
175  disabled_libs.push_back("Umpire");
176 #endif
177 
178  about += "\n";
179 
180  about += "Disabled Libraries:\n";
181  if (disabled_libs.size() == 0) {
182  about += "None\n";
183  } else {
184  for (auto& lib : disabled_libs) {
185  about += lib + "\n";
186  }
187  }
188 
189  return about;
190 }
191 
192 std::string gitSHA() { return SMITH_GIT_SHA; }
193 
195 {
196  // Add header
197  std::string infoMsg = std::format("{:*^80}\n", "*");
198 
199  infoMsg += std::format("{0}: {1}\n", "Smith Version", version());
200  infoMsg += std::format("{0}: {1}\n", "Build Type", buildType());
201  infoMsg += std::format("{0}: {1}\n", "User Name", axom::utilities::getUserName());
202  infoMsg += std::format("{0}: {1}\n", "Host Name", axom::utilities::getHostName());
203 
204  auto [count, rank] = getMPIInfo();
205  infoMsg += std::format("{0}: {1}\n", "MPI Rank Count", count);
206 
207  // Add footer
208  infoMsg += std::format("{:*^80}\n", "*");
209 
210  SLIC_INFO_ROOT(infoMsg);
211  smith::logger::flush();
212 }
213 
214 std::string version(bool add_SHA)
215 {
216  std::string version = std::format("v{0}.{1}.{2}", SMITH_VERSION_MAJOR, SMITH_VERSION_MINOR, SMITH_VERSION_PATCH);
217 
218  std::string sha = gitSHA();
219  if (add_SHA && !sha.empty()) {
220  version += "-" + sha;
221  }
222 
223  return version;
224 }
225 
226 std::string compiler() { return std::format("{0} version {1}", SMITH_COMPILER_NAME, SMITH_COMPILER_VERSION); }
227 
228 std::string buildType()
229 {
230 #ifdef SMITH_DEBUG
231  return "Debug";
232 #else
233  return "Release";
234 #endif
235 }
236 
237 std::pair<int, int> getMPIInfo(MPI_Comm comm)
238 {
239  int num_procs = 0;
240  int rank = 0;
241  if (MPI_Comm_size(comm, &num_procs) != MPI_SUCCESS) {
242  SLIC_ERROR("Failed to determine number of MPI processes");
243  }
244 
245  if (MPI_Comm_rank(comm, &rank) != MPI_SUCCESS) {
246  SLIC_ERROR("Failed to determine MPI rank");
247  }
248  return {num_procs, rank};
249 }
250 
251 } // namespace smith
This file contains the interface used for retrieving information about how the driver is configured.
This file contains the all the necessary functions and macros required for logging as well as a helpe...
Accelerator functionality.
Definition: smith.cpp:36
std::string version(bool add_SHA)
Returns a string for the version of Smith.
Definition: about.cpp:214
std::string buildType()
Returns a string for the current CMake build type (e.g. Debug, Release)
Definition: about.cpp:228
std::pair< int, int > getMPIInfo(MPI_Comm comm)
Get MPI Info.
Definition: about.cpp:237
std::string compiler()
Returns a string for the current compiler name and version.
Definition: about.cpp:226
std::string about()
Returns a string about the configuration of Smith.
Definition: about.cpp:56
std::string gitSHA()
Returns a string for the Git SHA when the driver was built.
Definition: about.cpp:192
void printRunInfo()
Outputs basic run information to the screen.
Definition: about.cpp:194