Triumvirate C++ API 0.5.0
Three-point clustering measurements in large-scale structure analyses.
Loading...
Searching...
No Matches
monitor.hpp
Go to the documentation of this file.
1// Copyright (C) [GPLv3 Licence]
2//
3// This file is part of the Triumvirate program. See the COPYRIGHT
4// and LICENCE files at the top-level directory of this distribution
5// for details of copyright and licensing.
6//
7// This program is free software: you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15// See the GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <https://www.gnu.org/licenses/>.
19
32#ifndef TRIUMVIRATE_INCLUDE_MONITOR_HPP_INCLUDED_
33#define TRIUMVIRATE_INCLUDE_MONITOR_HPP_INCLUDED_
34
35#include <chrono>
36#include <cstdarg>
37#include <cstdio>
38#include <iostream>
39#include <stdexcept>
40#include <string>
41#include <vector>
42
43#include <fftw3.h>
44#include <gsl/gsl_version.h>
45
47// Declares OMP macros.
48#ifdef TRV_USE_OMP
49#include <omp.h>
50#define OMP_ATOMIC _Pragma("omp atomic")
51#define OMP_CRITICAL _Pragma("omp critical")
52#else // !TRV_USE_OMP
53#define OMP_ATOMIC
54#define OMP_CRITICAL
55#endif // TRV_USE_OMP
57
58// Enter debugging mode.
59#ifdef DBG_MODE
60#include <iostream>
61#endif // DBG_MODE
62
63namespace trv {
64namespace sys {
65
66// ***********************************************************************
67// Program tracking
68// ***********************************************************************
69
70// STYLE: Standard naming convention is not followed below.
71
72// RFE: Implement MPI.
73extern int currTask;
74
75extern double gbytesMem;
76extern double gbytesMaxMem;
77
78extern int count_rgrid;
79extern int count_cgrid;
80extern float count_grid;
81extern int max_count_rgrid;
82extern int max_count_cgrid;
83extern float max_count_grid;
84
85extern int count_fft;
86extern int count_ifft;
87
89extern bool fftw_wisdom_f_imported;
91extern bool fftw_wisdom_b_imported;
92
100template <typename T>
101double size_in_gb(long long num) {
102 const double BYTES_PER_GBYTES = 1073741824.; // 1024³ bytes per gibibyte
103 return double(num) * sizeof(T) / BYTES_PER_GBYTES;
104}
105
115template <typename T>
116double size_in_gb(int num) {
117 const double BYTES_PER_GBYTES = 1073741824.; // 1024³ bytes per gibibyte
118 return double(num) * sizeof(T) / BYTES_PER_GBYTES;
119}
120
125void update_maxmem();
126
131void update_maxcntgrid();
132
139std::string show_current_datetime();
140
147std::string show_elapsed_time(double duration_in_seconds);
148
154std::string show_timestamp();
155
161 // CAVEAT: Discretionary choices.
162 NSET = 0,
163 DBUG = 10,
164 STAT = 20,
165 INFO = 30,
166 WARN = 40,
167 ERRO = 50
169
174class Logger {
175 public:
177
184 Logger(LogLevel level);
185
194 Logger(int level);
195
201 void reset_level(LogLevel level);
202
210 void reset_level(int level);
211
222 void log(LogLevel level_entry, const char* fmt_string, ...);
223
236 void log(int level_entry, const char* fmt_string, ...);
237
246 void debug(const char* fmt_string, ...);
247
256 void stat(const char* fmt_string, ...);
257
266 void info(const char* fmt_string, ...);
267
276 void warn(const char* fmt_string, ...);
277
286 void error(const char* fmt_string, ...);
287
288 private:
289 void emit(std::string log_type, const char* fmt_string, std::va_list args);
290};
291
292extern Logger logger;
293
299 public:
300 std::string name;
301 int task_count = 1;
302 int task_idx = 0;
303 float progress = 0.;
304
311 explicit ProgressBar(int task_count, std::string name = "");
312
318 void set_bar_width(int bar_width);
319
326 void set_nodes(std::vector<float> nodes);
327
335 void set_task_idx(int task_idx);
336
342 void set_progress(float progress);
343
351 void update(int task_idx_now);
352
360 void update(float progress_now);
361
362 private:
363 int bar_width = 50;
364
365 std::vector<float> nodes;
366 int next_node_idx = 0;
367
372 void set_default_pcpt_nodes();
373};
374
375
376// ***********************************************************************
377// Program exceptions
378// ***********************************************************************
379
384class UnimplementedError: public std::logic_error {
385 public:
386 std::string err_mesg;
387
394 UnimplementedError(const char* fmt_string, ...);
395
401 virtual const char* what() const noexcept;
402};
403
408class IOError: public std::runtime_error {
409 public:
410 std::string err_mesg;
411
418 IOError(const char* fmt_string, ...);
419
425 virtual const char* what() const noexcept;
426};
427
432class InvalidParameterError: public std::invalid_argument {
433 public:
434 std::string err_mesg;
435
442 InvalidParameterError(const char* fmt_string, ...);
443
449 virtual const char* what() const noexcept;
450};
451
456class InvalidDataError: public std::runtime_error {
457 public:
458 std::string err_mesg;
459
466 InvalidDataError(const char* fmt_string, ...);
467
473 virtual const char* what() const noexcept;
474};
475
476
477// ***********************************************************************
478// Program notices
479// ***********************************************************************
480
485void display_prog_logo();
486
492
497void display_prog_info();
498
504void display_prog_logbars(int endpoint);
505
506} // namespace trv::sys
507} // namespace trv
508
509#endif // !TRIUMVIRATE_INCLUDE_MONITOR_HPP_INCLUDED_
Exception raised when an input/output operation fails.
Definition monitor.hpp:408
std::string err_mesg
error message
Definition monitor.hpp:410
Exception raised when the data to be operated on are invalid.
Definition monitor.hpp:456
std::string err_mesg
error message
Definition monitor.hpp:458
Exception raised when parameters are invalid.
Definition monitor.hpp:432
std::string err_mesg
error message
Definition monitor.hpp:434
Logger with logging level differentiation.
Definition monitor.hpp:174
Logger(LogLevel level)
Construct the logger with the specified threshold level.
Definition monitor.cpp:148
void info(const char *fmt_string,...)
Emit a information-level message.
Definition monitor.cpp:264
void debug(const char *fmt_string,...)
Emit a debugging-level message.
Definition monitor.cpp:246
void error(const char *fmt_string,...)
Emit a warning-level message.
Definition monitor.cpp:282
void warn(const char *fmt_string,...)
Emit a warning-level message.
Definition monitor.cpp:273
void stat(const char *fmt_string,...)
Emit a status-level message.
Definition monitor.cpp:255
int level_limit
logger threshold level
Definition monitor.hpp:176
void log(LogLevel level_entry, const char *fmt_string,...)
Log a message at the specified level.
Definition monitor.cpp:177
void reset_level(LogLevel level)
Reset the logger threshold level.
Definition monitor.cpp:156
Progress bar for tracking tasks.
Definition monitor.hpp:298
float progress
progress value in [0, 1] interval
Definition monitor.hpp:303
int task_count
total task count
Definition monitor.hpp:301
ProgressBar(int task_count, std::string name="")
Construct a progress bar.
Definition monitor.cpp:291
void set_task_idx(int task_idx)
Set current (or initial) task index.
Definition monitor.cpp:320
void set_nodes(std::vector< float > nodes)
Set progress bar width.
Definition monitor.cpp:311
int task_idx
task index
Definition monitor.hpp:302
void set_bar_width(int bar_width)
Set progress bar width.
Definition monitor.cpp:304
std::string name
progress bar name
Definition monitor.hpp:300
void update(int task_idx_now)
Update the progress bar.
Definition monitor.cpp:347
void set_progress(float progress)
Set current (or initial) progress value.
Definition monitor.cpp:333
Exception raised when a function or method is unimplemented.
Definition monitor.hpp:384
virtual const char * what() const noexcept
Exception string representation.
Definition monitor.cpp:415
std::string err_mesg
error message
Definition monitor.hpp:386
UnimplementedError(const char *fmt_string,...)
Construct an trv::sys::UnimplementedError exception.
Definition monitor.cpp:401
double gbytesMem
current memory usage in gibibytes
Definition monitor.cpp:46
std::string show_timestamp()
Return the timestamp string including the elapsed time.
Definition monitor.cpp:128
double size_in_gb(long long num)
Return size in gibibytes.
Definition monitor.hpp:101
void update_maxmem()
Update the maximum memory usage estimate.
Definition monitor.cpp:68
void display_prog_licence()
Display program licence in stdout.
Definition monitor.cpp:489
bool fftw_wisdom_b_imported
wisdom import status for backward transform
Definition monitor.cpp:60
void display_prog_logo()
Display program logo in stdout.
Definition monitor.cpp:475
bool fftw_wisdom_f_imported
wisdom import status for forward transform
Definition monitor.cpp:59
float max_count_grid
maximum number of grids
Definition monitor.cpp:54
Logger logger
default logger (at NSET logging level)
int max_count_rgrid
maximum number of 3-d real grids
Definition monitor.cpp:52
float count_grid
number of grids
Definition monitor.cpp:51
int max_count_cgrid
maximum number of 3-d complex grids
Definition monitor.cpp:53
std::string show_current_datetime()
Return the current date-time string in 'YYYY-MM-DD HH:MM:SS' format.
Definition monitor.cpp:85
int currTask
current task
Definition monitor.cpp:44
void display_prog_logbars(int endpoint)
Display program log bars in stdout.
Definition monitor.cpp:534
LogLevel
Logging levels.
Definition monitor.hpp:160
@ NSET
0: unset
Definition monitor.hpp:162
@ INFO
30: info
Definition monitor.hpp:165
@ STAT
20: status
Definition monitor.hpp:164
@ WARN
40: warning
Definition monitor.hpp:166
@ ERRO
50: error/critical
Definition monitor.hpp:167
@ DBUG
10: debugging
Definition monitor.hpp:163
int count_fft
number of FFTs
Definition monitor.cpp:56
int count_cgrid
number of 3-d complex grids
Definition monitor.cpp:50
double gbytesMaxMem
maximum memory usage in gibibytes
Definition monitor.cpp:47
int count_rgrid
number of 3-d real grids
Definition monitor.cpp:49
int count_ifft
number of IFFTs
Definition monitor.cpp:57
void update_maxcntgrid()
Update the maximum 3-d grid counts.
Definition monitor.cpp:73
void display_prog_info()
Display program information in stdout.
Definition monitor.cpp:508
std::string show_elapsed_time(double duration_in_seconds)
Return the elapsed-time string in 'HH:MM:SS' format.
Definition monitor.cpp:102