34#ifndef TRIUMVIRATE_INCLUDE_MONITOR_HPP_INCLUDED_
35#define TRIUMVIRATE_INCLUDE_MONITOR_HPP_INCLUDED_
37#include <gsl/gsl_version.h>
39#if defined(TRV_USE_HIP)
40#include <hipfft/hipfftXt.h>
41#elif defined(TRV_USE_CUDA)
63#include "highfive/H5File.hpp"
74#define OMP_ATOMIC _Pragma("omp atomic")
75#define OMP_CRITICAL _Pragma("omp critical")
77#ifndef __HIP_DEVICE_COMPILE__
78#define _OMP_VERSION std::to_string(_OPENMP)
80#define _OMP_VERSION std::string("unknown")
82#define _OMP_NTHREADS omp_get_max_threads()
86#define _OMP_VERSION std::string("unknown")
87#define _OMP_NTHREADS 1
91#define GSL_VERSION "unknown"
95#ifndef __TRV_VERSION__
96#define __TRV_VERSION__ "0.6+"
101#define SHOW_CPPSTATE " C++"
103#define SHOW_CPPSTATE ""
108#define __TZOFFSET__ "+0000"
112#if defined(TRV_USE_HIP)
119#define HIP_EXEC(hip_call) { \
120 auto ret_status = static_cast<hipError_t>(hip_call); \
121 if (ret_status != hipSuccess) { \
125 "Function <%s> returned error code %d " \
126 "in file \"%s\", line %d.\n", \
127 hipGetErrorString(ret_status), \
128 #hip_call, ret_status, \
141#define HIPFFT_EXEC(hipfft_call) { \
142 auto ret_status = static_cast<hipfftResult>(hipfft_call); \
143 if (ret_status != HIPFFT_SUCCESS) { \
146 "hipFFT error: function <%s> returned error code %d " \
147 "in file \"%s\", line %d.\n", \
148 #hipfft_call, ret_status, \
155#elif defined(TRV_USE_CUDA)
162#define CUDA_EXEC(cuda_call) { \
163 auto ret_status = static_cast<cudaError_t>(cuda_call); \
164 if (ret_status != cudaSuccess) { \
168 "Function <%s> returned error code %d " \
169 "in file \"%s\", line %d.\n", \
170 cudaGetErrorString(ret_status), \
171 #cuda_call, ret_status, \
184#define CUFFT_EXEC(cufft_call) { \
185 auto ret_status = static_cast<cufftResult>(cufft_call); \
186 if (ret_status != CUFFT_SUCCESS) { \
189 "cuFFT error: function <%s> returned error code %d " \
190 "in file \"%s\", line %d.\n", \
191 #cufft_call, ret_status, \
208const std::string fn_delimiter =
"::";
218bool has_extension(
const std::string& fname,
const std::string& fext);
228 const std::vector<std::string>& strings,
const std::string& delimiter
239 const std::string& str,
const std::string& delimiter
282 const double BYTES_PER_GBYTES = 1073741824.;
283 return double(num) *
sizeof(T) / BYTES_PER_GBYTES;
297 const double BYTES_PER_GBYTES = 1073741824.;
298 return double(num) *
sizeof(T) / BYTES_PER_GBYTES;
301#if defined(TRV_USE_HIP)
311double worksize_in_gb(
314 int nx,
int ny,
int nz,
315 std::vector<int> gpus
317#elif defined(TRV_USE_CUDA)
328double worksize_in_gb(
331 int nx,
int ny,
int nz,
332 std::size_t* worksizes,
333 std::vector<int> gpus
421#if defined(TRV_USE_CUDA) && CUFFT_VERSION >= 10400
497 void log(
LogLevel level_entry,
const char* fmt_string, ...);
511 void log(
int level_entry,
const char* fmt_string, ...);
521 void debug(
const char* fmt_string, ...);
531 void stat(
const char* fmt_string, ...);
541 void info(
const char* fmt_string, ...);
551 void warn(
const char* fmt_string, ...);
561 void error(
const char* fmt_string, ...);
564 void emit(std::string log_type,
const char* fmt_string, std::va_list args);
611 void set_nodes(std::vector<float> nodes);
636 void update(
int task_idx_now);
645 void update(
float progress_now);
650 std::vector<float> nodes;
651 int next_node_idx = 0;
657 void set_default_pcpt_nodes();
700 virtual const char*
what() const noexcept;
717 IOError(
const char* fmt_string, ...);
724 virtual const char*
what() const noexcept;
748 virtual const char*
what() const noexcept;
772 virtual const char*
what() const noexcept;
IOError(const char *fmt_string,...)
Construct an trv::sys::IOError exception.
std::string err_mesg
error message
std::string err_mesg
error message
InvalidDataError(const char *fmt_string,...)
Construct an trv::sys::InvalidDataError exception.
InvalidParameterError(const char *fmt_string,...)
Construct an trv::sys::InvalidParameterError exception.
std::string err_mesg
error message
Logger with logging level differentiation.
Logger(LogLevel level)
Construct the logger with the specified threshold level.
void info(const char *fmt_string,...)
Emit a information-level message.
void debug(const char *fmt_string,...)
Emit a debugging-level message.
void error(const char *fmt_string,...)
Emit a warning-level message.
void warn(const char *fmt_string,...)
Emit a warning-level message.
void stat(const char *fmt_string,...)
Emit a status-level message.
int level_limit
logger threshold level
void log(LogLevel level_entry, const char *fmt_string,...)
Log a message at the specified level.
void reset_level(LogLevel level)
Reset the logger threshold level.
float progress
progress value in [0, 1] interval
int task_count
total task count
ProgressBar(int task_count, std::string name="")
Construct a progress bar.
void set_task_idx(int task_idx)
Set current (or initial) task index.
void set_nodes(std::vector< float > nodes)
Set progress bar width.
void set_bar_width(int bar_width)
Set progress bar width.
std::string name
progress bar name
void update(int task_idx_now)
Update the progress bar.
void set_progress(float progress)
Set current (or initial) progress value.
virtual const char * what() const noexcept
Exception string representation.
std::string err_mesg
error message
UnimplementedError(const char *fmt_string,...)
Construct an trv::sys::UnimplementedError exception.
double gbytesMem
current memory usage in gibibytes
bool has_extension(const std::string &fname, const std::string &fext)
Check if a file has a given extension.
void display_help()
Display help message in stdout.
void update_maxmem(bool gpu=false)
Update the maximum memory usage estimate.
std::string show_timestamp()
Return the timestamp string including the elapsed time.
double size_in_gb(long long num)
Return size in gibibytes.
void expand_envar_in_path(std::string &path_str)
Expand environment variables in a path string.
std::vector< int > get_gpu_ids()
Get the indices of GPUs available for use.
bool fftw_wisdom_b_imported
wisdom import status for backward transform
bool is_gpu_enabled()
Check if GPU mode is enabled.
bool is_gpu_available()
Check if GPUs are available in the system.
void display_prog_logo()
Display program logo in stdout.
bool fftw_wisdom_f_imported
wisdom import status for forward transform
float max_count_grid
maximum number of grids
Logger logger
default logger (at NSET logging level)
int max_count_rgrid
maximum number of 3-d real grids
std::string show_current_datetime(bool utc=false)
Return the current datetime string.
float count_grid
number of grids
void display_prog_licence(bool brief=false)
Display program licence in stdout.
double gbytesMemGPU
current (GPU) memory usage in gibibytes
double gbytesMaxMemGPU
maximum (GPU) memory usage in gibibytes
int max_count_cgrid
maximum number of 3-d complex grids
void display_prog_logbars(int endpoint)
Display program log bars in stdout.
std::vector< float > set_nodes_by_str(std::string interval_str)
Set a node list possibly from a string.
int get_gpu_count(bool sys=false)
Get the number of GPUs available.
bool is_gpu_single()
Check if in single-GPU mode.
int count_fft
number of FFTs
int count_cgrid
number of 3-d complex grids
double gbytesMaxMem
maximum memory usage in gibibytes
std::vector< std::string > split_string(const std::string &str, const std::string &delimiter)
Split a string into a vector of strings.
int count_rgrid
number of 3-d real grids
std::string join_strings(const std::vector< std::string > &strings, const std::string &delimiter)
Join a vector of strings with a delimiter.
int count_ifft
number of IFFTs
void update_maxcntgrid()
Update the maximum 3-d grid counts.
void display_prog_info(bool runtime=false)
Display program information in stdout.
void exit_fatal(const std::string &msg)
Terminate the program with exit status EXIT_FAILURE.
bool is_colourable()
Check if the program stdout is colourable.
std::string show_elapsed_time(double duration_in_seconds)
Return the elapsed-time string in 'HH:MM:SS' format.
std::string get_build_datetime()
Return the build datetime string in ISO 8601–like format.