A library for working with phylogenetic and population genetic data.
v0.32.0
info.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_CORE_INFO_H_
2 #define GENESIS_UTILS_CORE_INFO_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2024 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@sund.ku.dk>
23  University of Copenhagen, Globe Institute, Section for GeoGenetics
24  Oster Voldgade 5-7, 1350 Copenhagen K, Denmark
25 */
26 
34 #include <cstdint>
35 #include <memory>
36 #include <string>
37 #include <unordered_map>
38 #include <utility>
39 #include <vector>
40 
41 namespace genesis {
42 namespace utils {
43 
44 // =================================================================================================
45 // Compiler Info
46 // =================================================================================================
47 
49 {
56  std::string compile_date_time;
57 
61  bool is_debug;
62 
66  bool is_release;
67 
71  std::string build_type;
72 
78  std::string platform;
79 
85  std::string compiler_family;
86 
92  std::string compiler_version;
93 
97  std::string cpp_version;
98 
103 
110  bool with_avx;
111 
118  bool with_avx2;
119 
127 
128 };
129 
134 
141 std::unordered_map<std::string,std::string> const& info_preprocessor_definitions();
142 
146 std::string info_print_compiler();
147 
148 // =================================================================================================
149 // Hardware Info
150 // =================================================================================================
151 
153 {
158 
162  size_t total_memory;
163 
164  // CPU
167  std::string vendor_string;
168  std::string cpu_model;
171 
172  // OS Features
173  bool OS_x64;
174  bool OS_AVX;
175  bool OS_AVX512;
176 
177  // Misc.
178  bool HW_MMX;
179  bool HW_x64;
180  bool HW_ABM;
181  bool HW_RDRAND;
182  bool HW_RDSEED;
183  bool HW_BMI1;
184  bool HW_BMI2;
185  bool HW_ADX;
186  bool HW_MPX;
189  bool HW_RDPID;
190 
191  // SIMD: 128-bit
192  bool HW_SSE;
193  bool HW_SSE2;
194  bool HW_SSE3;
195  bool HW_SSSE3;
196  bool HW_SSE41;
197  bool HW_SSE42;
198  bool HW_SSE4a;
199  bool HW_AES;
200  bool HW_SHA;
201 
202  // SIMD: 256-bit
203  bool HW_AVX;
204  bool HW_XOP;
205  bool HW_FMA3;
206  bool HW_FMA4;
207  bool HW_AVX2;
208 
209  // SIMD: 512-bit
212 
213  // Knights Landing
216 
217  // Skylake Purley
221 
222  // Cannon Lake
225 
226  // Knights Mill
230 
231  // Cascade Lake
233 
234  // Cooper Lake
236 
237  // Ice Lake
239  bool HW_GFNI;
240  bool HW_VAES;
243 
244 };
245 
250 
258 std::string info_print_hardware( bool full = false );
259 
266 bool info_use_avx();
267 
274 bool info_use_avx2();
275 
282 bool info_use_avx512();
283 
284 // =================================================================================================
285 // Number of Threads
286 // =================================================================================================
287 
295 size_t info_physical_core_count();
296 
301 
313 
320 
348  bool use_openmp = true,
349  bool use_slurm = true,
350  bool physical_cores = true
351 );
352 
353 // =================================================================================================
354 // Run Time Environment
355 // =================================================================================================
356 
366 size_t info_get_pid();
367 
373 
379 
385 
390 std::pair<int, int> info_terminal_size();
391 
392 // =================================================================================================
393 // Current Resource Usage
394 // =================================================================================================
395 
401 
407 
412 
417 
422 
436 double info_process_current_cpu_usage( bool all_cores = true, bool percent = true );
437 
443 double info_system_current_cpu_usage( bool all_cores = true, bool percent = true );
444 
445 // =================================================================================================
446 // Total Resource Usage
447 // =================================================================================================
448 
453 
459 std::pair<double, double> info_process_total_cpu_time();
460 
465 
469 std::string info_process_print_total_usage();
470 
471 } // namespace utils
472 } // namespace genesis
473 
474 #endif // include guard
genesis::utils::InfoHardware::HW_AVX512_BW
bool HW_AVX512_BW
Definition: info.hpp:219
genesis::utils::InfoHardware::HW_AVX512_F
bool HW_AVX512_F
Definition: info.hpp:210
genesis::utils::guess_number_of_threads
size_t guess_number_of_threads(bool use_openmp, bool use_slurm, bool physical_cores)
Make an educated guess on the number of threads to use for multi-threaded functionality.
Definition: info.cpp:1078
genesis::utils::InfoCompiler::with_openmp
bool with_openmp
Compiled with OpenMP.
Definition: info.hpp:102
genesis::utils::InfoHardware::HW_SSE3
bool HW_SSE3
Definition: info.hpp:194
genesis::utils::InfoCompiler::is_release
bool is_release
Binary was compiled with build type RELEASE.
Definition: info.hpp:66
genesis::utils::info_terminal_size
std::pair< int, int > info_terminal_size()
Return the width and height of the terminal that is used to run the program, in number of columns and...
Definition: info.cpp:1172
genesis::utils::info_process_total_cpu_time
std::pair< double, double > info_process_total_cpu_time()
Get the currently used cpu run time, similar to the Unix time command.
Definition: info.cpp:1927
genesis::utils::InfoCompiler::with_avx512
bool with_avx512
Compiled with AVX512.
Definition: info.hpp:126
genesis::utils::InfoHardware::HW_ADX
bool HW_ADX
Definition: info.hpp:185
genesis::utils::InfoHardware::HW_AVX512_BF16
bool HW_AVX512_BF16
Definition: info.hpp:235
genesis::utils::InfoHardware::HW_AVX512_IFMA
bool HW_AVX512_IFMA
Definition: info.hpp:223
genesis::utils::InfoHardware::HW_SSE
bool HW_SSE
Definition: info.hpp:192
genesis::utils::InfoCompiler::with_avx
bool with_avx
Compiled with AVX.
Definition: info.hpp:110
genesis::utils::info_preprocessor_definitions
std::unordered_map< std::string, std::string > const & info_preprocessor_definitions()
Return a string map with some relevant preprocessor macros.
Definition: info.cpp:296
genesis::utils::info_process_current_cpu_usage
double info_process_current_cpu_usage(bool all_cores, bool percent)
Return the CPU usage of the current process.
Definition: info.cpp:1891
genesis::utils::InfoHardware::HW_AVX512_BITALG
bool HW_AVX512_BITALG
Definition: info.hpp:242
genesis::utils::InfoHardware::HW_AVX
bool HW_AVX
Definition: info.hpp:203
genesis::utils::InfoHardware::is_little_endian
bool is_little_endian
System uses little endian memory. If false, system uses big endian.
Definition: info.hpp:157
genesis::utils::info_process_peak_memory_usage
size_t info_process_peak_memory_usage()
Get the peak used memory, in bytes.
Definition: info.cpp:1911
genesis::utils::InfoHardware::HW_SSSE3
bool HW_SSSE3
Definition: info.hpp:195
genesis::utils::InfoHardware::HW_PREFETCHWT1
bool HW_PREFETCHWT1
Definition: info.hpp:188
genesis::utils::InfoHardware::cpu_model
std::string cpu_model
Definition: info.hpp:168
genesis::utils::InfoHardware::OS_AVX
bool OS_AVX
Definition: info.hpp:174
genesis::utils::InfoCompiler::platform
std::string platform
Platform under which genesis was compiled.
Definition: info.hpp:78
genesis::utils::InfoHardware::HW_AVX512_VPOPCNTDQ
bool HW_AVX512_VPOPCNTDQ
Definition: info.hpp:227
genesis::utils::info_system_current_memory_usage
size_t info_system_current_memory_usage()
Return the memory currently used across all running processes, in bytes.
Definition: info.cpp:1881
genesis::utils::info_get_hardware
InfoHardware const & info_get_hardware()
Return information about hardware features.
Definition: info.cpp:665
genesis::utils::InfoHardware::HW_AVX512_4VNNIW
bool HW_AVX512_4VNNIW
Definition: info.hpp:228
genesis::utils::info_print_compiler
std::string info_print_compiler()
Print information about compiler settings and flags to a string.
Definition: info.cpp:363
genesis::utils::info_process_print_total_usage
std::string info_process_print_total_usage()
Print usage information to a string.
Definition: info.cpp:1971
genesis::utils::info_process_current_memory_usage
size_t info_process_current_memory_usage()
Return the memory currently used by the current process, in bytes.
Definition: info.cpp:1876
genesis::utils::InfoHardware::total_memory
size_t total_memory
Total amount of memory, in bytes.
Definition: info.hpp:162
genesis::utils::InfoHardware::HW_GFNI
bool HW_GFNI
Definition: info.hpp:239
genesis::utils::InfoHardware::HW_XOP
bool HW_XOP
Definition: info.hpp:204
genesis::utils::InfoHardware::HW_FMA4
bool HW_FMA4
Definition: info.hpp:206
genesis::utils::info_process_total_energy_consumption
double info_process_total_energy_consumption()
Get energy consumption of the program so far, in Wh.
Definition: info.cpp:1940
genesis::utils::InfoHardware::HW_x64
bool HW_x64
Definition: info.hpp:179
genesis::utils::info_stdout_is_terminal
bool info_stdout_is_terminal()
Return true iff the standard output stream is a terminal, and false if not, i.e., if it is a file or ...
Definition: info.cpp:1154
genesis::utils::InfoHardware::HW_SSE2
bool HW_SSE2
Definition: info.hpp:193
genesis::utils::info_hyperthreads_enabled
bool info_hyperthreads_enabled()
Try to get whether hyperthreads are enabled in the current system.
Definition: info.cpp:1028
genesis::utils::InfoHardware::HW_BMI1
bool HW_BMI1
Definition: info.hpp:183
genesis::utils::info_number_of_threads_slurm
size_t info_number_of_threads_slurm()
Get the number of threads as indicated by the SLURM environment.
Definition: info.cpp:1067
genesis::utils::InfoHardware::HW_SSE4a
bool HW_SSE4a
Definition: info.hpp:198
genesis::utils::InfoHardware::vendor_Intel
bool vendor_Intel
Definition: info.hpp:166
genesis::utils::InfoHardware::with_hyperthreading
bool with_hyperthreading
Definition: info.hpp:170
genesis::utils::InfoHardware::HW_AVX512_PF
bool HW_AVX512_PF
Definition: info.hpp:214
genesis::utils::info_get_pid
size_t info_get_pid()
Get the process ID of the current process.
Definition: info.cpp:1133
genesis::utils::InfoHardware::HW_SSE41
bool HW_SSE41
Definition: info.hpp:196
genesis::utils::InfoCompiler::compiler_family
std::string compiler_family
Compiler family (name) that was used to compile genesis.
Definition: info.hpp:85
genesis::utils::info_number_of_threads_openmp
size_t info_number_of_threads_openmp()
Get the number of threads as indicated by the OpenMP environment.
Definition: info.cpp:1044
genesis::utils::InfoHardware::HW_AVX512_ER
bool HW_AVX512_ER
Definition: info.hpp:215
genesis::utils::InfoHardware::HW_AVX512_CD
bool HW_AVX512_CD
Definition: info.hpp:211
genesis::utils::info_system_current_memory_available
size_t info_system_current_memory_available()
Return the memory currently available in the system, in bytes.
Definition: info.cpp:1886
genesis::utils::info_use_avx
bool info_use_avx()
Assess if it is safe to use AVX features.
Definition: info.cpp:897
genesis::utils::InfoHardware::HW_BMI2
bool HW_BMI2
Definition: info.hpp:184
genesis::utils::InfoHardware::HW_AVX512_VNNI
bool HW_AVX512_VNNI
Definition: info.hpp:232
genesis::utils::InfoCompiler::build_type
std::string build_type
Build type that was used to compile the binary, i.e., "debug" or "release".
Definition: info.hpp:71
genesis::utils::InfoCompiler::compile_date_time
std::string compile_date_time
Date and time when genesis was compiled.
Definition: info.hpp:56
genesis::utils::InfoHardware::HW_FMA3
bool HW_FMA3
Definition: info.hpp:205
genesis::utils::info_system_current_cpu_usage
double info_system_current_cpu_usage(bool all_cores, bool percent)
Return the CPU usage of the system, across all cores.
Definition: info.cpp:1898
genesis::utils::InfoHardware::HW_AVX512_4FMAPS
bool HW_AVX512_4FMAPS
Definition: info.hpp:229
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::utils::info_stdin_is_terminal
bool info_stdin_is_terminal()
Return true iff the standard input stream is a terminal, and false if not, i.e., if it is a file or a...
Definition: info.cpp:1144
genesis::utils::InfoHardware::HW_ABM
bool HW_ABM
Definition: info.hpp:180
genesis::utils::InfoCompiler::cpp_version
std::string cpp_version
C++ version that was used to compile genesis.
Definition: info.hpp:97
genesis::utils::info_get_compiler
InfoCompiler const & info_get_compiler()
Return information about compiler settings and flags.
Definition: info.cpp:171
genesis::utils::InfoHardware
Definition: info.hpp:152
genesis::utils::info_physical_core_count
size_t info_physical_core_count()
Get the number of CPU cores.
Definition: info.cpp:1010
genesis::utils::InfoHardware::HW_MMX
bool HW_MMX
Definition: info.hpp:178
genesis::utils::InfoHardware::vendor_string
std::string vendor_string
Definition: info.hpp:167
genesis::utils::info_process_max_file_count
size_t info_process_max_file_count()
Return the maximum number of files (i.e., file descriptors) that can be opened simultaneously in the ...
Definition: info.cpp:1200
genesis::utils::info_use_avx2
bool info_use_avx2()
Assess if it is safe to use AVX2 features.
Definition: info.cpp:908
genesis::utils::InfoHardware::OS_x64
bool OS_x64
Definition: info.hpp:173
genesis::utils::InfoCompiler::with_avx2
bool with_avx2
Compiled with AVX2.
Definition: info.hpp:118
genesis::utils::info_process_current_file_count
size_t info_process_current_file_count()
Return the number of files (i.e., file descriptors) that the current process (the process calling thi...
Definition: info.cpp:1213
genesis::utils::InfoHardware::vendor_AMD
bool vendor_AMD
Definition: info.hpp:165
genesis::utils::InfoHardware::HW_AVX512_VPCLMUL
bool HW_AVX512_VPCLMUL
Definition: info.hpp:241
genesis::utils::InfoHardware::HW_AES
bool HW_AES
Definition: info.hpp:199
genesis::utils::InfoHardware::HW_SSE42
bool HW_SSE42
Definition: info.hpp:197
genesis::utils::InfoHardware::HW_RDRAND
bool HW_RDRAND
Definition: info.hpp:181
genesis::utils::InfoHardware::OS_AVX512
bool OS_AVX512
Definition: info.hpp:175
genesis::utils::InfoHardware::HW_AVX512_VBMI
bool HW_AVX512_VBMI
Definition: info.hpp:224
genesis::utils::info_stderr_is_terminal
bool info_stderr_is_terminal()
Return true iff the standard error stream is a terminal, and false if not, i.e., if it is a file or a...
Definition: info.cpp:1163
genesis::utils::InfoHardware::HW_AVX512_VL
bool HW_AVX512_VL
Definition: info.hpp:218
genesis::utils::info_use_avx512
bool info_use_avx512()
Assess if it is safe to use AVX512 features.
Definition: info.cpp:919
genesis::utils::InfoHardware::HW_PREFETCHW
bool HW_PREFETCHW
Definition: info.hpp:187
genesis::utils::InfoHardware::HW_RDPID
bool HW_RDPID
Definition: info.hpp:189
genesis::utils::InfoCompiler
Definition: info.hpp:48
genesis::utils::info_print_hardware
std::string info_print_hardware(bool full)
Print information about hardware features to a string.
Definition: info.cpp:795
genesis::utils::InfoHardware::physical_core_count
size_t physical_core_count
Definition: info.hpp:169
genesis::utils::InfoHardware::HW_AVX2
bool HW_AVX2
Definition: info.hpp:207
genesis::utils::InfoHardware::HW_RDSEED
bool HW_RDSEED
Definition: info.hpp:182
genesis::utils::InfoCompiler::is_debug
bool is_debug
Binary was compiled with build type DEBUG.
Definition: info.hpp:61
genesis::utils::InfoHardware::HW_AVX512_VBMI2
bool HW_AVX512_VBMI2
Definition: info.hpp:238
genesis::utils::InfoHardware::HW_SHA
bool HW_SHA
Definition: info.hpp:200
genesis::utils::InfoCompiler::compiler_version
std::string compiler_version
Compiler version that was used to compile genesis.
Definition: info.hpp:92
genesis::utils::InfoHardware::HW_MPX
bool HW_MPX
Definition: info.hpp:186
genesis::utils::InfoHardware::HW_AVX512_DQ
bool HW_AVX512_DQ
Definition: info.hpp:220
genesis::utils::InfoHardware::HW_VAES
bool HW_VAES
Definition: info.hpp:240