14 #ifndef SST_CORE_OUTPUT_H
15 #define SST_CORE_OUTPUT_H
24 #ifndef __STDC_FORMAT_MACROS
25 #define __STDC_FORMAT_MACROS
30 #include <unordered_map>
34 #include "sst/core/rankInfo.h"
36 extern int main(
int argc,
char **argv);
41 #define CALL_INFO __LINE__, __FILE__, __FUNCTION__
43 #if defined(__GNUC__) || defined(__clang__)
44 #define CALL_INFO_LONG __LINE__, __FILE__, __PRETTY_FUNCTION__
46 #define CALL_INFO_LONG __LINE__, __FILE__, __FUNCTION__
66 static constexpr uint32_t PrintAll = std::numeric_limits<uint32_t>::max();
115 Output(
const std::string& prefix, uint32_t verbose_level,
117 const std::string& localoutputfilename =
"");
174 void init(
const std::string& prefix, uint32_t verbose_level,
176 const std::string& localoutputfilename =
"");
186 void output(uint32_t line,
const char* file,
const char* func,
187 const char* format, ...) const
188 __attribute__ ((format (printf, 5, 6)))
191 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
193 va_start(arg, format);
194 outputprintf(line, file, func, format, arg);
203 void output(
const char* format, ...) const
204 __attribute__ ((format (printf, 2, 3)))
207 if (
true == m_objInitialized &&
NONE != m_targetLoc) {
209 va_start(arg, format);
210 outputprintf(format, arg);
231 void verbose(uint32_t line,
const char* file,
const char* func,
232 uint32_t output_level, uint32_t output_bits,
233 const char* format, ...) const
234 __attribute__ ((format (printf, 7, 8)))
238 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
241 if (((output_bits & ~m_verboseMask) == 0) &&
242 (output_level <= m_verboseLevel)){
244 va_start(arg, format);
245 outputprintf(line, file, func, format, arg);
268 void verbosePrefix(
const char* tempPrefix, uint32_t line,
const char* file,
const char* func,
269 uint32_t output_level, uint32_t output_bits,
270 const char* format, ...)
271 __attribute__ ((format (printf, 8, 9)))
276 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
277 const std::string normalPrefix = m_outputPrefix;
278 m_outputPrefix = tempPrefix;
282 if (((output_bits & ~m_verboseMask) == 0) &&
283 (output_level <= m_verboseLevel)){
285 va_start(arg, format);
286 outputprintf(line, file, func, format, arg);
290 m_outputPrefix = normalPrefix;
311 void debugPrefix(
const char* tempPrefix, uint32_t line,
const char* file,
const char* func,
312 uint32_t output_level, uint32_t output_bits,
313 const char* format, ...)
314 __attribute__ ((format (printf, 8, 9)))
317 #ifdef __SST_DEBUG_OUTPUT__
320 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
321 const std::string normalPrefix = m_outputPrefix;
322 m_outputPrefix = tempPrefix;
326 if (((output_bits & ~m_verboseMask) == 0) &&
327 (output_level <= m_verboseLevel)){
329 va_start(arg, format);
330 outputprintf(line, file, func, format, arg);
334 m_outputPrefix = normalPrefix;
367 void debug(uint32_t line,
const char* file,
const char* func,
368 uint32_t output_level, uint32_t output_bits,
369 const char* format, ...) const
370 __attribute__ ((format (printf, 7, 8)))
372 #ifdef __SST_DEBUG_OUTPUT__
374 if (
true == m_objInitialized &&
NONE != m_targetLoc ) {
377 if (((output_bits & ~m_verboseMask) == 0) &&
378 (output_level <= m_verboseLevel)){
380 va_start(arg, format);
381 outputprintf(line, file, func, format, arg);
410 void fatal(uint32_t line,
const char* file,
const char* func,
412 const char* format, ...) const
413 __attribute__ ((format (printf, 6, 7))) ;
444 void setPrefix(const std::
string& prefix);
486 inline
void flush()
const {std::fflush(*m_targetOutputRef);}
493 static void setFileName(
const std::string& filename);
495 static Output& getDefaultObject() {
return m_defaultObject; }
499 friend class TraceFunction;
502 void openSSTTargetFile()
const;
503 void closeSSTTargetFile();
505 int getMPIWorldRank()
const;
506 int getMPIWorldSize()
const;
507 uint32_t getNumThreads()
const;
508 uint32_t getThreadRank()
const;
509 std::string buildPrefixString(uint32_t line,
510 const std::string& file,
511 const std::string& func)
const;
512 void outputprintf(uint32_t line,
513 const std::string& file,
514 const std::string& func,
517 void outputprintf(
const char *format, va_list arg)
const;
519 friend int ::main(
int argc,
char **argv);
520 static Output& setDefaultObject(
const std::string& prefix, uint32_t verbose_level,
522 const std::string& localoutputfilename =
"")
524 m_defaultObject.
init(prefix, verbose_level, verbose_mask, location, localoutputfilename);
525 return getDefaultObject();
528 static void setWorldSize(
const RankInfo &ri,
int mpiRank)
534 static void setThreadID(std::thread::id mach, uint32_t user)
536 m_threadMap.insert(std::make_pair(mach, user));
541 bool m_objInitialized;
542 std::string m_outputPrefix;
543 uint32_t m_verboseLevel;
544 uint32_t m_verboseMask;
547 static Output m_defaultObject;
556 std::FILE** m_targetOutputRef;
561 std::FILE** m_targetFileHandleRef;
562 std::string* m_targetFileNameRef;
563 uint32_t* m_targetFileAccessCountRef;
566 static std::string m_sstGlobalSimFileName;
567 static std::FILE* m_sstGlobalSimFileHandle;
568 static uint32_t m_sstGlobalSimFileAccessCount;
571 std::string m_sstLocalFileName;
572 std::FILE* m_sstLocalFileHandle;
573 uint32_t m_sstLocalFileAccessCount;
575 static std::unordered_map<std::thread::id, uint32_t> m_threadMap;
576 static RankInfo m_worldSize;
577 static int m_mpiRank;
584 static int trace_level;
585 static std::vector<char> indent_array;
588 TraceFunction(uint32_t line,
const char* file,
const char* func,
bool print_sim_info =
true);
591 Output& getOutput() {
return output_obj;}
597 void output(
const char* format, ...)
const
598 __attribute__ ((format (printf, 2, 3)));
605 std::string
function;
614 #endif // SST_CORE_OUTPUT_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:54
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:367
output_location_t
Choice of output location.
Definition: output.h:59
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:203
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:231
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:268
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:311
static void setFileName(const std::string &filename)
This method sets the static filename used by SST.
Definition: output.cc:220
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:186
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:486
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:71
void output(const char *format,...) const
Output the message with formatting as specified by the format parameter.
Definition: output.cc:526
void setPrefix(const std::string &prefix)
Sets object prefix.
Definition: output.cc:127