24 template<
typename StackType,
typename ErrorType,
typename ProfilerType>
68 GlobalObj() : _debug_level(0), _log_level(0), _verb_level(1),
70 _OutStream(&
std::cout), _LogStream(NULL),
71 _ErrStream(&
std::cerr),_Profiler(NULL),
72 _profiling_enabled(false),_profiler_mine(false),_write_profiles(true),
73 _name(
""), _OutStreamSave(NULL), _ErrStreamSave(NULL),
74 _DebugStreamSave(NULL)
83 _debug_level(0), _log_level(0), _verb_level(1),
85 _OutStream(&
std::cout), _LogStream(NULL),
86 _ErrStream(&
std::cerr),_Profiler(NULL),
87 _profiling_enabled(false),_profiler_mine(false),_write_profiles(true),
88 _name(
""), _OutStreamSave(NULL), _ErrStreamSave(NULL),
89 _DebugStreamSave(NULL)
99 _debug_level(globin._debug_level), _log_level(globin._log_level),_verb_level(globin._verb_level),
100 _DebugStream(globin._DebugStream), _OutStream(globin._OutStream),
101 _LogStream(globin._LogStream), _ErrStream(globin._ErrStream),
102 _Profiler(globin._Profiler),_profiling_enabled(globin._profiling_enabled),
103 _profiler_mine(false), _write_profiles(true),_name(globin._name), _OutStreamSave(globin._OutStreamSave),
104 _ErrStreamSave(globin._ErrStreamSave), _DebugStreamSave(globin._DebugStreamSave)
107 if(!globin.
_Stack.empty()){
108 typename std::list<StackType>::iterator si = globin.
_Stack.begin();
109 while(si != globin.
_Stack.end())
110 _Stack.push_back(*si++);
119 GlobalObj(
const StackType &name) : _debug_level(0) , _log_level(0), _verb_level(1)
128 GlobalObj(
const StackType &name,
int id) : _debug_level(0), _log_level(0), _verb_level(1)
136 virtual inline int Init(
const StackType &name)
144 if(_Profiler && _profiler_mine)
147 _Profiler->
Init(name,
id);
148 _profiler_mine =
true;
149 _profiling_enabled =
false;
150 _write_profiles =
true;
152 _DebugStream = &std::cout;
153 _ErrStream = &std::cerr;
154 _OutStream = &std::cout;
160 _Stack.push_front(name);
168 virtual inline int Init(
const StackType &name,
unsigned int id)
174 _profiling_enabled =
false;
175 _write_profiles =
false;
176 if(_Profiler && _profiler_mine)
179 _Profiler->
Init(name,
id);
180 _profiler_mine =
true;
187 _DebugStream = &std::cout;
188 _ErrStream = &std::cerr;
189 _OutStream = &std::cout;
195 _Stack.push_front(name);
208 _Profiler->
Finalize(_write_profiles);
209 else if(_profiling_enabled)
212 _profiling_enabled =
false;
220 return(_write_profiles);
225 return(_write_profiles = yn);
230 return(_profiling_enabled);
235 _profiling_enabled = yn;
236 return(_profiling_enabled);
240 virtual inline void Report(std::ostream &ReportStream)
243 _Profiler->
Finalize(_write_profiles);
244 if(_profiling_enabled)
251 virtual inline void Register(
const StackType &stackentry){
252 _Stack.push_front(
FName()+stackentry);
253 if(_debug_level > 1 && _DebugStream)
254 *_DebugStream <<
"GlobalDebugging:Register(" <<
FName()+stackentry <<
")" << std::endl;
262 if(_debug_level > 1 && _DebugStream)
263 *_DebugStream <<
"GlobalDebugging:DeRegister(" <<
FName() + stackentry <<
")" << std::endl;
268 _Stack.push_front(
FName()+stackentry);
269 if(_profiling_enabled && _Profiler)
271 if(_debug_level > 1 && _DebugStream)
272 *_DebugStream <<
"GlobalDebugging:FunctionEntry(" <<
FName() + stackentry <<
")" << std::endl;
278 if(_profiling_enabled && _Profiler)
280 if(_debug_level > 1 && _DebugStream)
281 *_DebugStream <<
"GlobalDebugging:FunctionExit(" <<
FName() + stackentry <<
")" << std::endl;
292 _Errors.push_front(error);
308 _Profiler->
Dump(Ostr);
316 _DebugStream = &dbstream;
320 std::ostream &
DebugStream(){ assert(_DebugStream);
return(*_DebugStream); };
330 _ErrStream = &dbstream;
334 std::ostream &
ErrStream(){ assert(_ErrStream);
return(*_ErrStream); };
344 _OutStream = &outstream;
348 std::ostream &
OutStream(){ assert(_OutStream);
return(*_OutStream); };
361 _LogStream = &logstream;
365 std::ostream &
LogStream(){ assert(_LogStream);
return(*_LogStream); };
373 if(_profiling_enabled && _Profiler && _Profiler->
FinalizeReady())
378 _Profiler = &profiler;
381 virtual inline void SetName(
const std::string &name) { _name =
FName()+name; };
382 virtual inline void ReName(
const std::string &name) { _name = name; };
383 virtual inline const std::string &
Name(){
return(_name);};
409 _OutStream = &std::cout;
410 _ErrStream = &std::cerr;
411 _DebugStream = &std::cout;
422 virtual inline int ForceOut(
const std::string &outstr,
unsigned char inlev = 1)
424 if(_verb_level >= inlev){
426 std::istringstream Istr(outstr);
427 while(std::getline(Istr,line)){
428 std::cout << (
Name().empty() ?
"" : std::string(
Name()+std::string(
": ")))
430 std::cout << (Istr.good() ?
"\n" :
"");
432 std::flush(std::cout);
439 virtual inline int StdOut(
const std::string &outstr,
unsigned char inlev = 1)
441 if(_OutStream && _verb_level >= inlev){
443 std::istringstream Istr(outstr);
444 while(std::getline(Istr,line)){
445 *_OutStream << (
Name().empty() ?
"" : std::string(
Name()+std::string(
": ")))
447 *_OutStream << (Istr.good() ?
"\n" :
"");
449 std::flush(*_OutStream);
456 virtual inline int ErrOut(
const std::string &outstr)
460 std::istringstream Istr(outstr);
461 while(std::getline(Istr,line)){
462 *_ErrStream << (
Name().empty() ?
"" : std::string(
Name()+std::string(
":")))
463 <<
"Error: " << line;
464 *_ErrStream << (Istr.good() ?
"\n" :
"");
466 std::flush(*_ErrStream);
473 virtual inline int DebugOut(
const std::string &outstr,
int inlev=1)
475 if(_DebugStream && _debug_level >= inlev){
477 std::istringstream Istr(outstr);
478 while(std::getline(Istr,line)){
479 *_DebugStream << (
Name().empty() ?
"" : std::string(
Name()+std::string(
":")))
481 *_DebugStream << (Istr.good() ?
"\n" :
"");
483 std::flush(*_DebugStream);
490 virtual inline int LogOut(
const std::string &outstr,
int inlev=0)
493 if((_LogStream != NULL) && (_log_level >= inlev)){
495 std::istringstream Istr(outstr);
496 while(std::getline(Istr,line)){
497 *_LogStream << timestring
498 << (
Name().empty() ?
"" : std::string(
Name()+std::string(
": ")))
500 *_LogStream << (Istr.good() ?
"\n" :
"");
502 std::flush(*_LogStream);
514 if(_profiler_mine && _Profiler){
521 std::string(
Name()+std::string(
":")))); };
536 profilingBarrier =
false;
541 profilingBarrier =
false;
547 profilingBarrier =
false;
554 profilingBarrier =
false;
561 profilingBarrier =
false;
566 int result =
Init(narg,args);
568 profilingBarrier =
false;
576 profilingBarrier =
false;
580 int retval = globalCommunicator.
Initialize(incomm);
585 virtual inline int Init(
const std::string &name)
589 virtual inline int Init(
const std::string &name,
unsigned int id)
593 virtual inline int Init(
int narg,
char **args)
595 int retval = globalCommunicator.
Initialize(&narg,&args);
616 return(globalCommunicator.
Rank());
620 return(globalCommunicator.
Size());
627 return(globalCommunicator.
Finalize());
633 template<
typename GlobalType,
typename ComLineType>
650 _command_line.Record((
const char **)args);
658 _command_line.Record((
const char **)args);
663 _command_line.Initialize();
664 return(_command_line.ProcessOptions());
667 virtual inline int Run(){
return(0);};
668 virtual inline int Finalize(){
return(GlobalType::Finalize());};
virtual int Init(const std::string &name)
void SetDebugLevel(unsigned char l)
Sets the level of debugging.
int FunctionExit(const std::string &name)
mark construct exit
std::list< ErrorType > _Errors
Errors provides a list for storing caught execution errors for later processing.
virtual int DebugOut(const std::string &outstr, int inlev=1)
ComLineType _command_line
bool FinalizeReady()
Ready to finalize?
void DisableProfilingBarriers()
ProfilerType & Profiler()
Gets the debug stream object.
virtual void DumpProfile(std::ostream &Ostr)
Dumps the timing profile to the indicated stream.
GlobalObj< StackType, ErrorType, ProfilerType > GlobalType
void UnsetOutStream()
Sets outstream to NULL.
std::ostream * _ErrStream
virtual void Report(std::ostream &ReportStream)
Creates the final profiling report on the specified stream.
unsigned char VerbLevel()
Returns the verbosity level.
Performance profiling object.
std::ostream * ErrStreamPtr()
Gets the error stream pointer.
virtual int ErrOut(const std::string &outstr)
virtual int Finalize()
Finalizes the global object, and it's profiler object.
virtual ~ParallelGlobalObj()
std::ostream * _OutStream
std::ostream & LogStream()
Gets the log stream object.
unsigned char _verb_level
Verbosity level.
void DumpContents(std::ostream &Ostr, const ContainerType &c, std::string del="\)
Dump container contents.
void SetLogLevel(unsigned char l)
virtual bool Profiling()
Get profiling state.
std::ostream * _LogStream
Program(int narg, char **args, GlobalType &inglob)
virtual void FunctionExit(const StackType &stackentry)
FunctionExit updates the Stack as well as the Profiler.
int Finalize(bool writeFiles=true)
Shut down profiler.
std::ostream * _ErrStreamSave
Defines MPI-specific parallel global and program classes.
GlobalObj(const StackType &name)
Constructor with args.
std::ostream * _DebugStreamSave
std::ostream * _DebugStream
DebugStream is useful for parallel programs that cannot stream debugging information to the screen...
void SetErrStream(std::ostream &dbstream)
Sets the error stream object.
virtual void DeRegister(const StackType &stackentry)
DeRegister will pop from the stack only.
std::ostream & OutStream()
Gets the stdout stream object.
ComLineType & CommandLine()
void SyncIO()
Syncronize IO - assume control over IO, using established streams.
void SetDebugStream(std::ostream &dbstream)
Sets the debug stream object.
Program(int narg, char **args)
virtual int Init(int narg, char **args)
profiler::ProfilerObj ProfilerType
virtual int Init(const std::string &name, CommunicatorType &incomm)
ix::global::GlobalObj< std::string, std::string, ProfilerType > GlobalType
virtual void DumpErrors(std::ostream &Ostr)
Dumps the errors themselves to the indicated stream.
std::ostream * DebugStreamPtr()
Gets the debug stream pointer.
virtual void DumpStack(std::ostream &Ostr)
Dumps the code construct statck to the indicated stream.
std::list< StackType > _Stack
Stack provides a list for storing the user defined "stack".
void SummarizeSerialExecution(std::ostream &Ostr)
Profiling output for serial application.
virtual void ReName(const std::string &name)
unsigned char _log_level
Logging level.
bool ErrStreamReady()
Checks error stream.
void SetProfiler(ProfilerType &profiler)
Sets the Profiler object.
virtual void FunctionEntry(const StackType &stackentry)
FunctionEntry updates the Stack as well as the Profiler.
ParallelGlobalObj(int narg, char **args, CommunicatorType &incomm)
int Dump(std::ostream &Ostr)
dumps closed events, clears memory
ParallelGlobalObj(const std::string &name)
comm::CommunicatorObject CommunicatorType
Program(GlobalType &inglob)
GlobalObj(GlobalObj< StackType, ErrorType, ProfilerType > &globin)
Constructor with args.
unsigned char LogLevel()
Returns the verbosity level.
unsigned char DebugLevel()
Returns the debugging level.
int FunctionExitAll()
Force all open profiling Events to close (emergency)
virtual int StdOut(const std::string &outstr, unsigned char inlev=1)
ParallelGlobalObj(const std::string &name, unsigned int id)
virtual int Init(const std::string &name, unsigned int id)
Program(ComLineType &incom, GlobalType &inglob)
bool LogStreamReady()
Checks log stream.
ParallelGlobalObj(int narg, char **args)
Main encapsulation of MPI.
std::ostream & DebugStream()
Gets the debug stream object.
GlobalObj(int narg, char **args)
Default constructor.
int Initialize(CommunicatorObject &incomm)
virtual void Register(const StackType &stackentry)
Register will push to the Stack only.
virtual bool Profiling(bool yn)
Enable or disable profiling.
std::ostream & ErrStream()
Gets the error stream object.
const std::string stripdirs(const std::string &pname)
Strip absolute path.
virtual void FunctionExitAll()
FunctionExitAll exits all from the Profiler only.
void EnableProfilingBarriers()
void SetOutStream(std::ostream &outstream)
Sets the stdout stream object.
bool OutStreamReady()
Checks out stream.
Unix System Tools interface.
virtual CommunicatorType & Communicator()
ParallelGlobalObj(ParallelGlobalObj< CommunicatorType, StackType, ErrorType, ProfilerType > &pglobin)
virtual void FunctionEntry(const StackType &stackentry)
FunctionEntry updates the Stack as well as the Profiler.
ParallelGlobalObj(GlobalType &inglob)
std::ostream * LogStreamPtr()
Gets the log stream pointer.
CommunicatorType globalCommunicator
Program(ComLineType &incom)
virtual int Init(const StackType &name, unsigned int id)
Initializes the global object and it's profiler object Profiling is ON by default if Init is invoked...
GlobalObj()
Default constructor. Profiling is OFF by default.
virtual void Error(const ErrorType &error)
Pushes an error onto the error stack.
virtual ~GlobalObj()
Destructor.
bool _initd
has been initialized?
virtual int Finalize()
Finalizes the global object, and it's profiler object.
std::ostream * _OutStreamSave
void SetVerbLevel(unsigned char l)
std::ostream * OutStreamPtr()
Gets the stdout stream pointer.
bool DebugStreamReady()
Checks debug stream.
int FunctionEntry(const std::string &name)
mark construct entry
unsigned char _debug_level
Debugging level.
int Init(int id)
integer only inteface for init
ProfilerType * _Profiler
This is a placeholder for a generic profiling tool.
virtual bool WriteProfiles()
Get state of enablement for writing profile files.
void SetLogStream(std::ostream &logstream)
Sets the stdout stream object.
virtual int LogOut(const std::string &outstr, int inlev=0)
GlobalObj(const StackType &name, int id)
Constructor with args.
virtual void FunctionExit(const StackType &stackentry)
FunctionExit updates the Stack as well as the Profiler.
virtual int ForceOut(const std::string &outstr, unsigned char inlev=1)
virtual bool WriteProfiles(bool yn)
Enable or disable profile file writing.
void DeSyncIO()
DeSync IO - relinquish control over IO, revert to standard.
virtual int Init(const StackType &name)
Initializes the global object and it's profiler object /// Initializes the global object and it's pro...
virtual void SetName(const std::string &name)
virtual const std::string & Name()