gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
GmshMessage.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef GMSH_MESSAGE_H
7 #define GMSH_MESSAGE_H
8 
9 #include <map>
10 #include <vector>
11 #include <string>
12 #include <atomic>
13 #include <stdarg.h>
14 
15 #include "GmshConfig.h"
16 
17 class GmshClient;
18 namespace onelab {
19  class client;
20 }
21 
22 // the external message handler
23 class GmshMessage {
24 public:
26  virtual ~GmshMessage() {}
27  virtual void operator()(std::string level, std::string message) {}
28 };
29 
30 // a class to manage messages and communications
31 class Msg {
32 private:
33  // current cpu number and total number of cpus
34  static int _commRank, _commSize;
35  // verbosity level (0: silent except fatal errors, 1: +errors, 2: +warnings,
36  // 3: +direct, 4: +info, 5 (=normal): +statusbar, 99: debug)
37  static int _verbosity;
38  // step (in %) of the progress meter and current progress (in %)
39  static int _progressMeterStep;
40  static std::atomic<int> _progressMeterCurrent;
41  // total number of items considered in the current progress meter calculation
42  static int _progressMeterTotal;
43  // timers
44  static std::map<std::string, double> _timers;
45  // report cpu time for each info message?
46  static bool _infoCpu;
47  // report memory for each info message?
48  static bool _infoMem;
49  // starting time (gettimeofday at startup)
50  static double _startTime;
51  // counters
53  static std::string _firstWarning, _firstError, _lastError;
54  // callback
56  // command-line and startup time
57  static std::vector<std::string> _commandLineArgs;
58  static std::string _launchDate;
59  // command-line-specified numbers and strings
60  static std::map<std::string, std::vector<double> > _commandLineNumbers;
61  static std::map<std::string, std::string> _commandLineStrings;
62  // communication with Gmsh when run remotely
64 #if defined(HAVE_ONELAB)
65  // communication with onelab server
66  static onelab::client *_onelabClient;
67 #endif
68  // executable name
69  static std::string _execName;
70  // log file
71  static std::string _logFileName;
72  static FILE *_logFile;
73 
74 public:
75  Msg() {}
76  static void Initialize(int argc, char **argv);
77  static void Finalize();
78  static void Exit(int level);
79  static int GetCommRank();
80  static int GetCommSize();
81  static void SetCommRank(int val);
82  static void SetCommSize(int val);
83  static void SetCallback(GmshMessage *callback);
84  static GmshMessage *GetCallback();
85  static void Barrier();
86  static int GetNumThreads();
87  static void SetNumThreads(int num);
88  static int GetMaxThreads();
89  static int GetThreadNum();
90  static void SetVerbosity(int val);
91  static void SetLogFile(const std::string &name);
92  static int GetVerbosity();
93  static std::string GetLaunchDate();
94  static std::string GetCommandLineFull();
95  static std::vector<std::string> &GetCommandLineArgs();
96  static std::map<std::string, std::vector<double> > &GetCommandLineNumbers();
97  static std::map<std::string, std::string> &GetCommandLineStrings();
98  static std::string PrintResources(bool printDate, bool printWallTime,
99  bool printCpu, bool printMem);
100  static void Error(const char *fmt, ...);
101  static void Warning(const char *fmt, ...);
102  static void Info(const char *fmt, ...);
103  static void RequestRender();
104  static void Direct(const char *fmt, ...);
105  static void Auto(const char *fmt, ...);
106  static void StatusBar(bool log, const char *fmt, ...);
107  static void StatusGl(const char *fmt, ...);
108  static void SetWindowTitle(const std::string &title);
109  static void Debug(const char *fmt, ...);
110  static void StartProgressMeter(int ntotal);
111  static void ProgressMeter(int n, bool log, const char *fmt, ...);
112  static void StopProgressMeter();
113  static void SetProgressMeterStep(int step);
114  static int GetProgressMeterStep();
115  static void SetInfoCpu(bool val);
116  static void SetInfoMem(bool val);
117  static double &Timer(const std::string &str);
118  static void PrintTimers();
119  static void ResetErrorCounter();
120  static void PrintErrorCounter(const char *title);
121  static int GetWarningCount();
122  static int GetErrorCount();
123  static std::string GetFirstWarning();
124  static std::string GetFirstError();
125  static std::string GetLastError();
126  static double GetValue(const char *text, double defaultval);
127  static std::string GetString(const char *text, const std::string &defaultval);
128  static int GetAnswer(const char *question, int defaultval, const char *zero,
129  const char *one, const char *two = nullptr);
130  static void InitializeOnelab(const std::string &name,
131  const std::string &sockname = "");
132  static void FinalizeOnelab();
133  static void SetExecutableName(const std::string &name);
134  static std::string GetExecutableName();
135  static void LoadOnelabClient(const std::string &name,
136  const std::string &sockName);
137  static int GetNumOnelabClients();
138  static GmshClient *GetGmshClient();
139 #if defined(HAVE_ONELAB)
140  static onelab::client *GetOnelabClient();
141 #endif
142  static bool UseOnelab();
143  static void SetOnelabNumber(const std::string &name, double val,
144  bool visible = true, bool persistent = false,
145  bool readOnly = false, int changedValue = 3);
146  static void SetOnelabNumber(const std::string &name, const std::vector<double> &val,
147  bool visible = true);
148  static void SetOnelabString(const std::string &name, const std::string &val,
149  bool visible = true, bool persistent = false,
150  bool readOnly = false, int changedValue = 3,
151  const std::string &kind = "");
152  static double GetOnelabNumber(const std::string &name,
153  double defaultValue = 0.,
154  bool errorIfMissing = false);
155  static std::string GetOnelabString(const std::string &name,
156  const std::string &defaultValue = "",
157  bool errorIfMissing = false);
158  static void AddOnelabStringChoice(const std::string &name,
159  const std::string &kind,
160  const std::string &value,
161  bool updateValue = true,
162  bool readOnly = false, bool visible = true);
163  static void SetOnelabAction(const std::string &action);
164  static std::string GetOnelabAction();
165  static void ExchangeOnelabParameter(
166  const std::string &key, std::vector<double> &val,
167  std::map<std::string, std::vector<double> > &fopt,
168  std::map<std::string, std::vector<std::string> > &copt);
169  static void ExchangeOnelabParameter(
170  const std::string &key, std::string &val,
171  std::map<std::string, std::vector<double> > &fopt,
172  std::map<std::string, std::vector<std::string> > &copt);
173  static void UndefineOnelabParameter(const std::string &name);
174  static void RunOnelabClient(const std::string &name,
175  const std::string &exe = "");
176  static void SetOnelabChanged(int value, const std::string &client = "Gmsh");
177  static void ImportPhysicalGroupsInOnelab();
178 };
179 
180 // a class to print the progression and estimated remaining time
182 private:
187 
188 public:
189  MsgProgressStatus(int numElementToTreat);
191  void setInitialTime(double time) { _initialTime = time; }
192  void next();
193 };
194 
195 #endif
GmshMessage::operator()
virtual void operator()(std::string level, std::string message)
Definition: GmshMessage.h:27
Msg::GetCallback
static GmshMessage * GetCallback()
Definition: GmshMessage.cpp:244
Msg::SetOnelabAction
static void SetOnelabAction(const std::string &action)
Definition: GmshMessage.cpp:1213
Msg::_progressMeterCurrent
static std::atomic< int > _progressMeterCurrent
Definition: GmshMessage.h:40
Msg::_commRank
static int _commRank
Definition: GmshMessage.h:34
Msg::GetProgressMeterStep
static int GetProgressMeterStep()
Definition: GmshMessage.cpp:307
Msg::GetCommandLineStrings
static std::map< std::string, std::string > & GetCommandLineStrings()
Definition: GmshMessage.cpp:297
Msg::GetVerbosity
static int GetVerbosity()
Definition: GmshMessage.cpp:254
Msg::_atLeastOneErrorInRun
static int _atLeastOneErrorInRun
Definition: GmshMessage.h:52
Msg::SetInfoMem
static void SetInfoMem(bool val)
Definition: GmshMessage.cpp:335
Msg::GetFirstError
static std::string GetFirstError()
Definition: GmshMessage.cpp:357
Msg::Info
static void Info(const char *fmt,...)
Definition: GmshMessage.cpp:587
Msg::RunOnelabClient
static void RunOnelabClient(const std::string &name, const std::string &exe="")
Definition: GmshMessage.cpp:1605
Msg::Msg
Msg()
Definition: GmshMessage.h:75
Msg::GetOnelabNumber
static double GetOnelabNumber(const std::string &name, double defaultValue=0., bool errorIfMissing=false)
Definition: GmshMessage.cpp:1084
Msg::Debug
static void Debug(const char *fmt,...)
Definition: GmshMessage.cpp:752
Msg::_infoCpu
static bool _infoCpu
Definition: GmshMessage.h:46
MsgProgressStatus::next
void next()
Definition: GmshMessage.cpp:1658
Msg::_progressMeterStep
static int _progressMeterStep
Definition: GmshMessage.h:39
Msg::Warning
static void Warning(const char *fmt,...)
Definition: GmshMessage.cpp:543
Msg::_commandLineNumbers
static std::map< std::string, std::vector< double > > _commandLineNumbers
Definition: GmshMessage.h:60
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
Msg::StatusBar
static void StatusBar(bool log, const char *fmt,...)
Definition: GmshMessage.cpp:686
Msg::Timer
static double & Timer(const std::string &str)
Definition: GmshMessage.cpp:340
Msg::GetCommandLineFull
static std::string GetCommandLineFull()
Definition: GmshMessage.cpp:282
Msg::SetExecutableName
static void SetExecutableName(const std::string &name)
Definition: GmshMessage.cpp:367
Msg::ImportPhysicalGroupsInOnelab
static void ImportPhysicalGroupsInOnelab()
Definition: GmshMessage.cpp:1523
MsgProgressStatus::_lastTime
double _lastTime
Definition: GmshMessage.h:184
Msg::SetProgressMeterStep
static void SetProgressMeterStep(int step)
Definition: GmshMessage.cpp:302
Msg::GetGmshClient
static GmshClient * GetGmshClient()
Definition: GmshMessage.cpp:1272
Msg::StatusGl
static void StatusGl(const char *fmt,...)
Definition: GmshMessage.cpp:727
Msg::Initialize
static void Initialize(int argc, char **argv)
Definition: GmshMessage.cpp:125
Msg::_commandLineArgs
static std::vector< std::string > _commandLineArgs
Definition: GmshMessage.h:57
Msg::GetValue
static double GetValue(const char *text, double defaultval)
Definition: GmshMessage.cpp:900
Msg::PrintTimers
static void PrintTimers()
Definition: GmshMessage.cpp:828
Msg::ExchangeOnelabParameter
static void ExchangeOnelabParameter(const std::string &key, std::vector< double > &val, std::map< std::string, std::vector< double > > &fopt, std::map< std::string, std::vector< std::string > > &copt)
Definition: GmshMessage.cpp:1348
Msg::AddOnelabStringChoice
static void AddOnelabStringChoice(const std::string &name, const std::string &kind, const std::string &value, bool updateValue=true, bool readOnly=false, bool visible=true)
Definition: GmshMessage.cpp:1045
MsgProgressStatus::MsgProgressStatus
MsgProgressStatus(int numElementToTreat)
Definition: GmshMessage.cpp:1642
Msg::SetCommSize
static void SetCommSize(int val)
Definition: GmshMessage.cpp:234
GmshClient
Definition: GmshSocket.h:261
Msg::GetThreadNum
static int GetThreadNum()
Definition: GmshMessage.cpp:1638
Msg::SetNumThreads
static void SetNumThreads(int num)
Definition: GmshMessage.cpp:1636
Msg::SetOnelabString
static void SetOnelabString(const std::string &name, const std::string &val, bool visible=true, bool persistent=false, bool readOnly=false, int changedValue=3, const std::string &kind="")
Definition: GmshMessage.cpp:1021
Msg::_errorCount
static int _errorCount
Definition: GmshMessage.h:52
Msg::Finalize
static void Finalize()
Definition: GmshMessage.cpp:195
MsgProgressStatus::_nextIToCheck
int _nextIToCheck
Definition: GmshMessage.h:183
Msg::Barrier
static void Barrier()
Definition: GmshMessage.cpp:1619
Msg::_infoMem
static bool _infoMem
Definition: GmshMessage.h:48
Msg::UseOnelab
static bool UseOnelab()
Definition: GmshMessage.cpp:978
Msg::InitializeOnelab
static void InitializeOnelab(const std::string &name, const std::string &sockname="")
Definition: GmshMessage.cpp:1155
Msg::GetCommRank
static int GetCommRank()
Definition: GmshMessage.cpp:219
Msg
Definition: GmshMessage.h:31
Msg::GetFirstWarning
static std::string GetFirstWarning()
Definition: GmshMessage.cpp:352
MsgProgressStatus::setInitialTime
void setInitialTime(double time)
Definition: GmshMessage.h:191
Msg::PrintErrorCounter
static void PrintErrorCounter(const char *title)
Definition: GmshMessage.cpp:859
Msg::GetString
static std::string GetString(const char *text, const std::string &defaultval)
Definition: GmshMessage.cpp:927
onelab
Definition: GmshMessage.h:18
MsgProgressStatus
Definition: GmshMessage.h:181
Msg::StopProgressMeter
static void StopProgressMeter()
Definition: GmshMessage.cpp:318
Msg::SetOnelabChanged
static void SetOnelabChanged(int value, const std::string &client="Gmsh")
Definition: GmshMessage.cpp:1612
Msg::GetMaxThreads
static int GetMaxThreads()
Definition: GmshMessage.cpp:1637
Msg::SetCallback
static void SetCallback(GmshMessage *callback)
Definition: GmshMessage.cpp:239
Msg::_logFile
static FILE * _logFile
Definition: GmshMessage.h:72
Msg::SetWindowTitle
static void SetWindowTitle(const std::string &title)
Definition: GmshMessage.cpp:743
MsgProgressStatus::_currentI
int _currentI
Definition: GmshMessage.h:183
Msg::PrintResources
static std::string PrintResources(bool printDate, bool printWallTime, bool printCpu, bool printMem)
Definition: GmshMessage.cpp:436
Msg::_callback
static GmshMessage * _callback
Definition: GmshMessage.h:55
Msg::_execName
static std::string _execName
Definition: GmshMessage.h:69
GmshMessage
Definition: GmshMessage.h:23
Msg::Exit
static void Exit(int level)
Definition: GmshMessage.cpp:384
Msg::GetCommSize
static int GetCommSize()
Definition: GmshMessage.cpp:224
GmshMessage::~GmshMessage
virtual ~GmshMessage()
Definition: GmshMessage.h:26
Msg::_commSize
static int _commSize
Definition: GmshMessage.h:34
Msg::_verbosity
static int _verbosity
Definition: GmshMessage.h:37
Msg::LoadOnelabClient
static void LoadOnelabClient(const std::string &name, const std::string &sockName)
Definition: GmshMessage.cpp:1237
MsgProgressStatus::_progressMeterStep
int _progressMeterStep
Definition: GmshMessage.h:186
Msg::GetLastError
static std::string GetLastError()
Definition: GmshMessage.cpp:362
Msg::FinalizeOnelab
static void FinalizeOnelab()
Definition: GmshMessage.cpp:1196
Msg::GetLaunchDate
static std::string GetLaunchDate()
Definition: GmshMessage.cpp:272
Msg::GetNumOnelabClients
static int GetNumOnelabClients()
Definition: GmshMessage.cpp:1277
Msg::ResetErrorCounter
static void ResetErrorCounter()
Definition: GmshMessage.cpp:850
Msg::GetWarningCount
static int GetWarningCount()
Definition: GmshMessage.cpp:342
Msg::_warningCount
static int _warningCount
Definition: GmshMessage.h:52
Msg::GetCommandLineNumbers
static std::map< std::string, std::vector< double > > & GetCommandLineNumbers()
Definition: GmshMessage.cpp:292
Msg::Direct
static void Direct(const char *fmt,...)
Definition: GmshMessage.cpp:634
Msg::GetCommandLineArgs
static std::vector< std::string > & GetCommandLineArgs()
Definition: GmshMessage.cpp:277
Msg::_launchDate
static std::string _launchDate
Definition: GmshMessage.h:58
Msg::GetAnswer
static int GetAnswer(const char *question, int defaultval, const char *zero, const char *one, const char *two=nullptr)
Definition: GmshMessage.cpp:952
Msg::_startTime
static double _startTime
Definition: GmshMessage.h:50
MsgProgressStatus::_totalElementToTreat
int _totalElementToTreat
Definition: GmshMessage.h:183
Msg::StartProgressMeter
static void StartProgressMeter(int ntotal)
Definition: GmshMessage.cpp:312
Msg::_firstWarning
static std::string _firstWarning
Definition: GmshMessage.h:53
MsgProgressStatus::~MsgProgressStatus
~MsgProgressStatus()
Definition: GmshMessage.cpp:1651
MsgProgressStatus::_lastPercentage
int _lastPercentage
Definition: GmshMessage.h:185
Msg::GetNumThreads
static int GetNumThreads()
Definition: GmshMessage.cpp:1635
Msg::_progressMeterTotal
static int _progressMeterTotal
Definition: GmshMessage.h:42
Msg::SetVerbosity
static void SetVerbosity(int val)
Definition: GmshMessage.cpp:249
GmshMessage::GmshMessage
GmshMessage()
Definition: GmshMessage.h:25
Msg::_lastError
static std::string _lastError
Definition: GmshMessage.h:53
Msg::_logFileName
static std::string _logFileName
Definition: GmshMessage.h:71
Msg::_firstError
static std::string _firstError
Definition: GmshMessage.h:53
onelab::client
Definition: onelab.h:1201
Msg::_client
static GmshClient * _client
Definition: GmshMessage.h:63
Msg::SetOnelabNumber
static void SetOnelabNumber(const std::string &name, double val, bool visible=true, bool persistent=false, bool readOnly=false, int changedValue=3)
Definition: GmshMessage.cpp:987
Msg::RequestRender
static void RequestRender()
Definition: GmshMessage.cpp:629
Msg::_timers
static std::map< std::string, double > _timers
Definition: GmshMessage.h:44
Msg::ProgressMeter
static void ProgressMeter(int n, bool log, const char *fmt,...)
Definition: GmshMessage.cpp:783
Msg::Auto
static void Auto(const char *fmt,...)
Definition: GmshMessage.cpp:671
Msg::UndefineOnelabParameter
static void UndefineOnelabParameter(const std::string &name)
Definition: GmshMessage.cpp:1515
Msg::GetOnelabString
static std::string GetOnelabString(const std::string &name, const std::string &defaultValue="", bool errorIfMissing=false)
Definition: GmshMessage.cpp:1105
Msg::GetOnelabAction
static std::string GetOnelabAction()
Definition: GmshMessage.cpp:1225
Msg::GetErrorCount
static int GetErrorCount()
Definition: GmshMessage.cpp:347
Msg::GetExecutableName
static std::string GetExecutableName()
Definition: GmshMessage.cpp:372
Msg::SetCommRank
static void SetCommRank(int val)
Definition: GmshMessage.cpp:229
Msg::SetLogFile
static void SetLogFile(const std::string &name)
Definition: GmshMessage.cpp:259
Msg::_commandLineStrings
static std::map< std::string, std::string > _commandLineStrings
Definition: GmshMessage.h:61
Msg::SetInfoCpu
static void SetInfoCpu(bool val)
Definition: GmshMessage.cpp:330
MsgProgressStatus::_initialTime
double _initialTime
Definition: GmshMessage.h:184