Theoretica
Mathematical Library
Loading...
Searching...
No Matches
reprod.h
Go to the documentation of this file.
1
5
6#ifndef THEORETICA_REPROD_H
7#define THEORETICA_REPROD_H
8
9#include <string>
10
11
12namespace theoretica {
13
15namespace reprod {
16
17
21 struct environment {
22
23 // Operating system
24 std::string os {""};
25
26 // Architecture
27 std::string arch {""};
28
29 // Compiler
30 std::string compiler {""};
31
32 // Compiler version
33 std::string compiler_version {""};
34
35 // C++ Standard
36 std::string cpp_standard {""};
37
38 // Build date
39 std::string build_date {""};
40
41 // AVX2 support
42 bool has_avx2 {false};
43
44 // AVX512 support
45 bool has_avx512 {false};
46
47 // CUDA support
48 bool has_cuda {false};
49
50 // OpenMP support
51 bool has_omp {false};
52
53
55 inline std::string to_string() const {
56
57 std::string str = "Environment Information\n";
58 str += "OS: " + os + "\n";
59 str += "Architecture: " + arch + "\n";
60 str += "Compiler: " + compiler + " " + compiler_version + "\n";
61 str += "C++ Standard: " + cpp_standard + "\n";
62 str += "Features: ";
63
64 if (has_avx2) str += "AVX2 ";
65 if (has_avx512) str += "AVX512 ";
66 if (has_cuda) str += "CUDA ";
67 if (has_omp) str += "OpenMP ";
68
69 str += "\n";
70 //str += "Theoretica Version: " + lib_version + "\n";
71 str += "Build Date: " + build_date + "\n";
72
73 return str;
74 }
75
77 inline operator std::string() {
78 return to_string();
79 }
80
81
83 inline friend std::ostream& operator<<(std::ostream& out, const environment& obj) {
84 return out << obj.to_string();
85 }
86
87 };
88
89
93
94 environment env;
95
96 // Operating system
97 #ifdef _WIN32
98 env.os = "Windows";
99 #ifdef _WIN64
100 env. arch = "x86_64";
101 #else
102 env.arch = "x86";
103 #endif
104 #elif defined(__APPLE__)
105 env.os = "macOS";
106 #ifdef __arm64__
107 env.arch = "arm64";
108 #else
109 env.arch = "x86_64";
110 #endif
111 #elif defined(__linux__)
112 env.os = "Linux";
113 #ifdef __x86_64__
114 env.arch = "x86_64";
115 #elif defined(__aarch64__)
116 env.arch = "arm64";
117 #else
118 env.arch = "";
119 #endif
120 #endif
121
122 // Compiler detection
123 #ifdef __GNUC__
124 env.compiler = "gcc";
125 env.compiler_version = std::to_string(__GNUC__) + "."
126 + std::to_string(__GNUC_MINOR__) + "."
127 + std::to_string(__GNUC_PATCHLEVEL__);
128 #elif defined(__clang__)
129 env.compiler = "clang";
130 env.compiler_version = std::to_string(__clang_major__) + "."
131 + std:: to_string(__clang_minor__) + "."
132 + std::to_string(__clang_patchlevel__);
133 #elif defined(_MSC_VER)
134 env.compiler = "msvc";
135 env.compiler_version = std::to_string(_MSC_VER);
136 #endif
137
138 // C++ Standard
139 #if __cplusplus == 202002L
140 env.cpp_standard = "C++20";
141 #elif __cplusplus == 201703L
142 env.cpp_standard = "C++17";
143 #elif __cplusplus == 201402L
144 env.cpp_standard = "C++14";
145 #else
146 env.cpp_standard = "C++11 or earlier";
147 #endif
148
149 // CPU features
150 #ifdef __AVX2__
151 env.has_avx2 = true;
152 #endif
153
154 #ifdef __AVX512F__
155 env.has_avx512 = true;
156 #endif
157
158 #ifdef _OPENMP
159 env.has_omp = true;
160 #endif
161
162 // GPU features
163 #ifdef __CUDA_ARCH__
164 env.has_cuda = true;
165 #endif
166
167 // Theoretica versioning
168 //env.lib_version = std::string(THEORETICA_MAJOR) + "." + std::string(THEORETICA_MAJOR) + "." + std::string(THEORETICA_MAJOR);
169 env.build_date = __DATE__ " " __TIME__;
170
171 return env;
172
173 }
174
175}}
176
177#endif
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
environment get_env()
Get an environment structure holding information about the current executing environment.
Definition reprod.h:92
Structure containing information about the build environment, such as operating system and compiler,...
Definition reprod.h:21
friend std::ostream & operator<<(std::ostream &out, const environment &obj)
Stream the environment in string representation to an output stream (std::ostream)
Definition reprod.h:83
std::string to_string() const
Convert the environment to human-readable string representation.
Definition reprod.h:55