12 #ifndef SST_CORE_OUTPUT_H
13 #define SST_CORE_OUTPUT_H
22 #ifndef __STDC_FORMAT_MACROS
23 #define __STDC_FORMAT_MACROS
25 #include "sst/core/rankInfo.h"
31 #include <unordered_map>
33 extern int main(
int argc,
char** argv);
38 #define CALL_INFO __LINE__, __FILE__, __FUNCTION__
40 #if defined(__GNUC__) || defined(__clang__)
41 #define CALL_INFO_LONG __LINE__, __FILE__, __PRETTY_FUNCTION__
43 #define CALL_INFO_LONG __LINE__, __FILE__, __FUNCTION__
63 static constexpr uint32_t PrintAll = std::numeric_limits<uint32_t>::max();
113 const std::string& prefix, uint32_t verbose_level, uint32_t verbose_mask,
output_location_t location,
114 const std::string& localoutputfilename =
"");
171 const std::string& prefix, uint32_t verbose_level, uint32_t verbose_mask,
output_location_t location,
172 const std::string& localoutputfilename =
"");
182 void output(uint32_t line,
const char* file,
const char* func,
const char* format, ...) const
183 __attribute__((format(printf, 5, 6)))
186 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
188 va_start(arg, format);
189 outputprintf(line, file, func, format, arg);
198 void output(
const char* format, ...) const __attribute__((format(printf, 2, 3)))
201 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
203 va_start(arg, format);
204 outputprintf(format, arg);
226 uint32_t line,
const char* file,
const char* func, uint32_t output_level, uint32_t output_bits,
227 const char* format, ...) const __attribute__((format(printf, 7, 8)))
231 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
234 if ( ((output_bits & ~m_verboseMask) == 0) && (output_level <= m_verboseLevel) ) {
236 va_start(arg, format);
237 outputprintf(line, file, func, format, arg);
261 const char* tempPrefix, uint32_t line,
const char* file,
const char* func, uint32_t output_level,
262 uint32_t output_bits,
const char* format, ...) __attribute__((format(printf, 8, 9)))
267 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
268 const std::string normalPrefix = m_outputPrefix;
269 m_outputPrefix = tempPrefix;
273 if ( ((output_bits & ~m_verboseMask) == 0) && (output_level <= m_verboseLevel) ) {
275 va_start(arg, format);
276 outputprintf(line, file, func, format, arg);
280 m_outputPrefix = normalPrefix;
302 const char* tempPrefix, uint32_t line,
const char* file,
const char* func, uint32_t output_level,
303 uint32_t output_bits,
const char* format, ...) __attribute__((format(printf, 8, 9)))
306 #ifdef __SST_DEBUG_OUTPUT__
309 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
310 const std::string normalPrefix = m_outputPrefix;
311 m_outputPrefix = tempPrefix;
315 if ( ((output_bits & ~m_verboseMask) == 0) && (output_level <= m_verboseLevel) ) {
317 va_start(arg, format);
318 outputprintf(line, file, func, format, arg);
322 m_outputPrefix = normalPrefix;
356 uint32_t line,
const char* file,
const char* func, uint32_t output_level, uint32_t output_bits,
357 const char* format, ...) const __attribute__((format(printf, 7, 8)))
359 #ifdef __SST_DEBUG_OUTPUT__
361 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
364 if ( ((output_bits & ~m_verboseMask) == 0) && (output_level <= m_verboseLevel) ) {
366 va_start(arg, format);
367 outputprintf(line, file, func, format, arg);
395 void fatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, ...) const
396 __attribute__((format(printf, 6, 7)));
426 void setPrefix(const std::
string& prefix);
468 inline
void flush()
const { std::fflush(*m_targetOutputRef); }
474 static void setFileName(
const std::string& filename);
476 static Output& getDefaultObject() {
return m_defaultObject; }
479 friend class TraceFunction;
482 void openSSTTargetFile()
const;
483 void closeSSTTargetFile();
485 int getMPIWorldRank()
const;
486 int getMPIWorldSize()
const;
487 uint32_t getNumThreads()
const;
488 uint32_t getThreadRank()
const;
489 std::string buildPrefixString(uint32_t line,
const std::string& file,
const std::string& func)
const;
491 uint32_t line,
const std::string& file,
const std::string& func,
const char* format, va_list arg)
const;
492 void outputprintf(
const char* format, va_list arg)
const;
494 friend int ::main(
int argc,
char** argv);
495 static Output& setDefaultObject(
496 const std::string& prefix, uint32_t verbose_level, uint32_t verbose_mask,
output_location_t location,
497 const std::string& localoutputfilename =
"")
499 m_defaultObject.
init(prefix, verbose_level, verbose_mask, location, localoutputfilename);
500 return getDefaultObject();
503 static void setWorldSize(
const RankInfo& ri,
int mpiRank)
509 static void setThreadID(std::thread::id mach, uint32_t user) { m_threadMap.insert(std::make_pair(mach, user)); }
512 bool m_objInitialized;
513 std::string m_outputPrefix;
514 uint32_t m_verboseLevel;
515 uint32_t m_verboseMask;
518 static Output m_defaultObject;
527 std::FILE** m_targetOutputRef;
532 std::FILE** m_targetFileHandleRef;
533 std::string* m_targetFileNameRef;
534 uint32_t* m_targetFileAccessCountRef;
537 static std::string m_sstGlobalSimFileName;
538 static std::FILE* m_sstGlobalSimFileHandle;
539 static uint32_t m_sstGlobalSimFileAccessCount;
542 std::string m_sstLocalFileName;
543 std::FILE* m_sstLocalFileHandle;
544 uint32_t m_sstLocalFileAccessCount;
546 static std::unordered_map<std::thread::id, uint32_t> m_threadMap;
547 static RankInfo m_worldSize;
548 static int m_mpiRank;
555 thread_local
static int trace_level;
556 thread_local
static std::vector<char> indent_array;
559 TraceFunction(uint32_t line,
const char* file,
const char* func,
bool print_sim_info =
true,
bool activate =
true);
562 Output& getOutput() {
return output_obj; }
568 void output(
const char* format, ...)
const __attribute__((format(printf, 2, 3)));
574 std::string
function;
583 #endif // SST_CORE_OUTPUT_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:51
void setVerboseLevel(uint32_t verbose_level)
Sets object verbose level.
Definition: output.cc:103
void setOutputLocation(output_location_t location)
Sets object output location.
Definition: output.cc:139
void debug(uint32_t line, const char *file, const char *func, uint32_t output_level, uint32_t output_bits, const char *format,...) const
Output the debug message with formatting as specified by the format parameter.
Definition: output.h:355
output_location_t
Choice of output location.
Definition: output.h:56
uint32_t getVerboseLevel() const
Returns object verbose level.
Definition: output.cc:109
void setVerboseMask(uint32_t verbose_mask)
Sets object verbose mask.
Definition: output.cc:115
void output(const char *format,...) const
Output the message with formatting as specified by the format parameter.
Definition: output.h:198
Output()
Default Constructor.
Definition: output.cc:59
std::string getPrefix() const
Returns object prefix.
Definition: output.cc:133
void verbose(uint32_t line, const char *file, const char *func, uint32_t output_level, uint32_t output_bits, const char *format,...) const
Output the verbose message with formatting as specified by the format parameter.
Definition: output.h:225
void verbosePrefix(const char *tempPrefix, uint32_t line, const char *file, const char *func, uint32_t output_level, uint32_t output_bits, const char *format,...)
Output the verbose message with formatting as specified by the format parameter.
Definition: output.h:260
void debugPrefix(const char *tempPrefix, uint32_t line, const char *file, const char *func, uint32_t output_level, uint32_t output_bits, const char *format,...)
Output the debug message with formatting as specified by the format parameter.
Definition: output.h:301
static void setFileName(const std::string &filename)
This method sets the static filename used by SST.
Definition: output.cc:221
void fatal(uint32_t line, const char *file, const char *func, int exit_code, const char *format,...) const
Output the fatal message with formatting as specified by the format parameter.
Definition: output.cc:155
void output(uint32_t line, const char *file, const char *func, const char *format,...) const
Output the message with formatting as specified by the format parameter.
Definition: output.h:182
uint32_t getVerboseMask() const
Returns object verbose mask.
Definition: output.cc:121
void flush() const
This method allows for the manual flushing of the output.
Definition: output.h:468
output_location_t getOutputLocation() const
Returns object output location.
Definition: output.cc:149
void init(const std::string &prefix, uint32_t verbose_level, uint32_t verbose_mask, output_location_t location, const std::string &localoutputfilename="")
Initialize the object after construction.
Definition: output.cc:72
void output(const char *format,...) const
Output the message with formatting as specified by the format parameter.
Definition: output.cc:531
void setPrefix(const std::string &prefix)
Sets object prefix.
Definition: output.cc:127