12#include <boost/stacktrace.hpp>
17# include <sys/ioctl.h>
18# define _isatty isatty
20#if defined(_WIN32) || defined(__WINDOWS_)
29 std::cerr <<
"Signal " + std::to_string(signal) << std::endl;
30 std::signal(signal, SIG_DFL);
38 if (&ostream == &std::cout)
39 return _isatty(fileno(stdout));
40 if (&ostream == &std::cerr)
41 return _isatty(fileno(stderr));
60 CONSOLE_SCREEN_BUFFER_INFO csbi;
61 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
63 return csbi.srWindow.Right - csbi.srWindow.Left + 1;
67 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == 0)
77 progress = std::clamp(progress, 0.0, 1.0);
79 int bar_width = std::max(10, term_width - 10);
81 int pos =
static_cast<int>(bar_width * progress);
86 for (
int i = 0; i < bar_width; ++i)
95 os <<
"] " << std::setw(3) <<
static_cast<int>(progress * 100) <<
"% " << std::flush;
99 os <<
"[" << std::string(pos,
'=') <<
">" << std::string(bar_width - pos,
' ')
100 <<
"] " << std::setw(3) <<
static_cast<int>(progress * 100) <<
"%" << std::endl;
110 DISABLE_WARNING_DEPRECATED_DECLARATIONS
111 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
112 return converter.to_bytes(
v);
124 const char *env = std::getenv(
"OMP_NUM_THREADS");
129 ret = std::stoi(env);
144 const char *env = std::getenv(
"DNDS_DIST_OMP_NUM_THREADS");
149 ret = std::stoi(env);
164 std::stringstream ss;
165 ss << boost::stacktrace::stacktrace();
174 static std::string ver_name =
"UNKNOWN";
void DNDS_signal_handler(int signal)
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DISABLE_WARNING_PUSH
#define DISABLE_WARNING_POP
the host side operators are provided as implemented
ssp< std::ostream > logStream
Shared output stream: where DNDS::log() writes progress / diagnostics.
int get_env_OMP_NUM_THREADS()
Read OMP_NUM_THREADS env var, returning 1 if unset / invalid.
void setLogStream(ssp< std::ostream > nstream)
Redirect log() output to a user-supplied stream. Ownership is shared.
bool logIsTTY()
Convenience: ostreamIsTTY applied to the current log() stream.
std::string getTraceString()
Return a symbolicated stack trace for the calling thread.
int get_terminal_width()
Terminal width in columns (falls back to a fixed default when not a TTY).
std::string getStringForceWString(const std::wstring &v)
Convert a wstring to string (UTF-8 on Windows, byte-cast elsewhere).
int get_env_DNDS_DIST_OMP_NUM_THREADS()
Read the DNDSR-specific DNDS_DIST_OMP_NUM_THREADS override, falling back to get_env_OMP_NUM_THREADS.
std::shared_ptr< T > ssp
Shortened alias for std::shared_ptr used pervasively in DNDSR.
bool ostreamIsTTY(std::ostream &ostream)
Heuristic detection of whether ostream is attached to a terminal.
void print_progress(std::ostream &os, double progress)
Render a textual progress bar to os for progress in [0, 1].
std::ostream & log()
Return the current DNDSR log stream (either std::cout or the installed file).
bool useCout
Whether DNDS::log() is currently routed to std::cout.
void setLogStreamCout()
Restore the default std::cout routing for log().
std::string GetSetVersionName(const std::string &ver)
Read/set the build version string accessible from code.
Eigen::Matrix< real, 5, 1 > v