12 #ifndef SST_CORE_OUTPUT_H 13 #define SST_CORE_OUTPUT_H 23 #ifndef __STDC_FORMAT_MACROS 24 #define __STDC_FORMAT_MACROS 27 #include "sst/core/serialization/serializable.h" 33 #include <unordered_map> 35 extern int main(
int argc,
char** argv);
40 #define CALL_INFO __LINE__, __FILE__, __FUNCTION__ 42 #if defined(__GNUC__) || defined(__clang__) 43 #define CALL_INFO_LONG __LINE__, __FILE__, __PRETTY_FUNCTION__ 45 #define CALL_INFO_LONG __LINE__, __FILE__, __FUNCTION__ 65 static constexpr uint32_t PrintAll = std::numeric_limits<uint32_t>::max();
115 const std::string& prefix, uint32_t verbose_level, uint32_t verbose_mask,
output_location_t location,
116 const std::string& localoutputfilename =
"");
173 const std::string& prefix, uint32_t verbose_level, uint32_t verbose_mask,
output_location_t location,
174 const std::string& localoutputfilename =
"");
184 void output(uint32_t line,
const char* file,
const char* func,
const char* format, ...) const
185 __attribute__((format(printf, 5, 6)))
188 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
190 va_start(arg, format);
191 outputprintf(line, file, func, format, arg);
200 void output(
const char* format, ...) const __attribute__((format(printf, 2, 3)))
203 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
205 va_start(arg, format);
206 outputprintf(format, arg);
228 uint32_t line,
const char* file,
const char* func, uint32_t output_level, uint32_t output_bits,
229 const char* format, ...) const __attribute__((format(printf, 7, 8)))
233 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
236 if ( ((output_bits & ~m_verboseMask) == 0) && (output_level <= m_verboseLevel) ) {
238 va_start(arg, format);
239 outputprintf(line, file, func, format, arg);
263 const char* tempPrefix, uint32_t line,
const char* file,
const char* func, uint32_t output_level,
264 uint32_t output_bits,
const char* format, ...) __attribute__((format(printf, 8, 9)))
269 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
270 const std::string normalPrefix = m_outputPrefix;
271 m_outputPrefix = tempPrefix;
275 if ( ((output_bits & ~m_verboseMask) == 0) && (output_level <= m_verboseLevel) ) {
277 va_start(arg, format);
278 outputprintf(line, file, func, format, arg);
282 m_outputPrefix = normalPrefix;
304 const char* tempPrefix, uint32_t line,
const char* file,
const char* func, uint32_t output_level,
305 uint32_t output_bits,
const char* format, ...) __attribute__((format(printf, 8, 9)))
308 #ifdef __SST_DEBUG_OUTPUT__ 311 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
312 const std::string normalPrefix = m_outputPrefix;
313 m_outputPrefix = tempPrefix;
317 if ( ((output_bits & ~m_verboseMask) == 0) && (output_level <= m_verboseLevel) ) {
319 va_start(arg, format);
320 outputprintf(line, file, func, format, arg);
324 m_outputPrefix = normalPrefix;
358 uint32_t line,
const char* file,
const char* func, uint32_t output_level, uint32_t output_bits,
359 const char* format, ...) const __attribute__((format(printf, 7, 8)))
361 #ifdef __SST_DEBUG_OUTPUT__ 363 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
366 if ( ((output_bits & ~m_verboseMask) == 0) && (output_level <= m_verboseLevel) ) {
368 va_start(arg, format);
369 outputprintf(line, file, func, format, arg);
397 void fatal(uint32_t line,
const char* file,
const char* func,
int exit_code,
const char* format, ...) const
398 __attribute__((format(printf, 6, 7)));
470 inline
void flush()
const { std::fflush(*m_targetOutputRef); }
476 static void setFileName(
const std::string& filename);
478 static Output& getDefaultObject() {
return m_defaultObject; }
485 friend class TraceFunction;
488 void openSSTTargetFile()
const;
489 void closeSSTTargetFile();
491 int getMPIWorldRank()
const;
492 int getMPIWorldSize()
const;
493 uint32_t getNumThreads()
const;
494 uint32_t getThreadRank()
const;
495 std::string buildPrefixString(uint32_t line,
const std::string& file,
const std::string& func)
const;
497 uint32_t line,
const std::string& file,
const std::string& func,
const char* format, va_list arg)
const;
498 void outputprintf(
const char* format, va_list arg)
const;
500 friend int ::main(
int argc,
char** argv);
501 static Output& setDefaultObject(
502 const std::string& prefix, uint32_t verbose_level, uint32_t verbose_mask,
output_location_t location,
503 const std::string& localoutputfilename =
"")
505 m_defaultObject.
init(prefix, verbose_level, verbose_mask, location, localoutputfilename);
506 return getDefaultObject();
509 static void setWorldSize(
int num_ranks,
int num_threads,
int mpiRank)
511 m_worldSize_ranks = num_ranks;
512 m_worldSize_threads = num_threads;
516 static void setThreadID(std::thread::id mach, uint32_t user) { m_threadMap.insert(std::make_pair(mach, user)); }
519 bool m_objInitialized;
520 std::string m_outputPrefix;
521 uint32_t m_verboseLevel;
522 uint32_t m_verboseMask;
525 static Output m_defaultObject;
534 std::FILE** m_targetOutputRef;
539 std::FILE** m_targetFileHandleRef;
540 std::string* m_targetFileNameRef;
541 uint32_t* m_targetFileAccessCountRef;
544 static std::string m_sstGlobalSimFileName;
545 static std::FILE* m_sstGlobalSimFileHandle;
546 static uint32_t m_sstGlobalSimFileAccessCount;
549 std::string m_sstLocalFileName;
550 std::FILE* m_sstLocalFileHandle;
551 uint32_t m_sstLocalFileAccessCount;
553 static std::unordered_map<std::thread::id, uint32_t> m_threadMap;
554 static int m_worldSize_ranks;
555 static int m_worldSize_threads;
557 static int m_mpiRank;
564 thread_local
static int trace_level;
565 thread_local
static std::vector<char> indent_array;
568 TraceFunction(uint32_t line,
const char* file,
const char* func,
bool print_sim_info =
true,
bool activate =
true);
571 Output& getOutput() {
return output_obj; }
577 void output(
const char* format, ...)
const __attribute__((format(printf, 2, 3)));
583 std::string
function;
592 #endif // SST_CORE_OUTPUT_H Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:53
void setVerboseLevel(uint32_t verbose_level)
Sets object verbose level.
Definition: output.cc:108
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
void setOutputLocation(output_location_t location)
Sets object output location.
Definition: output.cc:144
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:227
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:160
output_location_t
Choice of output location.
Definition: output.h:58
void setVerboseMask(uint32_t verbose_mask)
Sets object verbose mask.
Definition: output.cc:120
Output()
Default Constructor.
Definition: output.cc:64
void flush() const
This method allows for the manual flushing of the output.
Definition: output.h:470
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:262
Definition: serializable.h:118
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:357
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:303
static void setFileName(const std::string &filename)
This method sets the static filename used by SST.
Definition: output.cc:232
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:184
output_location_t getOutputLocation() const
Returns object output location.
Definition: output.cc:154
uint32_t getVerboseLevel() const
Returns object verbose level.
Definition: output.cc:114
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:77
uint32_t getVerboseMask() const
Returns object verbose mask.
Definition: output.cc:126
void setPrefix(const std::string &prefix)
Sets object prefix.
Definition: output.cc:132
std::string getPrefix() const
Returns object prefix.
Definition: output.cc:138
void output(const char *format,...) const
Output the message with formatting as specified by the format parameter.
Definition: output.h:200
void output(const char *format,...) const
Output the message with formatting as specified by the format parameter.
Definition: output.cc:566